您的位置:首頁技術文章
文章詳情頁

javascript - log4js的使用問題

瀏覽:81日期:2023-08-25 15:30:33

問題描述

router.get(’/render’, async (ctx, next) => { const log = require(’../util/log.js’) log(’render’,’123’) await ctx.render(’index’,{title:’wanghao’})})

//../util/log.jsfunction 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.loglevels:{ 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’里面 請問為神馬 ?

問題解答

回答1:

你定義了log方法來使用log4js,但是你沒使用你的log方法啊,而且log4js也不是這么記錄log的,你看你的log方法里,

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

這段才是用來打log的

如果你的log是單獨的模塊的話,這么改試試:

const log = require(’./log’);router.get(’/render’, async (ctx, next) => { log(’render’,’123’) await ctx.render(’index’,{title:’wanghao’})})

標簽: JavaScript
相關文章:
国产综合久久一区二区三区