log4js-node
log4js-node copied to clipboard
[SOLUTION] Log4js with pm2 monit and pm2 logs
I would like to explaned my solution to problem in viewer logs in pm2 monit and pm2 logs.
My logger.js
import log4js from 'log4js'
log4js.configure( {
appenders : {
viewerLogsInPM2 : { type : 'stdout' },
everything : {
type : 'dateFile',
filename : 'logs/orchestrator.log',
// pattern : 'yyyy-MM-dd',
pattern : 'yyyy-MM-dd-hh-mm',
maxLogSize : '1G',
numBackups : 30,
compress : false,
keepFileExt : true,
fileNameSep : '-',
layout : {
type : 'pattern',
pattern : '%d{yyyy-MM-dd hh:mm:ss.SSS}|orchestrator|%m'
}
},
errorFile : {
type : 'dateFile',
filename : 'logs/orchestrator-errors.log',
// pattern : '-yyyy-MM-dd',
pattern : 'yyyy-MM-dd-hh-mm',
maxLogSize : '1G',
numBackups : 60,
compress : false,
keepFileExt : true,
fileNameSep : '-',
layout : {
type : 'pattern',
pattern : '%d{yyyy-MM-dd hh:mm:ss.SSS}|orchestrator|%m'
}
},
errors : {
type : 'logLevelFilter',
level : 'ERROR',
appender : 'errorFile'
}
},
categories : {
default : { appenders : ['viewerLogsInPM2', 'everything', 'errors'], level : 'debug' },
},
pm2 : true,
pm2InstanceVar : '0'
} )
const logger = log4js.getLogger()
export default logger
My ecosystem.config.js
module.exports = {
apps : [
{
name : 'orchestrator',
script : './build/src/app.js',
watch : false,
instance_var: 0,
env : {
PORT : 3000,
NODE_ENV : 'production'
}
}
]
}
My logger file is generated the following files:
logs/orchestrator-errors-2022-08-24-16-05-1.log
logs/orchestrator-2022-08-24-16-05-1.log
logs/orchestrator.log (now)
logs/orchestrator-errors.log (now)
ps.: enabled pattern with 'yyyy-MM-dd-hh-mm' to test rotate, after test, enable the pattern yyyy-MM-dd for daily rotate
Friends, i would like to apologize for polluting the issue queue, but, i struggled to get this to work and maybe it will be useful for someone else =D
@tidanielcarvalho, thanks for sharing the solution but what was the original problem for some context?
@tidanielcarvalho?
@tidanielcarvalho?
@tidanielcarvalho?
Closed due to extended period of inactivity.