如何只记录到pm2流日志?

时间:2017-12-14 05:19:47

标签: node.js logging pm2

我正在使用带有文件process.json的pm2运行express js框架

{
  "apps": [
    {
      "name": "api-starter",
      "script": "server.js",
      "watch": false,
      "ignore_watch": [
        "/[\s\S].spec.js$/",
        "node_modules",
        "temp",
        "logs/*"
      ],
      "exec_mode": "fork",
      "instances": 1,
      "log_date_format": "YYYY-MM-DD HH:mm:ssZ",
      "error_file": "logs/error.log",
      "out_file": "logs/out.log",
      "min_uptime": 500,
      "max_restarts": 10,
      "restart_delay": 1000,
      "env_development": {
        "NODE_ENV": "development",
        "watch": true
      },
      "env_production": {
        "NODE_ENV": "production"
      }
    }
  ]
}

我使用npm包pretty-error,它的真棒包使我的错误堆栈看起来更好。但是当pm2尝试保存在日志文件中时它变得不可读,有没有办法避免pm2将其记录到文件但保持流模式。

2017-12-14 01:22:35+07:00:   [0m[97m[41mReferenceError[0m[90m:[0m[37m [0m[97masd is not defined[0m
[0m  [0m
[0m  [0m[90m-[0m [0m[93mindex.js[0m[90m:[0m[93m5[0m[37m [0m[37mrouter.get[0m
[0m  [0m  [0m[90mC:/Users/mungil/Desktop/express-api-starter/app/routes/index.js:5:43[0m
[0m  [0m
[0m  [0m[90m-[0m [0m[93mlayer.js[0m[90m:[0m[93m95[0m[37m [0m[37mLayer.handle [as handle_request][0m
[0m  [0m  [0m[90m[express-api-starter]/[express]/lib/router/layer.js:95:5[0m
[0m  [0m
[0m  [0m[90m-[0m [0m[93mroute.js[0m[90m:[0m[93m137[0m[37m [0m[37mnext[0m
[0m  [0m  [0m[90m[express-api-starter]/[express]/lib/router/route.js:137:13[0m
[0m  [0m
[0m  [0m[90m-[0m [0m[93mroute.js[0m[90m:[0m[93m112[0m[37m [0m[37mRoute.dispatch[0m
[0m  [0m  [0m[90m[express-api-starter]/[express]/lib/router/route.js:112:3[0m
[0m  [0m
[0m  [0m[90m-[0m [0m[93mlayer.js[0m[90m:[0m[93m95[0m[37m [0m[37mLayer.handle [as handle_request][0m
[0m  [0m  [0m[90m[express-api-starter]/[express]/lib/router/layer.js:95:5[0m
[0m  [0m
[0m  [0m[90m-[0m [0m[93mindex.js[0m[90m:[0m[93m281[0m[37m [0m
[0m  [0m  [0m[90m[express-api-starter]/[express]/lib/router/index.js:281:22[0m
[0m  [0m
[0m  [0m[90m-[0m [0m[93mindex.js[0m[90m:[0m[93m335[0m[37m [0m[37mFunction.process_params[0m
[0m  [0m  [0m[90m[express-api-starter]/[express]/lib/router/index.js:335:12[0m
[0m  [0m
[0m  [0m[90m-[0m [0m[93mindex.js[0m[90m:[0m[93m275[0m[37m [0m[37mnext[0m
[0m  [0m  [0m[90m[express-api-starter]/[express]/lib/router/index.js:275:10[0m
[0m  [0m
[0m  [0m[90m-[0m [0m[93mindex.js[0m[90m:[0m[93m174[0m[37m [0m[37mFunction.handle[0m
[0m  [0m  [0m[90m[express-api-starter]/[express]/lib/router/index.js:174:3[0m
[0m  [0m
[0m  [0m[90m-[0m [0m[93mindex.js[0m[90m:[0m[93m47[0m[37m [0m[37mrouter[0m
[0m  [0m  [0m[90m[express-api-starter]/[express]/lib/router/index.js:47:12[0m
[0m  [0m
[0m

1 个答案:

答案 0 :(得分:0)

添加/dev/null作为out_file,' err_file'的值和 process.json 条目

中的log_file
{
  "out_file": "/dev/null",
  "err_file": "/dev/null",
  "log_file": "/dev/null",
}

More Details