Not a expert in nodes, this is my first time using log4js-node.
I am attempting to log my ERROR logs and any console logs to a file named log_file.log using log4js on a nodejs server running Express. Below is my configuration 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": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2cfdbc7cfc3cbcee2c5cfc3cbce8cc1cdcf">[email protected]</a>",
"sender": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84e9fde1e9e5ede8e5e0e0c4e3e9e5ede8aae7ebe9">[email protected]</a>",
"sendInterval": 60,
"transport": "SMTP",
"SMTP": {
"host": "localhost",
"port": 25
}
}
}]
}`
This is how I'm including the application in my app.js file:
var log4js = require("log4js");
log4js.configure("log_config.json")
logger = log4js.getLogger();
I'm manually sending errors to log4js like this (able to log to console but not to the log_file):
logger.error('A mandrill error occurred: ' + e.name + ' - ' + e.message);
Additionally, I want log4js to capture the application's standard ERROR messages.
How can I configure log4js to log to the log_file.log and then email me that log? Note that I have nodemailer 0.7 installed for smtp handling.