-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.js
More file actions
50 lines (42 loc) · 1.29 KB
/
Copy pathlogger.js
File metadata and controls
50 lines (42 loc) · 1.29 KB
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
'use strict';
const pino = require('pino');
/**
* Creates and configures a Pino logger instance
* @param {Object} options - Logger configuration options
* @param {string} options.level - Log level (default: 'info')
* @param {boolean} options.pretty - Enable pretty printing for development (default: false)
* @returns {pino.Logger} Configured Pino logger instance
*/
function createLogger(options = {}) {
const {
level = process.env.LOG_LEVEL || 'info',
pretty = process.env.NODE_ENV === 'development' || process.env.LOG_PRETTY === 'true'
} = options;
const loggerOptions = {
level,
formatters: {
level: (label) => {
return { level: label };
}
},
timestamp: pino.stdTimeFunctions.isoTime
};
if (pretty) {
return pino({
...loggerOptions,
transport: {
target: 'pino-pretty',
options: {
colorize: true,
translateTime: 'HH:MM:ss Z',
ignore: 'pid,hostname'
}
}
});
}
return pino(loggerOptions);
}
// Create default logger instance
const logger = createLogger();
module.exports = logger;
module.exports.createLogger = createLogger;