javascript - log4js的使用問題
問題描述
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’并沒有寫進(jìn)到‘。。、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’})})
相關(guān)文章:
1. angular.js - angular ng-class里面的引號問題2. css - 對于類選擇器使用的問題3. javascript - Web微信聊天輸入框解決方案4. docker - 如何修改運行中容器的配置5. javascript - Ajax加載Json時,移動端頁面向左上角縮小一截兒,加載完成后才正常顯示,這該如何解決?6. javascript - es6將類數(shù)組轉(zhuǎn)化成數(shù)組的問題7. javascript - history.replaceState()無法改變query參數(shù)8. javascript - react 中綁定事件和阻止事件冒泡9. mysql無法添加外鍵10. matplotlib - python函數(shù)的問題
