Home  >  Q&A  >  body text

node.js - How does PM2 define that log content has access IP?

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?

世界只因有你世界只因有你2683 days ago745

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑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

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-16 13:47:08

    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

    reply
    0
  • Cancelreply