简体   繁体   English

当两个 logback.xml 在 Websphere 服务器上运行时,日志被合并

[英]Logs getting merged when two logback.xml runs on Websphere server

The problem I'm facing is, I have an application which uses a jar file(jar1) containing the logback.xml(having destination folder for its log files) and another application also using a jar file(jar2) containing another logback.xml(having different destination folder for its log files).我面临的问题是,我有一个应用程序使用包含 logback.xml 的 jar 文件(jar1)(具有其日志文件的目标文件夹)和另一个应用程序也使用包含另一个 logback.xml 的 jar 文件(jar2) (其日志文件具有不同的目标文件夹)。 For the first application I'm using a classloader with a share file configuration of jar1.对于第一个应用程序,我使用了一个带有 jar1 共享文件配置的类加载器。 Now in this case, the logs are getting merged.现在在这种情况下,日志正在合并。 Some logs are getting created in the first destination folder for the second application and vice-versa.在第二个应用程序的第一个目标文件夹中创建了一些日志,反之亦然。 I'm using WebSphere9.我正在使用 WebSphere9。 Is there a way, the log files get created in their specific destination folder, without the logs getting merged?有没有办法在其特定的目标文件夹中创建日志文件,而不合并日志?

Keeping the first classloader, I have tried using a second classloader with a share file configuration of jar2,for second application.保留第一个类加载器,我尝试使用带有 jar2 共享文件配置的第二个类加载器,用于第二个应用程序。 But in this case either of the application works.但在这种情况下,任何一个应用程序都可以工作。 So this solution was ruled out.所以这个解决方案被排除了。

The logback.xml of first application:第一次申请的logback.xml:

<?xml version="1.0" encoding="UTF-8"?>

<appender name="consoleAppender"
    class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
        <Pattern>%-50(%level %logger{35}) cn=%contextName - %msg%n</Pattern>
    </layout>
</appender>

<appender name="mainAppender"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${USR_HOME}/yoda.log</file>
    <rollingPolicy
        class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>${USR_HOME}/yoda.%i.log</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>20</maxIndex>
        <cleanHistoryOnStart>true</cleanHistoryOnStart>
    </rollingPolicy>
    <triggeringPolicy
        class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>50MB</maxFileSize>
    </triggeringPolicy>
    <encoder
        class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern%-50(%level %logger{35}) cn=%contextName - %msg%n</Pattern>
    </encoder>
    <prudent>false</prudent>
</appender>

<root name="MAIN_LOGGER" level="ERROR" additivity="true">
    <appender-ref ref="mainAppender" />
</root>

The logback.xml for second application:第二个应用程序的 logback.xml:

 <?xml version="1.0" encoding="UTF-8"?>

<appender name="consoleAppender"
    class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
        <Pattern>%-50(%level %logger{35}) cn=%contextName - %msg%n</Pattern>
    </layout>
</appender>

<appender name="mainAppender"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${AG_HOME}/kenobi.log</file>
    <rollingPolicy
        class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>${AG_HOME}/kenobi.%i.log</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>20</maxIndex>
        <cleanHistoryOnStart>true</cleanHistoryOnStart>
    </rollingPolicy>
    <triggeringPolicy
        class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>50MB</maxFileSize>
    </triggeringPolicy>
    <encoder
        class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
        <Pattern%-50(%level %logger{35}) cn=%contextName - %msg%n</Pattern>
    </encoder>
    <prudent>false</prudent>
</appender>

<root name="MAIN_LOGGER" level="ERROR" additivity="true">
    <appender-ref ref="mainAppender" />
</root>

It looks like only one of the logback config file gets picked up by the classloader shared by both applications.看起来只有一个 logback 配置文件被两个应用程序共享的类加载器拾取。 Instead of packaging the logback or log4j config file in your application jar files, try to add the two config files in two shared libraries defined on WebSphere, and config your application to reference your shared libraries.不要将 logback 或 log4j 配置文件打包到您的应用程序 jar 文件中,而是尝试将这两个配置文件添加到 WebSphere 上定义的两个共享库中,并配置您的应用程序以引用您的共享库。

Take a look at IBM Knowledge Center's article on reference shared libraries.查看 IBM Knowledge Center 关于参考共享库的文章。 https://www.ibm.com/support/knowledgecenter/SS7K4U_9.0.5/com.ibm.websphere.zseries.doc/ae/tcws_sharedlib_app.html https://www.ibm.com/support/knowledgecenter/SS7K4U_9.0.5/com.ibm.websphere.zseries.doc/ae/tcws_sharedlib_app.html

In both the logback.xml files, you have defined root level logger only.在这两个 logback.xml 文件中,您只定义了根级别记录器。 Root level logger logs from all the applications in logger file.来自记录器文件中所有应用程序的根级别记录器日志。

Try, defining seperate logger in logback尝试,在 logback 中定义单独的记录器

<logger name="com.x.y.z" level="INFO" additivity="false">
    <appender-ref ref="refToAppender" />        
</logger>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM