私はログ出力にslf4jを使用するプロジェクトに取り組んでいます。事は、ログのレベルが動的であり、ユーザーによって選択されることです。そのため、ユーザーはロギングを停止してスペースを増やすことができます(ログには多くのことが記録され、大きなトラフィックが発生すると非常にコストがかかります)。logback:ログオフでレベルOFFが機能していません
これを行うには、いくつかの変数をプロパティファイルに保存し、変更するたびにリロードします。しかし、レベルをオフにして(ログを無効にするために)the docのように動作するようにするつもりはありませんでした。
ここに私のlogback.xmlです:
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="false">
<!-- We don't need the logback.xml to be checked every time, we will trigger in java
the reload if we need it -->
<property file="/opt/program/log.properties"/>
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<!-- To enable JMX Management -->
<jmxConfigurator/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${PATTERN_LOGS}</pattern>
</encoder>
</appender>
<appender name="generalFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_GENERAL_PATH}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_GENERAL_FILENAME}.%d{yyyy-MM-dd}.log</fileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>${PATTERN_LOGS}</pattern>
</encoder>
</appender>
<appender name="httpFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_HTTP_PATH}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_HTTP_FILENAME}.%d{yyyy-MM-dd}.log</fileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>${PATTERN_LOGS}</pattern>
</encoder>
</appender>
<appender name="errorFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_ERROR_PATH}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_ERROR_FILENAME}.%d{yyyy-MM-dd}.log</fileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>${PATTERN_LOGS}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>
<logger name="http" level="DEBUG" additivity="false">
<appender-ref ref="httpFile"/>
<appender-ref ref="generalFile"/>
<appender-ref ref="console"/>
</logger>
<root level="${LEVEL_ROOT}">
<appender-ref ref="console"/>
<appender-ref ref="generalFile"/>
<appender-ref ref="errorFile"/>
</root>
</configuration>
そして、これは私がステータスメッセージアクティブにしたとき、私は、コンソールから得たものである:、あなたが提供logbackステータスメッセージから
00:06:45,861 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
00:06:45,861 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
00:06:45,862 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/root/Documents/project/projet%20OSM/Tomcat%20Installation/wtpwebapps/SekaiServer/WEB-INF/classes/logback.xml]
00:06:45,944 |-INFO in ch.qos.logback.classic.joran.action.LoggerContextListenerAction - Adding LoggerContextListener of type [ch.qos.logback.classic.jul.LevelChangePropagator] to the object stack
00:06:45,961 |-INFO in [email protected] - Propagating DEBUG level on Logger[ROOT] onto the JUL framework
00:06:45,962 |-INFO in ch.qos.logback.classic.joran.action.LoggerContextListenerAction - Starting LoggerContextListener
00:06:45,962 |-INFO in ch.qos.logback.classic.joran.action.JMXConfiguratorAction - begin
00:06:45,968 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
00:06:45,975 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [console]
00:06:45,993 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
00:06:46,091 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
00:06:46,100 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [generalFile]
00:06:46,143 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
00:06:46,148 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern /opt/program/log/general.%d{yyyy-MM-dd}.log for the active file
00:06:46,155 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/opt/program/log/general.%d{yyyy-MM-dd}.log'.
00:06:46,155 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
00:06:46,156 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sat Mar 26 00:03:15 CET 2016
00:06:46,159 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
00:06:46,165 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[generalFile] - Active log file name: /opt/program//log/general.log
00:06:46,165 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[generalFile] - File property is set to [/opt/program//log/general.log]
00:06:46,167 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
00:06:46,168 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [httpFile]
00:06:46,170 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
00:06:46,170 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern /opt/program/log/http.%d{yyyy-MM-dd}.log for the active file
00:06:46,171 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/opt/program/log/http.%d{yyyy-MM-dd}.log'.
00:06:46,171 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
00:06:46,172 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sat Mar 26 00:03:15 CET 2016
00:06:46,172 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
00:06:46,174 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[httpFile] - Active log file name: /opt/program//log/http.log
00:06:46,174 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[httpFile] - File property is set to [/opt/program//log/http.log]
00:06:46,174 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
00:06:46,175 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [errorFile]
00:06:46,177 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
00:06:46,177 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern /opt/program/log/error.%d{yyyy-MM-dd}.log for the active file
00:06:46,178 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern '/opt/program/log/error.%d{yyyy-MM-dd}.log'.
00:06:46,178 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
00:06:46,178 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Thu Mar 24 19:50:38 CET 2016
00:06:46,179 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
00:06:46,190 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[errorFile] - Active log file name: /opt/program//log/error.log
00:06:46,190 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[errorFile] - File property is set to [/opt/program//log/error.log]
00:06:46,192 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [http] to DEBUG
00:06:46,192 |-INFO in [email protected] - Propagating DEBUG level on Logger[http] onto the JUL framework
00:06:46,192 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [http] to false
00:06:46,192 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [httpFile] to Logger[http]
00:06:46,194 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [generalFile] to Logger[http]
00:06:46,194 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [console] to Logger[http]
00:06:46,194 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to OFF
00:06:46,194 |-INFO in [email protected] - Propagating OFF level on Logger[ROOT] onto the JUL framework
00:06:46,194 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [console] to Logger[ROOT]
00:06:46,194 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [generalFile] to Logger[ROOT]
00:06:46,194 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [errorFile] to Logger[ROOT]
00:06:46,195 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
00:06:46,195 |-INFO in [email protected] - Registering current configuration as safe fallback point
ステータスメッセージは何を表していますか? http://logback.qos.ch/manual/configuration.html#statusリスナーの詳細をご覧ください。 – Ceki
私の質問にあなたの助けを借りているのは私のためのplaisureです。私は私の質問にログを追加しました – rsabir