-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
51 lines (43 loc) · 1.05 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
/**
* The main module of the logger package.
*/
'use strict';
var winston = require( 'winston' );
var peliasConfig = require( 'pelias-config' );
var pkgConfig = peliasConfig.generate().logger;
function CreateLogger( name, loggerOpts ){
if( loggerOpts === undefined ){
loggerOpts = {
transports: [
new winston.transports.Console( {
colorize: pkgConfig.colorize,
json: pkgConfig.json,
stringify: true,
timestamp: pkgConfig.timestamp,
level: pkgConfig.level,
label: name,
stderrLevels: ['emerg', 'alert', 'crit', 'error']
})
]
};
}
return new winston.Logger( loggerOpts );
}
var loggers = {};
/**
* If a logger named `name` exists, return it; otherwise, create a new one.
*/
function getLogger( name, loggerOpts ){
if( name in loggers ){
return loggers[ name ];
}
else {
var logger = new CreateLogger( name, loggerOpts );
loggers[ name ] = logger;
return logger;
}
}
module.exports = {
get: getLogger,
winston: winston
};