java - 将 logging.properties 与标准 Appengine Java 11 一起使用
问题描述
我正在尝试使用logging.properties
文件对我的标准 AppEngine Java 11 应用程序进行一些日志记录修改,我的应用程序是一个 Jetty Web 服务器,我通过将以下入口点添加到我的app.yaml
文件来运行它
runtime: java11
entrypoint: 'java -cp "*" com.jettymain.Main webapp.war'
现在这里的谷歌文档建议为了使用logging.properties
. 配置文件的路径必须作为系统属性提供给您的应用程序:-Djava.util.logging.config.file=/path/to/logging.properties
我已经尝试在代码中设置它,首先在 com.jettymain.Main 类中通过执行以下操作启动 Jetty 嵌入式 Web 服务器
System.setProperty("java.util.logging.config.file", "WEB-INF/logging.properties")
但这不起作用,修改入口点app.yaml
确实使网络服务器加载了这些配置,但它未能加载谷歌云日志记录处理程序类com.google.cloud.logging.LoggingHandler
,我需要将这些日志写入谷歌 Stackdriver,我有谷歌云日志依赖添加到我的应用程序和网络服务器中,但这没有帮助。
<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 文件,它是可以在此处找到的示例文件以及一些额外的东西
# 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
解决方案
进入System.setProperty
任何方法。它也可以是主要方法。我认为问题是根据此链接the logging.properties
“必须进入”,而不是代码中提到的目录。WEB-INF/classes directory
WEB-INF/
System.setProperty("java.util.logging.config.file", "WEB-INF/classes/logging.properties")
推荐阅读
- rabbitmq - 如何检查 RabbitMQ firehose 是否打开
- javascript - 从 ReactJS 调用 javascript 函数
- java - 我正在尝试从 api 获取数据,但它似乎无法正常工作
- string - 当我们连接两个字符串时会发生什么
- odoo-10 - 下载使用 python-docx 创建的文档
- python - 在 ctypes 加载共享库中卸载共享库
- jenkins - 有没有更好的方法来根据规则调整gerrit插入代码大小并排除文件路径?
- c# - 检查 BIN 编号
- + 性能增强
- python - 训练集和测试集的准确率突然下降,损失突然上升,但慢慢恢复
- ios - 在 iOS 应用程序中连接后 Chromecast 未播放媒体