-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.js
59 lines (53 loc) · 1.48 KB
/
log.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
58
59
var winston = require('winston');
const moment = require('moment');
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
// set default log level.
var logLevel = 'info'
workDir = process.env.WORK_DIR || "/opt/mirror/";
const newFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} [${label}] ${level}: ${message}`;
});
const tsFormat = () => moment().format('YYYY-MM-DD hh:mm:ss').trim();
var logger = winston.createLogger({
level: logLevel,
levels: {
fatal: 0,
crit: 1,
warn: 2,
info: 3,
debug: 4,
trace: 5
},
transports: [
new (winston.transports.Console)({
format: format.combine(
label({ label: 'uploader' }),
timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
newFormat
)
}),
new (winston.transports.File)({
filename: `${workDir}/uploader.log`,
format: format.combine(
label({ label: 'uploader' }),
timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
newFormat
)
})
]
})
/* LOGGER EXAMPLES
var log = require('./log.js')
log.trace('testing')
log.debug('testing')
log.info('testing')
log.warn('testing')
log.crit('testing')
log.fatal('testing')
*/
module.exports = logger