javascript - Problems using log4js
扔个三星炸死你
扔个三星炸死你 2017-07-06 10:34:37
0
1
942
router.get('/render', async (ctx, next) => {
    const log = require('../util/log.js')
     log('render','123')
     await ctx.render('index',{title:'wanghao'})
})



//../util/log.js
function log(f_name='index',f_log_msg=2){
    const log4js = require('log4js');
    log4js.configure({
    appenders: [
            {
                type: 'console',
                category: "console"
            }, 
            {
                type: "dateFile",
                filename: '../logrecord/log',
                pattern: "_yyyyMMdd.log",   //日期文件格式
                // absolute: false,
                alwaysIncludePattern: true,
                maxLogSize: 20480,
                backups: 3
                // category: 'logInfo'     //过滤功能
            }
        ],
        replaceConsole: true,   //替换console.log
        levels:{
            logInfo: 'info',
            console: 'debug' 
        }
    });
    console.log(f_name) //render
    const logger = log4js.getLogger(f_name); 
     logger.info(f_log_msg);
}
module.exports=log;

But ‘123’ was not written into ‘. . , logrecord.log’ What is the name of Shenma?

扔个三星炸死你
扔个三星炸死你

reply all(1)
小葫芦

You defined the log method to use log4js, but you did not use your log method,
And log4js does not record logs in this way. Look at your log method,

const logger = log4js.getLogger(f_name); 
logger.info(f_log_msg);

This paragraph is for logging

If your log is a separate module, try changing it like this:

const log = require('./log');
router.get('/render', async (ctx, next) => {
     log('render','123')
     await ctx.render('index',{title:'wanghao'})
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template