redis.js
1.44 KB
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
58
59
60
61
62
63
64
65
66
const path = require('path');
// publish config object to be used by tektrans-logger
global.TEKTRANS_LOGGER_CONFIG = {
level: 'silly',
label: 'REDIS-EXAMPLE',
// default is "logs" directory on current workdir
directory: path.join(process.cwd(), 'logs'),
filename: 'redis-log',
// default is using generic level value
console_level: null,
// default is using generic level value
file_level: null,
// default is no old file removal
max_files: '10d',
redis: {
host: 'localhost',
port: 6379,
auth: null,
channel: null,
},
};
const logger = require('..');
const sleep = (ms) => new Promise((resolve) => {
setTimeout(() => {
resolve();
}, ms);
});
const main = async () => {
// await sleep(2000);
logger.silly('This is a silly log.');
logger.debug('This is a debug log.');
logger.verbose('This is a verbose log');
logger.verbose('This is a verbose example of log with metadata', {
a: 'metadata1',
b: 'metadata2',
c: {
c1: 'compund',
},
});
logger.http('This in a http log');
logger.info('This is an info log');
logger.warn('This is an warn log');
logger.error('This in an error');
// give few seconds to make sure all logs
// has been emitted to redis before close the log
await sleep(2000);
// don't forget to close the logger at the end
logger.end();
};
main();