-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.js
43 lines (34 loc) · 1017 Bytes
/
util.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
var pathFn = require('path')
var winston = require('winston')
var config = require('config');
var Logio = require("winston-logio").Logio
var util = module.exports = {}
util.getLogger = getLogger
// loggers_map
var loggers = {}
function getLogger(namespace) {
if (loggers[namespace]) {
return loggers[namespace]
}
var logger = loggers[namespace] = new winston.Logger({
levels: config.levels // logger 的 levels
})
// file
logger.add(winston.transports.File, {
levels: config.levels,
level: config.file_level,
filename: pathFn.join(config.logs_dir, namespace + '.log') // 在项目主文件夹运行
})
// log.io
logger.add(Logio, {
levels: config.levels,
level: config.logio_level,
host: config.logio.host,
port: config.logio.port,
localhost: config.project_name, // node
node_name: namespace // stream
})
// TODO : splunk or elk blabla
// logger.add()
return logger
}