/
index.js
62 lines (51 loc) · 1.72 KB
/
index.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
60
61
62
(function()
{
const Logger = require('./src/logger.js');
const ConsoleAdapter = require('./src/adapters/console.adapter.js');
let Manager = function(options)
{
this.options = options || {};
if(!this.options.hasOwnProperty('publish'))
{
this.options.publish = {};
}
this.options.timestamp = this.options.timestamp || {};
this.options.timestamp.format = this.options.timestamp.format || 'YYYY-MM-DD hh:mm:ss.sss';
this.options.timestamp.timezone = this.options.timestamp.timezone || 'utc';
this.options.adapters = this.options.adapters || [];
let checkConsoleAdapter = false;
for(let i=0, l=this.options.adapters.length; i<l; i++)
{
let adaptor = this.options.adapters[i];
if(adaptor.name === 'console')
{
checkConsoleAdapter = true;
break;
}
}
if(!checkConsoleAdapter)
{
this.options.adapters.push(new ConsoleAdapter());
}
};
Manager.prototype.createLogger = function(header)
{
let logger = new Logger(header, { timestamp: this.options.timestamp });
logger.manager = this;
return logger;
};
Manager.prototype.publish = function(logger)
{
for(let i=0, l=this.options.adapters.length; i<l; i++)
{
let adaptor = this.options.adapters[i];
adaptor.publish(logger, this.options.publish);
}
};
Manager.Adapter = {
Console: ConsoleAdapter,
Slack: require('./src/adapters/slack.adapter.js'),
SocketIO: require('./src/adapters/socket.io.adapter.js')
}
module.exports = Manager;
})();