Nodejs如何打印日志文件
工具/原料
log4js
nodejs
方法/步骤
1、安装log4js---npmilog4js
2、引入和配置log4js
3、配置log4js.json
4、varlog4js=require('挢旗扦渌;log4js');//注意log4js的module位置引用是否丬涪斟享正确returnlog4js.configure({appenders:[{type:'console',category:"console"},//控制台输出{type:"dateFile",filename:'logs/',pattern:"yyyy-MM-dd.log",alwaysIncludePattern:true,category:'console'//将console打印的输入到log文件}//日期文件格式],replaceConsole:true,//替换console.loglevels:{logInfo:'all',//输出到日志文件}});
5、{"appenders":咯悝滩镞[{"type":"console&q锇栀劐箨uot;,"category":"console"},{"category":"log_file","type":"file","filename":"./logs/log_file/file.log","maxLogSize":104800,"backups":100},{"category":"log_date","type":"dateFile","filename":"./logs/log_date/date","alwaysIncludePattern":true,"pattern":"-yyyy-MM-dd-hh.log"}],"replaceConsole":true,"levels":{"log_file":"ALL","console":"ALL","log_date":"ALL"}}