forked from UnblockNeteaseMusic/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
44 lines (39 loc) · 927 Bytes
/
logger.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
const pino = require('pino');
// The destination of the log file. Can be `undefined`.
const destFile = process.env.LOG_FILE;
// Do not colorize if printing to non-TTY deivce.
const colorize = process.stdout.isTTY;
const messageFormat = colorize
? '\x1b[1m\x1b[32m({scope})\x1b[0m\x1b[36m {msg}'
: '({scope}) {msg}';
const logger = pino(
{
level: process.env.LOG_LEVEL ?? 'info',
prettyPrint:
process.env.JSON_LOG === 'true'
? false
: {
colorize: colorize,
messageFormat: messageFormat,
ignore: 'time,pid,hostname,scope',
errorProps: '*',
},
},
// Redirect the logs to destFile if specified.
destFile && pino.destination(destFile)
);
/**
* Add the scope of this log message.
*
* @param {string} scope The scope of this log message.
* @return {pino.Logger}
*/
function logScope(scope) {
return logger.child({
scope,
});
}
module.exports = {
logger,
logScope,
};