Currently I have implemented and express.js application and I have added log4js logger for logging purposes. Now I wanted to write logs into Redis and then background worker which continuously pulls logs from the Redis List and write those logs into a local log files.
App.js would look like this
import { getLogger, configure } from 'log4js';
import {initServer} from './middleware/Express'
import { initRoutes } from './routes/RouterAggregator';
configure('./src/config/log4js-config.json');
const logger = getLogger("app");
const init = ()=> {
logger.info("Initializing Application");
initServer();
initRoutes();
};
And log configuration file would look like this.
{
"appenders": [
{
"type": "console",
"layout": {
"type": "pattern",
"pattern": "[%d] [%[%p%]] %c {%x{ln}} - %m",
"tokens": {
"ln" : "loggerFunction()"
}
}
},
{
"type": "dateFile",
"filename": "log/access.log",
"pattern": "-yyyy-MM-dd",
"alwaysIncludePattern": false,
"category": "http",
"layout": {
"type" : "pattern",
"pattern": "[%d] [%p] %c {%x{ln}} - %m",
"tokens": {
"ln" : "loggerFunction()"
}
}
},
{
"type": "dateFile",
"filename": "log/app.log",
"maxLogSize": 10485760,
"numBackups": 3,
"alwaysIncludePattern": false,
"layout": {
"type" : "pattern",
"pattern": "[%d] [%p] %c {%x{ln}} - %m",
"tokens": {
"ln" : "loggerFunction()"
}
}
},
{
"type": "logLevelFilter",
"level": "ERROR",
"appender": {
"type": "file",
"filename": "log/errors.log"
},
"layout": {
"type" : "pattern",
"pattern": "[%d] [%p] %c {%x{ln}} - %m",
"tokens": {
"ln" : "loggerFunction()"
}
}
}
]
}
I want to know how to add redis to support above mentioned functionality.