代码之家  ›  专栏  ›  技术社区  ›  MarkoU

重新加载配置后,logback停止日志记录

  •  2
  • MarkoU  · 技术社区  · 15 年前

    我们正在评估在多服务器Weblogic环境中使用logback。在一台机器上,我们有两个WebLogic服务器实例(基本上是两个单独的JVM进程)在同一个WebLogic域上运行。服务器记录到同一个日志文件(application.log)。两台服务器的logback配置(logback.xml)相同(如下所示):

    <configuration scan="true" debug="true">
    
        <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>log/application.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <FileNamePattern>log/application.%d{yyyy-MM-dd}.log</FileNamePattern>
        </rollingPolicy>
            <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%d{HH:mm:ss.SSS} [%31.31logger] [%-5level] [%28.-28thread] %msg %xEx %n</pattern>
            </encoder>
        </appender>
    
        <logger name="org" level="ERROR"/>
    
        <root level="DEBUG">
            <appender-ref ref="FILE" />
        </root>
    </configuration>
    

    在编辑配置(例如更改根日志记录级别或添加新日志记录程序)之前,所有操作都正常,之后日志记录将完全停止。日志中不会打印任何内容,控制台中也不会显示任何日志返回错误消息。logback已经处于调试模式,在服务器启动时,通过将以下内容写入每个服务器的控制台进行验证:

    18:06:37,949 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
    18:06:37,951 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
    18:06:37,957 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/opt/bea10/user_projects/KG/resources/config/logback.xml]
    18:06:39,457 |-INFO in ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter@158ef4f  - Will scan for changes in file [/opt/bea10/user_projects/KG/resources/config/logback.xml] every 60 seconds.
    18:06:39,457 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - Adding ReconfigureOnChangeFilter as a turbo filter
    18:06:39,471 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
    18:06:39,556 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE]
    18:06:40,061 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing component [rollingPolicy] on top of the object stack.
    18:06:40,533 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
    18:06:40,563 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern log/application.%d{yyyy-MM-dd}.log for the active file
    18:06:40,652 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'log/application.%d{yyyy-MM-dd}.log'.
    18:06:40,652 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
    18:06:40,654 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Wed Oct 20 17:43:20 EEST 2010
    18:06:40,685 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Pushing component [encoder] on top of the object stack.
    18:06:41,256 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - Active log file name: log/application.log
    18:06:41,257 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - File property is set to [log/application.log]
    18:06:41,307 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org] to ERROR
    18:06:41,307 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org] to true
    18:06:41,307 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
    18:06:41,308 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE] to Logger[ROOT]
    18:06:41,351 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
    

    回溯的版本为0.924,SLF4J为1.06,WebLogic为10.3(怀疑是否重要),Java为1.60*12。操作系统是Solaris。我甚至尝试过使用Java选项

    -XX:-UseVMInterruptibleIO
    

    因为这是针对Solaris上的一个日志问题提出的 here 但是这没有帮助。

    有什么方法可以让这个工作吗?让这两个服务器写入同一个日志文件是一个坏主意吗?

    3 回复  |  直到 7 年前
        1
  •  1
  •   Alex Poole    15 年前

    prudent property 帮助?它增加了开销,但可以解决多个JVM的问题。我不确定你的症状是否完全一致,但也许值得一试。

        2
  •  2
  •   Ceki    14 年前

    正如亚历克斯·普尔之前提到的, prudent mode 应该帮助。还强烈建议注册状态侦听器,例如 OnConsoleStatusListener ,以便在应用程序的生命周期中发生的问题,以及在初始化logback之后,可以报告。

    如果修改的配置文件不是 well formed 0.0.29及更高版本的日志将恢复到以前的格式良好的配置文件。您没有提到新的配置文件有一个格式良好的问题,这就是为什么谨慎模式可能是最相关的响应。

        3
  •  0
  •   Viswa Teja Kuncham    7 年前

    我们有一个类似的问题,有时当重新部署应用程序时,日志会停止日志记录。所以我们在每次部署之后都要重新启动应用服务器。解决了这个问题。

    由于重新启动prod服务器总是很困难的,在进一步的调查和搜索中,我们发现旧版本的logback存在问题。我们将版本从1.1.7改为1.1.10,解决了这个问题。

    推荐文章