Added scene tags filter.
This commit is contained in:
36
src/logger.js
Executable file
36
src/logger.js
Executable file
@@ -0,0 +1,36 @@
|
||||
import util from 'util';
|
||||
import path from 'path';
|
||||
import * as winston from 'winston';
|
||||
import 'winston-daily-rotate-file';
|
||||
import stackParser from 'error-stack-parser';
|
||||
|
||||
// import args from './args';
|
||||
|
||||
export default function initLogger(customLabel) {
|
||||
const filepath = stackParser.parse(new Error())[1]?.fileName;
|
||||
const contextLabel = customLabel || path.basename(filepath, '.js');
|
||||
|
||||
return winston.createLogger({
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
||||
winston.format((info) => (info instanceof Error
|
||||
? { ...info, message: info.stack }
|
||||
: { ...info, message: typeof info.message === 'string' ? info.message : util.inspect(info.message) }))(),
|
||||
winston.format.colorize(),
|
||||
winston.format.printf(({
|
||||
level, timestamp, label, message,
|
||||
}) => `${timestamp} ${level} [${label || contextLabel}] ${message}`),
|
||||
),
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
level: 'silly',
|
||||
timestamp: true,
|
||||
}),
|
||||
new winston.transports.DailyRotateFile({
|
||||
datePattern: 'YYYY-MM-DD',
|
||||
filename: path.join('log', '%DATE%.log'),
|
||||
level: 'silly',
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user