log4js 2怎么设置日志等级
好像去掉了 setLevel方法, 请问怎么根据环境设置不通等级的日志输入
3 回复
const log4js = require('log4js');
log4js.configure({
appenders: {
out: { type: 'stdout' },
app: { type: 'file', filename: 'application.log' }
},
categories: {
default: { appenders: [ 'out', 'app' ], level: 'debug' }
}
});
config的时候配置
import { configure, getLogger } from './log4js';
configure('./filename');
const logger = getLogger();
logger.level = 'debug';
logger.debug("Some debug messages");
configure({
appenders: { cheese: { type: 'file', filename: 'cheese.log' } },
categories: { default: { appenders: ['cheese'], level: 'error' } }
});
@imhered 多谢多谢,