Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egg-logger 在prod环境下没有输出 #489

Closed
kkys4bfgp75be9p opened this issue Mar 1, 2017 · 36 comments
Closed

egg-logger 在prod环境下没有输出 #489

kkys4bfgp75be9p opened this issue Mar 1, 2017 · 36 comments
Assignees

Comments

@kkys4bfgp75be9p
Copy link

kkys4bfgp75be9p commented Mar 1, 2017

  • Node Version: v7.0.0
  • Egg Version: v1.0.0-rc.2
  • Plugin Name: Egg-logger
  • Plugin Version:
  • Platform: Mac os

egg-logger 不能在生产环境(production)下写入log文件。本地和测试环境之下可以写入文件。

如何得出的结论:

  1. 下载example custom-env 例子
  2. npm i
  3. 加入 index.js
'use strict';

// npm run dev DO NOT read this file

const isLocal = process.env.NODE_ENV !== 'production' && !process.env.EGG_SERVER_ENV;

require('egg').startCluster({
  baseDir: __dirname,
  port: process.env.PORT || 7002, // default to 7001
  workers: isLocal ? 1 : undefined, // default to cpu count
});

4 加入code到home controller

exports.index = function* index(ctx) {
  ctx.logger.info('test')
  ctx.body = {
    env: ctx.app.config.env,
    config: ctx.app.config.keys,
  };
};
  1. command line start:
EGG_SERVER_ENV=prod npm start
  1. console 没有任何输出, logs文件夹底下没有文件更新
@atian25
Copy link
Member

atian25 commented Mar 1, 2017 via email

@kkys4bfgp75be9p
Copy link
Author

@atian25

"logger": {
      "dir": "/Users/zhangming0305/logs/custom-env",
      "encoding": "utf8",
      "env": "prod",
      "level": "INFO",
      "consoleLevel": "INFO",
      "outputJSON": false,
      "buffer": true,
      "appLogName": "custom-env-web.log",
      "coreLogName": "egg-web.log",
      "agentLogName": "egg-agent.log",
      "errorLogName": "common-error.log",
      "coreLogger": {},
      "type": "application"
    },

不管是local还是prod环境下,logger输出的dir都是不变的
不过在prod环境下里面空的,在local环境下是能生成4个文件的。

@atian25
Copy link
Member

atian25 commented Mar 1, 2017 via email

@kkys4bfgp75be9p
Copy link
Author

@atian25 在prod环境下没有,在本地开发和测试有日志

@dead-horse
Copy link
Member

@zhangming0305 你检查的是你项目根目录下吧

@dead-horse
Copy link
Member

local 环境下的 dir 不会是 /Users/zhangming0305/logs/custom-env 除非你自行指定了。

@kkys4bfgp75be9p
Copy link
Author

@atian25 @dead-horse 我在自己的工程和你们examples/custom-env下试过多次,不知道什么原因。我上传了custom-env: https://github.com/zhangming0305/custom-env.git 请帮忙下载运行看看为什么prod下没有任何log文件产生。

@atian25
Copy link
Member

atian25 commented Mar 3, 2017

@zhangming0305 你先不要 env 这个,egg-init --type=simple 这个测试下

@kkys4bfgp75be9p
Copy link
Author

刚刚测试了一下

  1. 升级了egg-init 到1.8
  2. egg-init egg-example --type=simple
  3. 添加了测试logger语句到home controller
  4. local 测试 npm start, logs目录底下生成4个log文件
  5. 删除所有log文件
  6. EGG_SERVER_ENV=prod npm start
  7. 没有任何文件生成
:egg-example mingzhang$ EGG_SERVER_ENV=prod npm start

> egg-example@1.0.0 start /Users/mingzhang/workspace/egg-example
> node index.js

2017-03-03 09:05:26,006 INFO 26567 [master] =================== egg start =====================
2017-03-03 09:05:26,007 INFO 26567 [master] egg version 0.9.0
2017-03-03 09:05:26,008 INFO 26567 [master] start with options: {"framework":"/Users/mingzhang/workspace/egg-example/node_modules/egg","baseDir":"/Users/mingzhang/workspace/egg-example","port":7001,"workers":8,"plugins":null,"https":false,"key":"","cert":"","customEgg":"/Users/mingzhang/workspace/egg-example/node_modules/egg"}
2017-03-03 09:05:26,008 INFO 26567 [master] start with env: isProduction: true, isDebug: false, EGG_SERVER_ENV: prod, NODE_ENV: undefined
2017-03-03 09:05:26,014 INFO 26567 [master] Agent Worker:26568 start with ["{\"framework\":\"/Users/mingzhang/workspace/egg-example/node_modules/egg\",\"baseDir\":\"/Users/mingzhang/workspace/egg-example\",\"port\":7001,\"workers\":8,\"plugins\":null,\"https\":false,\"key\":\"\",\"cert\":\"\",\"customEgg\":\"/Users/mingzhang/workspace/egg-example/node_modules/egg\",\"clusterPort\":52278}"]
2017-03-03 09:05:26,243 INFO 26568 [egg:logger] init all loggers with options: {"dir":"/Users/mingzhang/logs/egg-example","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-example-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"agent"}
2017-03-03 09:05:26,292 WARN 26568 [egg-watcher] defaultEventSource watcher will NOT take effect
2017-03-03 09:05:26,293 INFO 26568 [egg:agent] create an AgentWorkerClient for "watcher"
2017-03-03 09:05:26,316 INFO 26568 [egg:watcher:agent] watcher start success
2017-03-03 09:05:26,319 INFO 26567 [master] Agent Worker started (309ms)
2017-03-03 09:05:26,345 INFO 26567 [master] App Worker#1:26569 start, state: none, current workers: ["1","2","3","4","5","6","7","8"]
2017-03-03 09:05:26,345 INFO 26567 [master] App Worker#2:26570 start, state: none, current workers: ["1","2","3","4","5","6","7","8"]
2017-03-03 09:05:26,345 INFO 26567 [master] App Worker#3:26571 start, state: none, current workers: ["1","2","3","4","5","6","7","8"]
2017-03-03 09:05:26,346 INFO 26567 [master] App Worker#4:26572 start, state: none, current workers: ["1","2","3","4","5","6","7","8"]
2017-03-03 09:05:26,346 INFO 26567 [master] App Worker#5:26573 start, state: none, current workers: ["1","2","3","4","5","6","7","8"]
2017-03-03 09:05:26,346 INFO 26567 [master] App Worker#6:26574 start, state: none, current workers: ["1","2","3","4","5","6","7","8"]
2017-03-03 09:05:26,346 INFO 26567 [master] App Worker#7:26575 start, state: none, current workers: ["1","2","3","4","5","6","7","8"]
2017-03-03 09:05:26,346 INFO 26567 [master] App Worker#8:26576 start, state: none, current workers: ["1","2","3","4","5","6","7","8"]
2017-03-03 09:05:26,898 INFO 26570 [egg:logger] init all loggers with options: {"dir":"/Users/mingzhang/logs/egg-example","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-example-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"application"}
2017-03-03 09:05:26,903 INFO 26569 [egg:logger] init all loggers with options: {"dir":"/Users/mingzhang/logs/egg-example","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-example-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"application"}
2017-03-03 09:05:26,905 INFO 26569 [egg:worker] create an AppWorkerClient for "watcher"
2017-03-03 09:05:26,905 INFO 26570 [egg:worker] create an AppWorkerClient for "watcher"
2017-03-03 09:05:26,922 INFO 26575 [egg:logger] init all loggers with options: {"dir":"/Users/mingzhang/logs/egg-example","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-example-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"application"}
2017-03-03 09:05:26,924 INFO 26575 [egg:worker] create an AppWorkerClient for "watcher"
2017-03-03 09:05:26,925 INFO 26573 [egg:logger] init all loggers with options: {"dir":"/Users/mingzhang/logs/egg-example","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-example-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"application"}
2017-03-03 09:05:26,927 INFO 26573 [egg:worker] create an AppWorkerClient for "watcher"
2017-03-03 09:05:26,926 INFO 26571 [egg:logger] init all loggers with options: {"dir":"/Users/mingzhang/logs/egg-example","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-example-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"application"}
2017-03-03 09:05:26,926 INFO 26574 [egg:logger] init all loggers with options: {"dir":"/Users/mingzhang/logs/egg-example","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-example-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"application"}
2017-03-03 09:05:26,927 INFO 26572 [egg:logger] init all loggers with options: {"dir":"/Users/mingzhang/logs/egg-example","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-example-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"application"}
2017-03-03 09:05:26,929 INFO 26571 [egg:worker] create an AppWorkerClient for "watcher"
2017-03-03 09:05:26,931 INFO 26574 [egg:worker] create an AppWorkerClient for "watcher"
2017-03-03 09:05:26,931 INFO 26572 [egg:worker] create an AppWorkerClient for "watcher"
2017-03-03 09:05:26,931 INFO 26576 [egg:logger] init all loggers with options: {"dir":"/Users/mingzhang/logs/egg-example","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"egg-example-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"application"}
2017-03-03 09:05:26,933 INFO 26576 [egg:worker] create an AppWorkerClient for "watcher"
2017-03-03 09:05:26,971 INFO 26570 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/clean_log.js
2017-03-03 09:05:26,971 INFO 26570 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/rotate_by_file.js
2017-03-03 09:05:26,978 INFO 26569 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/clean_log.js
2017-03-03 09:05:26,978 INFO 26569 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/rotate_by_file.js
2017-03-03 09:05:26,998 INFO 26574 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/clean_log.js
2017-03-03 09:05:26,998 INFO 26574 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/rotate_by_file.js
2017-03-03 09:05:27,000 INFO 26575 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/clean_log.js
2017-03-03 09:05:27,000 INFO 26575 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/rotate_by_file.js
2017-03-03 09:05:27,001 INFO 26573 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/clean_log.js
2017-03-03 09:05:27,001 INFO 26573 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/rotate_by_file.js
2017-03-03 09:05:27,001 INFO 26571 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/clean_log.js
2017-03-03 09:05:27,001 INFO 26571 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/rotate_by_file.js
2017-03-03 09:05:27,002 INFO 26576 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/clean_log.js
2017-03-03 09:05:27,002 INFO 26576 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/rotate_by_file.js
2017-03-03 09:05:27,006 INFO 26572 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/clean_log.js
2017-03-03 09:05:27,006 INFO 26572 [egg-schedule]: register schedule egg-schedule:/Users/mingzhang/workspace/egg-example/node_modules/egg-logrotator/app/schedule/rotate_by_file.js
2017-03-03 09:05:27,023 INFO 26570 [egg-static] starting static serve /public/ -> /Users/mingzhang/workspace/egg-example/app/public
2017-03-03 09:05:27,024 INFO 26569 [egg-static] starting static serve /public/ -> /Users/mingzhang/workspace/egg-example/app/public
2017-03-03 09:05:27,029 INFO 26570 [egg-security] use csrf middleware
2017-03-03 09:05:27,031 INFO 26570 [egg-security] use methodnoallow middleware
2017-03-03 09:05:27,032 INFO 26570 [egg-security] use noopen middleware
2017-03-03 09:05:27,032 INFO 26569 [egg-security] use csrf middleware
2017-03-03 09:05:27,032 INFO 26570 [egg-security] use nosniff middleware
2017-03-03 09:05:27,033 INFO 26570 [egg-security] use xssProtection middleware
2017-03-03 09:05:27,034 INFO 26569 [egg-security] use methodnoallow middleware
2017-03-03 09:05:27,034 INFO 26570 [egg-security] use xframe middleware
2017-03-03 09:05:27,034 INFO 26570 [egg-security] compose 6 middlewares into one security middleware
2017-03-03 09:05:27,034 INFO 26569 [egg-security] use noopen middleware
2017-03-03 09:05:27,036 INFO 26569 [egg-security] use nosniff middleware
2017-03-03 09:05:27,038 INFO 26569 [egg-security] use xssProtection middleware
2017-03-03 09:05:27,038 INFO 26569 [egg-security] use xframe middleware
2017-03-03 09:05:27,039 INFO 26569 [egg-security] compose 6 middlewares into one security middleware
2017-03-03 09:05:27,047 INFO 26573 [egg-static] starting static serve /public/ -> /Users/mingzhang/workspace/egg-example/app/public
2017-03-03 09:05:27,045 INFO 26575 [egg-static] starting static serve /public/ -> /Users/mingzhang/workspace/egg-example/app/public
2017-03-03 09:05:27,054 WARN 26567 [master] App Worker#2:26570 started at 7001, remain 7 (734ms)
2017-03-03 09:05:27,054 INFO 26573 [egg-security] use csrf middleware
2017-03-03 09:05:27,054 INFO 26575 [egg-security] use csrf middleware
2017-03-03 09:05:27,054 INFO 26571 [egg-static] starting static serve /public/ -> /Users/mingzhang/workspace/egg-example/app/public
2017-03-03 09:05:27,054 INFO 26576 [egg-static] starting static serve /public/ -> /Users/mingzhang/workspace/egg-example/app/public
2017-03-03 09:05:27,055 INFO 26573 [egg-security] use methodnoallow middleware
2017-03-03 09:05:27,055 INFO 26572 [egg-static] starting static serve /public/ -> /Users/mingzhang/workspace/egg-example/app/public
2017-03-03 09:05:27,055 INFO 26575 [egg-security] use methodnoallow middleware
2017-03-03 09:05:27,055 INFO 26575 [egg-security] use noopen middleware
2017-03-03 09:05:27,055 INFO 26573 [egg-security] use noopen middleware
2017-03-03 09:05:27,056 INFO 26575 [egg-security] use nosniff middleware
2017-03-03 09:05:27,056 INFO 26573 [egg-security] use nosniff middleware
2017-03-03 09:05:27,056 INFO 26575 [egg-security] use xssProtection middleware
2017-03-03 09:05:27,056 INFO 26574 [egg-static] starting static serve /public/ -> /Users/mingzhang/workspace/egg-example/app/public
2017-03-03 09:05:27,057 INFO 26573 [egg-security] use xssProtection middleware
2017-03-03 09:05:27,057 INFO 26575 [egg-security] use xframe middleware
2017-03-03 09:05:27,057 INFO 26575 [egg-security] compose 6 middlewares into one security middleware
2017-03-03 09:05:27,057 INFO 26573 [egg-security] use xframe middleware
2017-03-03 09:05:27,058 INFO 26573 [egg-security] compose 6 middlewares into one security middleware
2017-03-03 09:05:27,059 INFO 26571 [egg-security] use csrf middleware
2017-03-03 09:05:27,060 INFO 26572 [egg-security] use csrf middleware
2017-03-03 09:05:27,060 INFO 26576 [egg-security] use csrf middleware
2017-03-03 09:05:27,061 INFO 26571 [egg-security] use methodnoallow middleware
2017-03-03 09:05:27,061 INFO 26572 [egg-security] use methodnoallow middleware
2017-03-03 09:05:27,061 INFO 26576 [egg-security] use methodnoallow middleware
2017-03-03 09:05:27,062 INFO 26571 [egg-security] use noopen middleware
2017-03-03 09:05:27,062 INFO 26572 [egg-security] use noopen middleware
2017-03-03 09:05:27,062 INFO 26576 [egg-security] use noopen middleware
2017-03-03 09:05:27,062 INFO 26574 [egg-security] use csrf middleware
2017-03-03 09:05:27,062 INFO 26571 [egg-security] use nosniff middleware
2017-03-03 09:05:27,062 INFO 26572 [egg-security] use nosniff middleware
2017-03-03 09:05:27,062 INFO 26576 [egg-security] use nosniff middleware
2017-03-03 09:05:27,063 INFO 26574 [egg-security] use methodnoallow middleware
2017-03-03 09:05:27,063 INFO 26571 [egg-security] use xssProtection middleware
2017-03-03 09:05:27,063 INFO 26572 [egg-security] use xssProtection middleware
2017-03-03 09:05:27,063 INFO 26576 [egg-security] use xssProtection middleware
2017-03-03 09:05:27,063 INFO 26574 [egg-security] use noopen middleware
2017-03-03 09:05:27,064 INFO 26571 [egg-security] use xframe middleware
2017-03-03 09:05:27,064 INFO 26576 [egg-security] use xframe middleware
2017-03-03 09:05:27,064 INFO 26572 [egg-security] use xframe middleware
2017-03-03 09:05:27,064 INFO 26571 [egg-security] compose 6 middlewares into one security middleware
2017-03-03 09:05:27,064 INFO 26576 [egg-security] compose 6 middlewares into one security middleware
2017-03-03 09:05:27,064 INFO 26572 [egg-security] compose 6 middlewares into one security middleware
2017-03-03 09:05:27,064 INFO 26574 [egg-security] use nosniff middleware
2017-03-03 09:05:27,064 WARN 26567 [master] App Worker#1:26569 started at 7001, remain 6 (744ms)
2017-03-03 09:05:27,065 INFO 26574 [egg-security] use xssProtection middleware
2017-03-03 09:05:27,066 INFO 26574 [egg-security] use xframe middleware
2017-03-03 09:05:27,066 INFO 26574 [egg-security] compose 6 middlewares into one security middleware
2017-03-03 09:05:27,072 WARN 26567 [master] App Worker#7:26575 started at 7001, remain 5 (752ms)
2017-03-03 09:05:27,073 WARN 26567 [master] App Worker#5:26573 started at 7001, remain 4 (753ms)
2017-03-03 09:05:27,075 WARN 26567 [master] App Worker#3:26571 started at 7001, remain 3 (755ms)
2017-03-03 09:05:27,075 WARN 26567 [master] App Worker#4:26572 started at 7001, remain 2 (755ms)
2017-03-03 09:05:27,077 WARN 26567 [master] App Worker#8:26576 started at 7001, remain 1 (757ms)
2017-03-03 09:05:27,077 WARN 26567 [master] App Worker#6:26574 started at 7001, remain 0 (757ms)
2017-03-03 09:05:27,078 INFO 26567 [master] egg started on http://127.0.0.1:7001 (1070ms)

@kkys4bfgp75be9p
Copy link
Author

而且和mac系统应该没有关系,我线上ubuntu 16里也没有输出

@atian25
Copy link
Member

atian25 commented Mar 3, 2017

[egg:logger] init all loggers with options: {"dir":"/Users/mingzhang/logs/egg-example"

这个目录下没日志? 测试的 logger 语句用 info 还是 debug?

@kkys4bfgp75be9p
Copy link
Author

prod下什么也没有

'use strict';

exports.index = function* index(ctx) {
  ctx.logger.info('test')
  ctx.body = 'hi, egg';
};

@atian25
Copy link
Member

atian25 commented Mar 3, 2017

其他人看看,我按你的操作步骤,本地无法复现,可以正常输出日志。

另外,@zhangming0305 再重新试一次看看,我刚更新了 simple 的模板,把 egg 的版本升级到 rc2 了。

@kkys4bfgp75be9p
Copy link
Author

kkys4bfgp75be9p commented Mar 3, 2017

这就见鬼了。。。我再试一次!

@kkys4bfgp75be9p
Copy link
Author

我这里还是不行。难道是这个命令有问题?:

EGG_SERVER_ENV=prod npm start

我直接 EGG_SERVER_ENV=prod npm start 启动server,甚至logs文件夹都没有自动生成,你说奇怪不奇怪

@atian25
Copy link
Member

atian25 commented Mar 3, 2017

这指令等价于 EGG_SERVER_ENV=prod node index.js

@kkys4bfgp75be9p
Copy link
Author

这个肯定知道了,就是不明白就是我的有问题,你的机器就可以,我再换个机器试试

@atian25
Copy link
Member

atian25 commented Mar 3, 2017

看看是不是没有权限创建.

@kkys4bfgp75be9p
Copy link
Author

问题是 npm start 就一切正常了。

@kkys4bfgp75be9p
Copy link
Author

我换了个mac,升级egg-init, 还是不行,同样的症状。
我觉得肯定有问题。请你们再看看

@fengmk2
Copy link
Member

fengmk2 commented Mar 3, 2017

/Users/mingzhang/logs/egg-example 这个目录没有日志文件?stdout 里面就显示日志输出到这里的啊

@kkys4bfgp75be9p
Copy link
Author

@fengmk2 直接EGG_SERVER_ENV=prod npm start 连 /Users/mingzhang/logs 目录都没有生成

@kkys4bfgp75be9p
Copy link
Author

我的问题就在prod,其他都能正常运行,EGG_SERVER_ENV=local 没问题

@fengmk2
Copy link
Member

fengmk2 commented Mar 3, 2017

我按你的方式重现,也是有日志的

image

EGG_SERVER_ENV=prod npm start

> showcase@1.0.0 start /private/tmp/showcase
> node index.js

2017-03-03 17:44:37,351 INFO 90017 [master] =================== egg start =====================
2017-03-03 17:44:37,354 INFO 90017 [master] egg version 1.0.0-rc.2
2017-03-03 17:44:37,355 INFO 90017 [master] start with options: {"framework":"/private/tmp/showcase/node_modules/.1.0.0-rc.2@egg","baseDir":"/private/tmp/showcase","port":7001,"workers":4,"plugins":null,"https":false,"key":"","cert":"","customEgg":"/private/tmp/showcase/node_modules/.1.0.0-rc.2@egg"}
2017-03-03 17:44:37,355 INFO 90017 [master] start with env: isProduction: true, isDebug: false, EGG_SERVER_ENV: prod, NODE_ENV: undefined
2017-03-03 17:44:37,365 INFO 90017 [master] Agent Worker:90018 start with ["{\"framework\":\"/private/tmp/showcase/node_modules/.1.0.0-rc.2@egg\",\"baseDir\":\"/private/tmp/showcase\",\"port\":7001,\"workers\":4,\"plugins\":null,\"https\":false,\"key\":\"\",\"cert\":\"\",\"customEgg\":\"/private/tmp/showcase/node_modules/.1.0.0-rc.2@egg\",\"clusterPort\":50078}"]
2017-03-03 17:44:37,818 INFO 90018 [egg:logger] init all loggers with options: {"dir":"/Users/mk2/logs/showcase","encoding":"utf8","env":"prod","level":"INFO","consoleLevel":"INFO","outputJSON":false,"buffer":true,"appLogName":"showcase-web.log","coreLogName":"egg-web.log","agentLogName":"egg-agent.log","errorLogName":"common-error.log","coreLogger":{},"type":"agent"}

@dead-horse
Copy link
Member

@zhangming0305 按照你的描述,local 环境的日志出现在了 /Users/zhangming0305/logs/custom-env 目录下,而 prod 环境的日志没有出现在这个目录下?local 环境的日志不会打印到这个目录下去的。

你试试:

rm -rf /Users/zhangming0305/logs
EGG_SERVER_ENV=local npm start
ls -l /Users/zhangming0305/logs/custom-env
cp run/application_config.json ./local.json

rm -rf /Users/zhangming0305/logs
EGG_SERVER_ENV=prod npm start
ls -l /Users/zhangming0305/logs/custom-env
cp run/application_config.json ./prod.json

如果还是没有出现日志的话,将 local 和 prod 两个环境下运行的配置文件都提交上来。

@kkys4bfgp75be9p
Copy link
Author

好的,我等下在试试,然后提交

@atian25
Copy link
Member

atian25 commented Mar 3, 2017

还有一个可以尝试下,排查下是不是权限问题:

// config/config.prod.js
const path = require('path');
module.exports = appInfo => {
  return {
    logger: {
      dir: path.join(appInfo.baseDir, 'abc'),
    },
  };
};

@kkys4bfgp75be9p
Copy link
Author

@atian25 还真是,这样就可以了prod 也能生成logs及子目录当然还有log文件

const path = require('path');
module.exports = appInfo => {
  return {
    logger: {
      dir: path.join(appInfo.baseDir, 'logs/example'),
    },
  };
};

@atian25
Copy link
Member

atian25 commented Mar 3, 2017

怀疑是权限问题了, ls -l ~/logs 看看是不是目录权限问题

@atian25
Copy link
Member

atian25 commented Mar 6, 2017

@popomore 创建日志目录失败后有控制台输出不

@dead-horse
Copy link
Member

@zhangming0305 看你的描述我感觉你一直在看当前应用所在的目录,而不是 /Users/zhangming0305/logs 这个目录。

@kkys4bfgp75be9p
Copy link
Author

的确是我没看仔细。

@atian25
Copy link
Member

atian25 commented Mar 8, 2017

.............

@xiaoxiaoxiao-s
Copy link

你的问题找到原因了吗,我也有同样的问题,所以想请教一下你

@Liutos
Copy link

Liutos commented Jun 23, 2020

你的问题找到原因了吗,我也有同样的问题,所以想请教一下你

检查一下你的egg-js项目的run/application_config.json文件,看看里面的logger.dir是不是配置成了你的用户主目录下的 logs/XXX 了。

如果是的话,你应该可以在那个目录里找到日志。然后你可以在 config.default.js 中通过设置

config.logger = {
  dir: path.resolve(appInfo.baseDir, 'logs/XXX/')
};

来解决。

@atian25
Copy link
Member

atian25 commented Jun 23, 2020

不用加 resolve,相对路径即可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants