In the nodejs project, the log uses the log function that comes with pm2.
I hope that the log content can include the access IP and the log can be divided by day. How to set it up?
巴扎黑2017-05-16 13:47:08
If the console prints ip in the project, it will be output to the pm2 log file. Log splitting by day requires configuration
pm2
Parameters.
soonfy
滿天的星座2017-05-16 13:47:08
pm2实现不了你这功能
,需要配置log4js
to handleThe log function parameters provided by pm2 are as follows
--merge-logs 不合并process id
--log-date-format <format> 日期格式化
-l --log [path] 日志文件路径(标准输出+错误输出)
-o --output <path> 日志文件路径(标准输出)
-e --error <path> 日志文件路径(错误输出)
Example
{
"script" : "echo.js",
"error_file" : "err.log",
"out_file" : "out.log",
"merge_logs" : true,
"log_date_format" : "YYYY-MM-DD HH:mm Z"
}
log4js
The npm documentation is very detailed, I’ll just give you some ideas
Initializationlog4js
(define file path, segmentation rules)
express uses app.user(log4jsInstance.connectLogger, please check the documentation for specific API)
Use pm2 to start express app