log4js-example icon indicating copy to clipboard operation
log4js-example copied to clipboard

app.log is also including access logs

Open anperez78 opened this issue 8 years ago • 2 comments

anperez78 avatar Aug 25 '15 15:08 anperez78

I am having the same problem. Any idea how to change the configuration so this won't happen ?

dehlen avatar Feb 29 '16 10:02 dehlen

Basically you can have two appenders, one for application logs and another one for access logs. Then just exclude application from access logs (category 'http'):

                {
                    "type": "dateFile",
                    "filename": config.server.logs.accessLogs.filename,
                    "pattern": "-yyyy-MM-dd",
                    "layout": {"type": "messagePassThrough"},
                    "category": "http"
                },
                {
                    "type": "categoryFilter",
                    "exclude": ["http"],
                    "appender": {
                        "type": "dateFile",
                        "filename": config.server.logs.applicationLogs.filename,
                        "pattern": "-yyyy-MM-dd",
                        "layout": {
                            "type": "pattern",
                            "pattern": commonPattern,
                            "tokens": commonPatternTokens
                        }
                    }
                }

Then you need to set an specific connector for those access logs:

app.use(log4js.connectLogger(log4js.getLogger('http'), { level: 'auto', format: config.server.logs.accessLogs.pattern }))

anperez78 avatar Mar 10 '16 12:03 anperez78