-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathlogging.js
21 lines (18 loc) · 942 Bytes
/
logging.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const tracer = require('dd-trace').init(); // eslint-disable-line no-unused-vars
const bunyan = require('bunyan');
// Default to INFO logs and above, unless a valid level name is provided by $LOG_LEVEL.
const logLevel = bunyan.levelFromName[(process.env.LOG_LEVEL || '').toLowerCase()] || bunyan.levelFromName.info;
// By default, log "src" data (filename, line number) if log level is "debug" or lower.
// $LOG_SRC_ENABLED overrides this behavior when set to "true"/"1" or "false"/"0".
let logSrc = logLevel <= bunyan.levelFromName.debug;
if (process.env.LOG_SRC_ENABLED === 'true' || process.env.LOG_SRC_ENABLED === '1') {
logSrc = true;
} else if (process.env.LOG_SRC_ENABLED === 'false' || process.env.LOG_SRC_ENABLED === '0') {
logSrc = false;
}
module.exports.log = bunyan.createLogger({
name: process.env.LOG_NAME || 'gost',
level: logLevel,
src: logSrc,
serializers: { err: bunyan.stdSerializers.err },
});