0

背景:我正在将我的应用程序部署mvn gcloud:deployGoogle 灵活环境,但我看不到我的网站在线。我想知道服务器启动时发生了什么,因此我尝试查看我的日志消息。


根据此文档,我需要格式化以 JSON 格式发送我的日志消息:

{
  "eventTime": string,
  "serviceContext": {      // Required.
    "service": string,
    "version": string
  },
  "message": string,       // Required.
  // ...
}

我已经像这样配置了我的附加程序:

log4j.rootLogger=TRACE, consoleAppender, fileAppender, appEngineAppender, appEngineAppender2

log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=[%t] %-5p %c %x- %m%n

log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern=[%t] %-5p %c %x- %m%n
log4j.appender.fileAppender.File=mz-web-server.log

# Google Cloud Logging

log4j.appender.appEngineAppender=org.apache.log4j.RollingFileAppender
log4j.appender.appEngineAppender.layout=com.mz.server.AppEngineAppenderLayout
log4j.appender.appEngineAppender.File=/var/log/app_engine/custom_logs/err_mz-web-server.json
log4j.appender.appEngineAppender.Threshold=DEBUG

log4j.appender.appEngineAppender2=org.apache.log4j.RollingFileAppender
log4j.appender.appEngineAppender2.layout=com.mz.server.AppEngineAppenderLayout
log4j.appender.appEngineAppender2.File=err_mz-web-server.json
log4j.appender.appEngineAppender2.Threshold=DEBUG

# Mz
log4j.logger.com.mz=debug

# Spring Framework
log4j.logger.org.springframework=warn

# jOOQ prints to stdout - have do redirect that somehow
log4j.logger.org.jooq=warn

# FlywayDB
log4j.logger.org.flywaydb=warn

# ehcache
log4j.logger.net.sf.ehcache=warn

err_mz-web-server.json 看起来像这样:

{"eventTime":"2016-06-05, 12:01:13","serviceContext":{"service":"[mz-server]","version":"v0.1"},"message":"Server booting up. Time: UTC 2016-06-05T12:01:13.406Z"}
{"eventTime":"2016-06-05, 12:01:13","serviceContext":{"service":"[mz-server]","version":"v0.1"},"message":"Joda Time default Timezone: UTC"}
{"eventTime":"2016-06-05, 12:01:13","serviceContext":{"service":"[mz-server]","version":"v0.1"},"message":"Running database migration ..."}
{"eventTime":"2016-06-05, 12:01:13","serviceContext":{"service":"[mz-server]","version":"v0.1"},"message":"Executing migration .."}
{"eventTime":"2016-06-05, 12:01:14","serviceContext":{"service":"[mz-server]","version":"v0.1"},"message":"Not migration required."}
{"eventTime":"2016-06-05, 12:01:14","serviceContext":{"service":"[mz-server]","version":"v0.1"},"message":"Database migration done."}
{"eventTime":"2016-06-05, 12:01:14","serviceContext":{"service":"[mz-server]","version":"v0.1"},"message":"Initialization done."}
{"eventTime":"2016-06-05, 12:01:14","serviceContext":{"service":"[mz-server]","version":"v0.1"},"message":"Unhandled event"}
{"eventTime":"2016-06-05, 12:01:14","serviceContext":{"service":"[mz-server]","version":"v0.1"},"message":"Unhandled event"}

但是,我没有看到https://console.cloud.google.com/errors?time=P1D&refresh=off&order=1下记录的任何错误,如此所述。


更新:

我检查了文件是否存在,但似乎/var/log/app_engine/custom_logs/没有创建目录:

user@gae-default-20160605t144407-u28j:/var/log/app_engine$ ls -la
total 16
drwxrwxrwx  4 root root 4096 May 26 21:55 .
drwxr-xr-x 14 root root 4096 Jun  5 12:48 ..
drwxrwxrwx  3 root root 4096 May 26 21:55 app
drwxr-xr-x  2 root root 4096 May 26 21:55 monitoring
4

0 回答 0