[英]log4js-node in nodejs not logging to file
Not a node expert, and this is the first time I'm using log4js -node. 不是节点专家,这是我第一次使用log4js -node。
I am trying to get my ERROR logs and any of my console logs to write to a log_file.log file with log4js on a nodejs server running Express. 我正在尝试获取我的错误日志和任何控制台日志,以在运行Express的nodejs服务器上使用log4js写入log_file.log文件。 Here is my config file:`
这是我的配置文件:
{
"replaceConsole": true,
"appenders": [
{
"type": "file",
"filename":"log_file.log",
"maxLogSize":20480,
"backups": 3,
"category":"relative-logger"
},
{
"type":"logLevelFilter",
"level":"ERROR",
"appender":{
"type":"file",
"filename":"log_file.log"
}
},
{
"appender": {
"type": "smtp",
"recipients": "myemail@gmail.com",
"sender": "myemailadd@gmail.com",
"sendInterval": 60,
"transport": "SMTP",
"SMTP": {
"host": "localhost",
"port": 25
}
}
}]
}`
And here is how I'm requiring the application in my app.js file: 这是我在app.js文件中要求该应用程序的方式:
var log4js = require("log4js");
log4js.configure("log_config.json")
logger = log4js.getLogger();
I'm sending manual errors to log4js with this (I can get this to log to the console fine, just can't get the log_file written): 我正在使用此方法向log4js发送手动错误(我可以将其错误地记录到控制台,只是无法获取log_file):
logger.error('A mandrill error occurred: ' + e.name + ' - ' + e.message);
And I'm hoping jog4js catches the application's normal ERROR messages. 而且我希望jog4js能够捕获应用程序的常规ERROR消息。
How do I get log4js to log to the log_file.log them send me an email of that log? 我如何让log4js登录到log_file.log,它们向我发送该日志的电子邮件? I have installed nodemailer 0.7, fyi, to handle smtp.
我已经安装了nodemailer 0.7 fyi来处理smtp。
也许您可以在文件附加程序中删除"category":"relative-logger"
。
Yes remove "category":"relative-logger" it somehow blocks the data transfer into your log file.. Or try something like this: 是的,删除“ category”:“ relative-logger”会以某种方式阻止数据传输到您的日志文件中。或者尝试执行以下操作:
// Setup Logging log4js.configure({ appenders: [ { type: 'console' }, { type: 'file', filename: '.\\\\logs\\\\PesaFastaArchiveData.log' } ] });
The path is of-course the windows path. 当然,该路径是Windows路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.