log4js-node icon indicating copy to clipboard operation
log4js-node copied to clipboard

when i use the pm2, The log4js log segmentation is not work?

Open qingyang-id opened this issue 8 years ago • 2 comments

my log4j config is:

  appenders: {
    console: { type: 'console' },
    out: {
      type: 'file',
      filename: './logs/out.log',
      maxLogSize: 10 * 1024,
      layout: {
        type: 'basic'
      },
      backups: 5,
    },
    error: {
      type: 'file',
      filename: './logs/error.log',
      maxLogSize: 10 * 1024,
      layout: {
        type: 'basic'
      },
      backups: 5,
    },
    zk: {
      type: 'file',
      filename: './logs/zk.log',
      // 1M 单文件大小,单位字节
      maxLogSize: 10 * 1024 * 1024,
      backups: 5
    },
    monitor: {
      type: 'file',
      filename: './logs/monitor.log',
      // 1M 单文件大小,单位字节
      maxLogSize: 10 * 1024 * 1024,
      backups: 5
    },
    cron: {
      type: 'dateFile',
      filename: './logs/cron.log',
      pattern: '-yyyy-MM-dd.log',
    },
  },
  categories: {
    default: { appenders: ['console', 'out'], level: 'info' },
    error: { appenders: ['error'], level: 'error' },
    zk: { appenders: ['zk'], level: 'info' },
    monitor: { appenders: ['monitor'], level: 'info' },
    cron: { appenders: ['cron'], level: 'info' },
  }
};

and the pm2 config is:

  "apps": [
    {
      "name": "api-server",
      "script": "src/app.js",
      "max_memory_restart": "1G",
      "error_file"      : "./logs/error.log",
      "out_file"        : "./logs/out.log",
      // "out_file": "/dev/null",
      // "error_file": "/dev/null",
      "merge_logs"      : true,
      "log_date_format" : "YYYY-MM-DD HH:mm Z",
      "env": {
        "NODE_ENV": "development"
      },
      "env_test" : {
        "NODE_ENV": "test"
      },
      "env_pro" : {
        "NODE_ENV": "production"
      }
    },
    {
      "name": "cron-server",
      "script": "src/cron.js",
      "max_memory_restart": "1G",
      "error_file"      : "./logs/error.log",
      "out_file"        : "./logs/out.log",
      "merge_logs"      : true,
      "log_date_format" : "YYYY-MM-DD HH:mm Z",
      "env": {
        "NODE_ENV": "development"
      },
      "env_test" : {
        "NODE_ENV": "test"
      },
      "env_pro" : {
        "NODE_ENV": "production"
      }
    }
  ]
}

But the error.log log segmentation is not work! what should i do? node 6.9.11 pm2 2.6.1 log4js 2.3.11

thanks for first!

qingyang-id avatar Nov 06 '17 14:11 qingyang-id

Can you provide some more information so we can troubleshoot? The following would help:

  1. When you say that the error.log segmentation does not work, what do you mean? Errors? No log messages?
  2. Can you share the code to create and use the error logger?
  3. Are all other loggers (default, zk, etc) working fine?
  4. If you try to call the error logger without pm2, does it work fine?

ramicohen303 avatar Nov 07 '17 02:11 ramicohen303

1、no log messages was wrote 2、all log was not work 4、without pm2, all log working fine

qingyang-id avatar Sep 28 '18 12:09 qingyang-id