java - 如果 App Engine 自动将 stdout & stderr 记录到 INFO & WARNING,你为什么要使用 logging.properties?

标签 java google-app-engine logging java.util.logging

根据 Google App Engine for Java 的文档:

The App Engine Java SDK includes a template logging.properties file, in the appengine-java-sdk/config/user/ directory. To use it, copy the file to your WEB-INF/classes directory (or elsewhere in the WAR), then the system property java.util.logging.config.file to "WEB-INF/classes/logging.properties" (or whichever path you choose, relative to the application root). You can set system properties in the appengine-web.xml file, as follows:

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    ...

    <system-properties>
        <property name="java.util.logging.config.file" value="WEB-INF/classes/logging.properties" />
    </system-properties>

</appengine-web-app>

The Google Plugin for Eclipse new project wizard creates these logging configuration files for you, and copies them to WEB-INF/classes/ automatically. For java.util.logging, you must set the system property to use this file.

如果您写入标准输出或标准错误,将自动记录为 INFO 或 WARNING。

那么,为什么需要使用 logging.properties 文件?

这会让您对日志记录有一些额外的控制吗?

最佳答案

如果您想使用更具体的日志记录信息,例如一些 DEBUG。

这样您就可以在开发过程中记录更多信息,并且在将代码投入生产时无需更改代码。

个人示例:当我编码时,我会记录很多信息(记录级别 FINE 和 FINEST)。当我将我的应用程序发送给测试人员时,他们使用 DEBUG 级别。在生产环境中(对公众)只有 INFO、WARNING 和 SEVERE 是日志。

总而言之,这为您提供了更多控制权,并且您无需更改任何代码行。

有关在 java 中登录的更多信息:here

关于java - 如果 App Engine 自动将 stdout & stderr 记录到 INFO & WARNING,你为什么要使用 logging.properties?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1517884/

相关文章:

python - 如何在 Google App Engine 上检查可用的 Python 库并添加更多

logging - 如何在XAMPP中启用错误报告

Java AES加密/解密始终返回相同的内容

java Fork/Join 池、ExecutorService 和 CountDownLatch

java - 如何集成不同编程语言编写的程序?

java - JDO - 更新对象

google-app-engine - 仅从 Google App Engine 访问 Google Compute Engine 实例?

java - 生成报告 - 什么对您有用?

asp.net - 如何从 ASP.NET Core 中的 Controller 以外的其他类登录?

c++ - 如何在 C++ 中读取不断增长的文本文件?