简体   繁体   English

如何在运行时更改日志级别而不重新启动Vert.x应用程序

[英]How do I change log level in runtime without restarting Vert.x application

I know that we can change log level by putting it in vertx-default-jul-logging.properties file. 我知道我们可以通过将日志级别放入vertx-default-jul-logging.properties文件来更改日志级别。

java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.ConsoleHandler.level=FINER

java.util.logging.FileHandler.limit=10000000
java.util.logging.FileHandler.count=10
java.util.logging.FileHandler.level=FINER
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter

But I need to restart the application when we change log level in this file as it gets built with application. 但是,当我们更改该文件的日志级别时,我需要重新启动该应用程序,因为它是使用应用程序构建的。 Is there any way to change the log level without restarting the application like we can do in jboss by jboss cli. 有什么方法可以更改日志级别而无需重新启动应用程序,就像我们在jboss cli中通过jboss所做的那样。

This file doesn't have to be built with the application. 该文件不必与应用程序一起构建。 It just has to be on the classpath. 它只必须在类路径上。

But anyway, I don't believe JDK logging supports hot reload of a configuration file. 但是无论如何,我不相信JDK日志记录支持热重载配置文件。 There are other logging tools which do though. 但是还有其他日志记录工具。 Like Logback-classic . Logback-classic一样

Logback-classic can scan for changes in its configuration file and automatically reconfigure itself when the configuration file changes. 经典的Logback可以扫描其配置文件中的更改,并在配置文件更改时自动重新配置自身。

For example, to reload every five seconds: 例如,每五秒钟重新加载一次:

<configuration scan="true" scanPeriod="5 seconds" > 
  ...
</configuration> 

Vert.x can be configured to use different logging frameworks . 可以将Vert.x配置为使用不同的日志记录框架 To do so, you must set the vertx.logger-delegate-factory-class-name system property. 为此,必须设置vertx.logger-delegate-factory-class-name系统属性。 As Logback-classic is an slf4j implementation, you need: 由于Logback-classicslf4j的实现,因此您需要:

-Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM