node.js - How does PM2 define that log content has access IP?
世界只因有你
世界只因有你 2017-05-16 13:45:08
0
2
828

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?

世界只因有你
世界只因有你

reply all(2)
巴扎黑

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

滿天的星座

pm2实现不了你这功能,需要配置log4jsto handle

The 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"
}

log4jsThe npm documentation is very detailed, I’ll just give you some ideas

  1. Initializationlog4js(define file path, segmentation rules)

  2. express uses app.user(log4jsInstance.connectLogger, please check the documentation for specific API)

  3. Use pm2 to start express app

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template