登录外化 [英] logback externalization

查看:71
本文介绍了登录外化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前我有logback配置文件,即logback.xml,它是src/main/resources.我想设置日志记录级别,但是我想在战场之外进行控制.

Currently I have logback configuration file i.e logback.xml which is src/main/resources. I want to set the logging level but i want control outside of war.

我想到的一种解决方案是将其外部化到属性文件中,在服务器启动时加载它并替换占位符.有什么更好的方法吗?我们不能将logback.xml保留在战争文件之外吗?

One solution which i could think of is to externalize it in properties file, load it on server startup and substitute the placeholder. Is there any better way of doing it ? Can't we keep logback.xml outside of war file ?

<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${catalina.base}/logs/logFile.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- daily rollover -->
        <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
        <!-- keep 7 days' worth of history -->
        <maxHistory>7</maxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>%date [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
</appender>

<root level="DEBUG">
    <appender-ref ref="FILE"/>
</root>

推荐答案

如果只想更改日志级别,则无需覆盖整个文件,可以执行以下操作:

If you just want to change the log level you don't need to override the whole file, you can do this:

<root level="${log.level:-INFO}">

然后,如果您设置系统属性:

Then if you set the system property:

-Dlog.level=DEBUG

它将覆盖默认的"INFO".

It will override the default of 'INFO'.

这篇关于登录外化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆