运行 spring 带有 --debug 的应用程序不会影响我的记录器
Run spring app with --debug doesn't affect my loggers
private static final Logger myLogger = LoggerFactory.getLogger("NAME");
我有几个像上面的例子一样创建的记录器,问题是,当我 运行 我的 Spring 应用程序与 --debug
时,myLogger.debug("something")
不是已记录,只有 spring default/internal 个记录器实际上使用了 --debug
参数。
如何让我的记录器也使用 --<level>
参数?
这是设计使然。不可能让其他记录器使用 —debug 或任何其他级别。
来自docs、
The default log configuration echoes messages to the console as they
are written. By default, ERROR-level, WARN-level, and INFO-level
messages are logged. You can also enable a “debug” mode by starting
your application with a --debug flag.
$ java -jar myapp.jar --debug
[Note] You can also specify debug=true
in your application.properties.
When the debug mode is enabled, a selection of core loggers (embedded
container, Hibernate, and Spring Boot) are configured to output more
information. Enabling the debug mode does not configure your
application to log all messages with DEBUG level.
Alternatively, you can enable a “trace” mode by starting your
application with a --trace flag (or trace=true in your
application.properties). Doing so enables trace logging for a
selection of core loggers (embedded container, Hibernate schema
generation, and the whole Spring portfolio).
但是您可以使用以下键值在应用程序属性文件中记录所有调试消息
logging.level.root=debug
您好下面是一个示例logback.xml,将放在资源文件夹中
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<logger name="<PACKAGE ON WHICH YOU WOULD LIKE TO ENABLE DEBUGGING (EXAMPLE: com.mypackage)>" level="DEBUG" />
<root level="ERROR">
<appender-ref ref="STDOUT" />
<appender-ref ref="DAILY_ROLLING" />
<appender-ref ref="SYSLOG" />
</root>
</configuration>
改变<PACKAGE ON WHICH YOU WOULD LIKE TO ENABLE DEBUGGING (EXAMPLE: com.mypackage))>
使用您自己的包,您希望在其上启用 DEBUG。
或者,如果您想在所有包上启用根级别,请将 <root level="ERROR" >
替换为 <root level="DEBUG" >
。它会打印所有代码的调试消息,即使它是在依赖项中打印的。此外,如果您的包的日志级别与根级别相同,您可以删除 <logger name="<PACKAGE ON WHICH YOU WOULD LIKE TO ENABLE DEBUGGING (EXAMPLE: com.mypackage)>" level="debug" />
。
private static final Logger myLogger = LoggerFactory.getLogger("NAME");
我有几个像上面的例子一样创建的记录器,问题是,当我 运行 我的 Spring 应用程序与 --debug
时,myLogger.debug("something")
不是已记录,只有 spring default/internal 个记录器实际上使用了 --debug
参数。
如何让我的记录器也使用 --<level>
参数?
这是设计使然。不可能让其他记录器使用 —debug 或任何其他级别。
来自docs、
The default log configuration echoes messages to the console as they are written. By default, ERROR-level, WARN-level, and INFO-level messages are logged. You can also enable a “debug” mode by starting your application with a --debug flag.
$ java -jar myapp.jar --debug
[Note] You can also specify debug=true in your application.properties.
When the debug mode is enabled, a selection of core loggers (embedded container, Hibernate, and Spring Boot) are configured to output more information. Enabling the debug mode does not configure your application to log all messages with DEBUG level.
Alternatively, you can enable a “trace” mode by starting your application with a --trace flag (or trace=true in your application.properties). Doing so enables trace logging for a selection of core loggers (embedded container, Hibernate schema generation, and the whole Spring portfolio).
但是您可以使用以下键值在应用程序属性文件中记录所有调试消息
logging.level.root=debug
您好下面是一个示例logback.xml,将放在资源文件夹中
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<logger name="<PACKAGE ON WHICH YOU WOULD LIKE TO ENABLE DEBUGGING (EXAMPLE: com.mypackage)>" level="DEBUG" />
<root level="ERROR">
<appender-ref ref="STDOUT" />
<appender-ref ref="DAILY_ROLLING" />
<appender-ref ref="SYSLOG" />
</root>
</configuration>
改变<PACKAGE ON WHICH YOU WOULD LIKE TO ENABLE DEBUGGING (EXAMPLE: com.mypackage))>
使用您自己的包,您希望在其上启用 DEBUG。
或者,如果您想在所有包上启用根级别,请将 <root level="ERROR" >
替换为 <root level="DEBUG" >
。它会打印所有代码的调试消息,即使它是在依赖项中打印的。此外,如果您的包的日志级别与根级别相同,您可以删除 <logger name="<PACKAGE ON WHICH YOU WOULD LIKE TO ENABLE DEBUGGING (EXAMPLE: com.mypackage)>" level="debug" />
。