Egg: 关于日志打印目录的问题

Created on 7 May 2018  ·  3Comments  ·  Source: eggjs/egg

官方说:在非开发期的环境(非 local 和 unittest 环境),所有的日志都会打印到 $HOME/logs 文件夹下,那如果我在同一台机上部署多个eggjs项目的话,是会覆盖还是叠加,不会和乱吗?好像我配置了日志打印目录后,除了我指定的目录以外,$HOME/logs 文件夹下还是会打印日志,想请教下这个问题该怎么解决!谢谢

Most helpful comment

首先eggjs产生的日志有三类。

  • 业务日志
    common-error.log
    egg-agent.log
    egg-web.log
    ${appInfo.name}-web.log
  • 定时任务日志
    egg-schedule.log

  • 框架启动日志
    master-stderr.log
    master-stdout.log

默认情况下,
业务日志和定时任务日志都在${appInfo.root}/logs/${appInfo.name}目录下,例如 /home/admin/logs/example-app
而框架启动日志在${appInfo.root}/logs/目录下。

当你要把日志文件转移到指定目录下,分三步。
第一步对业务日志,需修改配置文件config.{env}.js

config.logger = {
  dir: '日志目录路径',
};

第二步对定时任务日志,需修改配置文件config.{env}.js

config.customLogger = {
   scheduleLogger: {
      consoleLevel: 'NONE',
      file: 'aaa/bbb/egg-schedule.log',   // 新日志文件路径
    },
 };

config.schedule = {
    directory: [],
};

第三步对框架启动日志,需要在启动命令上加参数

npm run start -- --stdout="/xx/master-stdout.log" --stderr="/xx/master-stderr.log"

All 3 comments

Translation of this issue:


Questions about the log print directory

The official said: In the non-development environment (non-local and unittest environment), all the logs will be printed to the $HOME/logs folder, if I deploy multiple eggjs projects on the same machine, it will cover or overlay Will not be confused? I seem to configure the log print directory, in addition to the directory I specify, the $HOME/logs folder will still print the log, I would like to ask how to solve this problem! Thank you

  • all logs will output to $HOME/logs/{app_name}, so don't worry about override.
  • change dir like this:
  config.logger = {
    dir: path.join(appInfo.root, 'logs'),
  };

首先eggjs产生的日志有三类。

  • 业务日志
    common-error.log
    egg-agent.log
    egg-web.log
    ${appInfo.name}-web.log
  • 定时任务日志
    egg-schedule.log

  • 框架启动日志
    master-stderr.log
    master-stdout.log

默认情况下,
业务日志和定时任务日志都在${appInfo.root}/logs/${appInfo.name}目录下,例如 /home/admin/logs/example-app
而框架启动日志在${appInfo.root}/logs/目录下。

当你要把日志文件转移到指定目录下,分三步。
第一步对业务日志,需修改配置文件config.{env}.js

config.logger = {
  dir: '日志目录路径',
};

第二步对定时任务日志,需修改配置文件config.{env}.js

config.customLogger = {
   scheduleLogger: {
      consoleLevel: 'NONE',
      file: 'aaa/bbb/egg-schedule.log',   // 新日志文件路径
    },
 };

config.schedule = {
    directory: [],
};

第三步对框架启动日志,需要在启动命令上加参数

npm run start -- --stdout="/xx/master-stdout.log" --stderr="/xx/master-stderr.log"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bupafengyu picture bupafengyu  ·  3Comments

popomore picture popomore  ·  3Comments

wujianling picture wujianling  ·  3Comments

kylezhang picture kylezhang  ·  3Comments

AkashiX picture AkashiX  ·  4Comments