我正在开发一个 cli 应用程序,它可以接受一些选项:--info
, --debug
, --trace
。我想使用参数来设置整个应用程序的日志记录级别。是否有捷径可寻?这是我到目前为止所尝试过的:
LogLevel level;
if(info) {
level = LogLevel.INFO;
} else if (debug) {
level = LogLevel.DEBUG;
} else if (trace) {
level = LogLevel.TRACE;
} else {
level = LogLevel.WARN;
}
loggingSystem.setLogLevel(Logger.ROOT_LOGGER_NAME, level);
Run Code Online (Sandbox Code Playgroud)
loggingSystem
被注入到类中。
@Inject
private LoggingSystem loggingSystem;
Run Code Online (Sandbox Code Playgroud)
I am not quite sure if I get your point. Here is what I found in the official documentation.
Controlling Log Levels with Properties
Controlling Log Levels with Properties
Log levels can be configured via properties defined in application.yml (and environment variables) with the log.level prefix:
logger:
levels:
foo.bar: ERROR
Run Code Online (Sandbox Code Playgroud)
Note that the ability to control log levels via config is controlled via the LoggingSystem interface. Currently Micronaut ships with a single implementation that allows setting log levels for the Logback library. If another library is chosen you should provide a bean that implements this interface.
归档时间: |
|
查看次数: |
13857 次 |
最近记录: |