yxfanxiao / yxfanxiao.github.io

My Blog Space
3 stars 0 forks source link

Log4js Note #16

Open yxfanxiao opened 8 years ago

yxfanxiao commented 8 years ago
var log4js = require('log4js')

log4js.configure({
    appenders: [{
        type: 'DateFile',
        filename: 'log/access/access.log',
        pattern: '-yyyy-MM-dd.log',
        alwaysIncludePattern: true,
        category: 'access'
    }, {
        type: 'logLevelFilter',
        level: 'DEBUG',
        category: 'daily',
        appender: {
            type: 'file',
            filename: 'log/default.log'
        }
    }]
})

var log1 = log4js.getLogger('daily')
var log2 = log4js.getLogger('access')

/**
 * Connect Express
 */
// app.use(log4js.connectLogger(log4js.getLogger('access'), { level: log4js.levels.INFO }))

log1.trace('Log1 trace')
log1.debug('Log1 debug')
log1.info('Log1 info')
log1.warn('Log1 warn')
log1.error('Log1 error')

log2.trace('Log2 trace')
log2.debug('Log2 debug')
log2.info('Log2 info')
log2.warn('Log2 warn')
log2.error('Log2 error')
yxfanxiao commented 8 years ago

https://github.com/opencredo/opencredo-react-boilerplate/blob/master/webpack.config.js