【发布时间】:2021-08-25 12:04:40
【问题描述】:
我正在尝试使用 logging.properties 文件对我的标准 AppEngine Java 11 应用程序进行一些日志记录修改,我的应用程序是一个 Jetty 网络服务器,我通过将以下入口点添加到我的 app.yaml 文件来运行它
runtime: java11
entrypoint: 'java -cp "*" com.jettymain.Main webapp.war'
现在 Google 文档 here 建议使用 logging.properties。配置文件的路径必须作为系统属性提供给您的应用程序:-Djava.util.logging.config.file=/path/to/logging.properties
我已经尝试在代码中设置它,首先在 com.jettymain.Main 类中通过执行以下操作启动 Jetty 嵌入式网络服务器
System.setProperty("java.util.logging.config.file", "WEB-INF/logging.properties")
但这不起作用,修改app.yaml 中的入口点确实使网络服务器加载了这些配置,但它未能加载谷歌云日志记录处理程序类com.google.cloud.logging.LoggingHandler,我需要编写这些登录到 Google Stackdriver,我将 Google 云日志记录依赖项添加到我的应用程序和网络服务器中,但这没有帮助。
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-logging</artifactId>
<version>3.0.1</version>
</dependency>
修改入口品脱
runtime: java11
entrypoint: 'java -cp "*" com.jettymain.Main webapp.war -Djava.util.logging.config.file=WEB-INF/logging.properties'
logging.properties 文件,它是可以在here 找到的示例文件以及一些额外的东西
# To use this configuration, add to system properties : -Djava.util.logging.config.file="/path/to/file"
.level = INFO
# it is recommended that io.grpc and sun.net logging level is kept at INFO level,
# as both these packages are used by Cloud internals and can result in verbose / initialization problems.
io.grpc.netty.level=INFO
sun.net.level=INFO
handlers=com.google.cloud.logging.LoggingHandler
# default : java.log
com.google.cloud.logging.LoggingHandler.log=custom_log
# default : INFO
com.google.cloud.logging.LoggingHandler.level=FINE
# default : ERROR
com.google.cloud.logging.LoggingHandler.flushLevel=EMERGENCY
# default : auto-detected, fallback "global"
com.google.cloud.logging.LoggingHandler.resourceType=container
# custom formatter
com.google.cloud.logging.LoggingHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=%3$s: %5$s%6$s
# Level for all logs coming from GWT client (can't filter by specific classes on client)
com.google.gwt.logging.server.RemoteLoggingServiceUtil.level = WARNING
com.beoui.geocell.level=WARNING
【问题讨论】:
-
我假设您使用 java.util.logging 处理程序来设置 Java 的 Cloud Logging,而不是直接使用 Java 的 Cloud 日志库?
标签: java google-app-engine jetty java.util.logging google-cloud-logging