无法在多个应用程序的 WebSphere Liberty 配置文件中配置 log4j

Unable to configure log4j in WebSphere Liberty profile for multiple apps

我正在自由部署多个 Web 应用程序,所有这些应用程序都有自己的 log4j 配置 files.The 每个 WAR 中的 log4j 配置文件位于 WEB-INF/classes 文件夹中WAR。添加 log4j 配置的 web.xml 片段如下:

<context-param>
                <param-name>log4jConfiguration</param-name>
                <param-value>classpath:portal-log4j2.xml</param-value>
        </context-param>

这似乎适用于所有其他 Tomcat 和 Jboss 应用程序服务器,但不适用于 WebSphere Liberty 配置文件。即使在 WebSphere Basic profile 中,它似乎也能正常工作。在 jvm.options 中指定 -Dlog4j.configurationFile 对我不起作用,因为我有多个应用程序

我看了

并尝试了同样的方法。对我来说,这导致了以下错误

Exception = javax.xml.stream.XMLStreamException
Source = com.ibm.ws.artifact.loose.internal.LooseContainerFactoryHelper
probeid = 126
Stack Dump = javax.xml.stream.XMLStreamException: ParseError at [row,col]:[8,46]
Message: found: CHARACTERS, expected START_ELEMENT or END_ELEMENT
        at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.nextTag(XMLStreamReaderImpl.java:1361)
        at com.ibm.ws.artifact.loose.internal.LooseContainerFactoryHelper.createContainer(LooseContainerFactoryHelper.java:80)

我的log4j.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="error" name="mbaasportal" packages="com.kony.mobilefabric.logger">
    <!-- Filter to control log level dynamically. The name of the key should match with key in TenantContextFilter.java -->
 <DynamicLogFilter key="KONY_PORTAL_DYNAMIC_LOG_LEVEL" />
 <Appenders>
        <CustomRollingFile name="logfileappender" fileName="${sys:LOG_LOCATION}/mbaasportal.log" append="true" filePattern="${sys:LOG_LOCATION}/mbaasportal.log.%i">
            <MobileFabricPatternLayout>
                <ProductName>console.portal</ProductName>
            </MobileFabricPatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="10 MB"/>
            </Policies>
            <DefaultRolloverStrategy max="10"/>
        </CustomRollingFile>

        <Console name="dockerappender" target="SYSTEM_OUT">            
            <JsonLayout compact="true" eventEol="true" properties="true" locationInfo="true">
                <KeyValuePair key="fabricService" value="console.portal"/>
            </JsonLayout>
        </Console>

        <Console name="consoleappender" target="SYSTEM_OUT"> 
            <MobileFabricPatternLayout> 
                <ProductName>console.portal</ProductName>
            </MobileFabricPatternLayout> 
        </Console>

        <Socket name="SYSLOGappender" host="localhost" port="514" protocol="UDP">
            <Rfc3164SyslogLayout charset="ISO-8859-1" ProductName="console.portal"/>
        </Socket>
    </Appenders>

    <Loggers>
    
     <Logger name="org.hibernate" level="ERROR" additivity="false">
            <AppenderRef ref="${sys:LOG_OPTION}appender"/>
        </Logger>

        <Logger name="org.springframework" level="ERROR" additivity="false">
            <AppenderRef ref="${sys:LOG_OPTION}appender"/>
        </Logger>

        <Logger name="httpclient" level="ERROR" additivity="false">
            <AppenderRef ref="${sys:LOG_OPTION}appender"/>
        </Logger>
        
        <Logger name="com.kony.mbaas.portal.wsclient.RestTemplateWrapper" level="ERROR" additivity="false">
            <AppenderRef ref="${sys:LOG_OPTION}appender"/>
        </Logger>

        <Root level="${sys:LOG_LEVEL}">
            <AppenderRef ref="${sys:LOG_OPTION}appender"/>
        </Root>
    </Loggers>
</Configuration>

非常感谢任何相关指导

我与 IBM 支持部门的 Brian 一起解决了这个问题。似乎该问题特定于 Liberty 上的 Log4j2 2.8,升级到 v2.13 解决了该问题。详情参考如下:

https://developer.ibm.com/answers/questions/526956/log4j-config-file-present-in-webapp-not-loaded-in.html