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;
可是‘123’並沒有寫進到‘。 。 、logrecord.log’裡面 請問為神馬 ?
你定義了log方法來使用log4js,但是你沒使用你的log方法啊,
而且log4js也不是這麼記錄log的,你看你的log方法裡,
這段才是用來打log的
如果你的log是單獨的模組的話,這麼改試試: