js记录日志工具log4js,参数请参考官网文档https://log4js-node.github.io/log4js-node/index.html
const log4js = require('log4js'); const path = require('path'); log4js.configure({ appenders: { info1: { type: 'file', filename: path.resolve(__dirname, 'logs/info.log') }, info2: { type: 'dateFile', filename: path.resolve(__dirname, 'logs/statistics'), pattern: 'yyyy-MM-dd.log', alwaysIncludePattern: true }, errors: { type: 'file', filename: path.resolve(__dirname, 'logs/error.log') } }, categories: { autoInfo: { appenders: ['info1'], level: 'info' }, staInfo: { appenders: ['info2'], level: 'info' }, error: { appenders: ['errors'], level: 'error' }, default: { appenders: ['errors'], level: 'error' } } }); // getLogger参数是categories里的 module.exports = { infoLog: log4js.getLogger('autoInfo'), errorLog: log4js.getLogger('error'), staLog: log4js.getLogger('staInfo') };