-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
62 lines (47 loc) · 1.85 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const quickLog = require('./index');
const fileLogger = quickLog.fileLogger;
const QueueLog = quickLog.QueueLog;
// Set config (Do this on the init file of your application)
quickLog.setConfig({
logPath: './log/'
});
// Log normal message
fileLogger.log('Yes test');
// Log error
fileLogger.error({name: 'hello world'});
const queueLog = new QueueLog({
referenceId: 'test-log',
referenceName: 'Display',
processId: true
});
const logs = [1, 'test log', 'an other log'];
let intervals = 0;
// Async example
const interval = setInterval(() => {
intervals++;
logs.forEach((itemToLog, i) => {
queueLog.log(`Interval ${intervals}: This is a log item: ${itemToLog} - ${i}`);
});
if (intervals >= 3) {
clearInterval(interval);
// Write the log when your done with your async calls
queueLog.write(); // or pass 'error' to display as an error
}
}, 500);
// Output
/*
2016-09-30 12:14:43 (NORMAL) - Yes test
2016-09-30 12:14:43 (ERROR) - Yes test
2016-09-30 12:14:43 - sWExaCCatY - --------- INIT Display ( test-log ) ---------
2016-09-30 12:14:44 - sWExaCCatY - Interval 1: This is a log item: 1 - 0
2016-09-30 12:14:44 - sWExaCCatY - Interval 1: This is a log item: test log - 1
2016-09-30 12:14:44 - sWExaCCatY - Interval 1: This is a log item: an other log - 2
2016-09-30 12:14:44 - sWExaCCatY - Interval 2: This is a log item: 1 - 0
2016-09-30 12:14:44 - sWExaCCatY - Interval 2: This is a log item: test log - 1
2016-09-30 12:14:44 - sWExaCCatY - Interval 2: This is a log item: an other log - 2
2016-09-30 12:14:45 - sWExaCCatY - Interval 3: This is a log item: 1 - 0
2016-09-30 12:14:45 - sWExaCCatY - Interval 3: This is a log item: test log - 1
2016-09-30 12:14:45 - sWExaCCatY - Interval 3: This is a log item: an other log - 2
2016-09-30 12:14:45 - sWExaCCatY - --------- (NORMAL) END Display ( test-log ) ---------
*/