版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/adley_app/article/details/88045230
const winston = require('winston');
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { ServerName: 'CGI' },
transports: [
new winston.transports.File({ filename: 'default.log', level: 'info' }),
new winston.transports.File({ filename: 'error.log', level: 'error'})
]
});
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'dev') {
logger.add(new winston.transports.Console({
format: winston.format.simple()
}));
}
logger.info('jkdshfkjds')
logger.error('jkdshfkjds')
var winston = require('winston');
require('winston-daily-rotate-file');
var process = require('child_process');
var transport = new (winston.transports.DailyRotateFile)({
filename: 'CGI-%DATE%.log',
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxSize: '1k',
maxFiles: '14d'
});
transport.on('rotate', function (oldFilename, newFilename) {
// do something fun
console.log(oldFilename, newFilename);
log
// if(){
// process.exec('mkdir ')
// }
});
var logger = winston.createLogger({
transports: [
transport
]
});
for(let i=0; i< 100; i++){
logger.info('Hello World!');
}
var str = 'CGI-2019-02-28.log';
var _arr = str.replace(/\.log/,'').split('-');
_arr.shift();
console.log(_arr.join('-'));