0

While migrating from log 1.x to log2.17.1. I am facing issue in printing of the logs over the console. I changed my web app version from 2.4 to 3.0 and remove all the other config for log4j 1.x. I kept only the new config:-

<context-param>
    <param-name>log4jContextName</param-name>
    <param-value>myApplication</param-value>
</context-param>
<context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>/WEB-INF/config/log4j2.xml</param-value>
</context-param>

in the web.xml

I am using slf4j methods and classes in the code. I kept all the necessary jars related to the the slf4j and log4j in pom.xml.

Application started with below messages while initialisation of the log. But after that no logs from the application in console.

Application startup logs:-

[1/3/22 9:53:22:314 MST] 000000ec SystemOut     O WARN: The method class org.apache.commons.logging.impl.SLF4JLogFactory#release() was invoked.
[1/3/22 9:53:22:315 MST] 000000ec SystemOut     O WARN: Please see http://www.slf4j.org/codes.html#release for an explanation.
[1/3/22 9:53:23:581 MST] 000000ec CompositionUn A   WSVR0193I: Composition unit WebSphere:cuname=my-application in BLA WebSphere:blaname=my-application stopped.
[1/3/22 9:53:25:277 MST] 000000ec AdminHelper   A   ADMN1008I: An attempt is made to start the my-application application. (User ID = defaultWIMFileBasedRealm/server:server1212Cell_server1212Node_server1212sbs1Server)
[1/3/22 9:53:25:291 MST] 000000ec CompositionUn A   WSVR0190I: Starting composition unit WebSphere:cuname=my-application in BLA WebSphere:blaname=my-application.
[1/3/22 9:53:25:318 MST] 000000ec ApplicationMg A   WSVR0200I: Starting application: my-application
[1/3/22 9:53:25:318 MST] 000000ec ApplicationMg A   WSVR0204I: Application: my-application  Application build level: Unknown
[1/3/22 9:53:28:830 MST] 000000ec webapp        I com.ibm.ws.webcontainer.webapp.WebGroupImpl WebGroup SRVE0169I: Loading Web Module: vr-cornerstone.
[1/3/22 9:53:28:893 MST] 000000ec WASSessionCor I SessionContextRegistry getSessionContext SESN0176I: Will create a new session context for application key vhost_sbs1/voice/cornerstone
[1/3/22 9:53:28:894 MST] 000000ec WASSession    I MTMStore setDRSMode SESN0188I: Memory To Memory mode for application vhost_sbs1/voice/cornerstone is BOTH
[1/3/22 9:53:28:894 MST] 000000ec WASSession    I MTMStore setDRSMode SESN0188I: Memory To Memory mode for application vhost_sbs1my-application is BOTH
[1/3/22 9:53:31:001 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,000 Default : 2 DEBUG Starting LoggerContext[name=myApplication] from configuration at file:/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml
[1/3/22 9:53:31:002 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,002 Default : 2 DEBUG Starting LoggerContext[name=myApplication, org.apache.logging.log4j.core.LoggerContext@10e67293] with configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml]...
[1/3/22 9:53:31:003 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,003 Default : 2 DEBUG Shutdown hook enabled. Registering a new one.
[1/3/22 9:53:31:005 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,005 Default : 2 DEBUG Apache Log4j Core 2.17.1 initializing configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml]
[1/3/22 9:53:31:243 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,243 Default : 2 DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
[1/3/22 9:53:31:251 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,251 Default : 2 DEBUG PluginManager 'TypeConverter' found 26 plugins
[1/3/22 9:53:31:259 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,259 Default : 2 DEBUG PatternLayout$Builder(pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", PatternSelector=null, Configuration(/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", disableAnsi="null", noConsoleNoAnsi="null", header="null", footer="null")
[1/3/22 9:53:31:260 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,260 Default : 2 DEBUG PluginManager 'Converter' found 45 plugins
[1/3/22 9:53:31:261 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,261 Default : 2 DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender].
[1/3/22 9:53:31:269 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,269 Default : 2 DEBUG ConsoleAppender$Builder(target="SYSTEM_OUT", follow="null", direct="null", bufferedIo="null", bufferSize="null", immediateFlush="null", ignoreExceptions="null", PatternLayout(%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n), name="Console", Configuration(/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml), Filter=null, ={})
[1/3/22 9:53:31:272 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,272 Default : 2 DEBUG Starting OutputStreamManager SYSTEM_OUT.false.false
[1/3/22 9:53:31:272 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,272 Default : 2 DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
[1/3/22 9:53:31:273 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,273 Default : 2 DEBUG createAppenders(={Console})
[1/3/22 9:53:31:273 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,273 Default : 2 DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
[1/3/22 9:53:31:276 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,276 Default : 2 DEBUG createAppenderRef(ref="Console", level="null", Filter=null)
[1/3/22 9:53:31:276 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,276 Default : 2 DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
[1/3/22 9:53:31:277 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,277 Default : 2 DEBUG createLogger(additivity="null", level="DEBUG", includeLocation="null", ={Console}, ={}, Configuration(/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml), Filter=null)
[1/3/22 9:53:31:280 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,280 Default : 2 DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
[1/3/22 9:53:31:281 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,281 Default : 2 DEBUG createLoggers(={root})
[1/3/22 9:53:31:282 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,282 Default : 2 DEBUG Configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml] initialized
[1/3/22 9:53:31:282 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,282 Default : 2 DEBUG Starting configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml]
[1/3/22 9:53:31:283 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,283 Default : 2 DEBUG Started configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml] OK.
[1/3/22 9:53:31:283 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,283 Default : 2 DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false.false-1
[1/3/22 9:53:31:284 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,284 Default : 2 DEBUG OutputStream closed
[1/3/22 9:53:31:284 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,284 Default : 2 DEBUG Shut down OutputStreamManager SYSTEM_OUT.false.false-1, all resources released: true
[1/3/22 9:53:31:285 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,284 Default : 2 DEBUG Appender DefaultConsole-1 stopped with status true
[1/3/22 9:53:31:285 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,285 Default : 2 DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@14d1de6e OK
[1/3/22 9:53:31:288 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,288 Default : 2 DEBUG Registering MBean org.apache.logging.log4j2:type=myApplication
[1/3/22 9:53:31:291 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,291 Default : 2 DEBUG Registering MBean org.apache.logging.log4j2:type=myApplication,component=StatusLogger
[1/3/22 9:53:31:292 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,292 Default : 2 DEBUG Registering MBean org.apache.logging.log4j2:type=myApplication,component=ContextSelector
[1/3/22 9:53:31:294 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,294 Default : 2 DEBUG Registering MBean org.apache.logging.log4j2:type=myApplication,component=Loggers,name=
[1/3/22 9:53:31:296 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,296 Default : 2 DEBUG Registering MBean org.apache.logging.log4j2:type=myApplication,component=Appenders,name=Console
[1/3/22 9:53:31:299 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,299 Default : 2 DEBUG org.apache.logging.log4j.core.util.SystemClock does not support precise timestamps.
[1/3/22 9:53:31:300 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,300 Default : 2 DEBUG LoggerContext[name=myApplication, org.apache.logging.log4j.core.LoggerContext@10e67293] started OK with configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml].
[1/3/22 9:53:31:301 MST] 000000ec webapp        I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [my-application#my-application-service.war]:.No Spring WebApplicationInitializer types detected on classpath
[1/3/22 9:53:31:308 MST] 000000ec SystemOut     O 2022-01-03 09:53:31,308 Default : 2 DEBUG Log4jServletContextListener ensuring that Log4j starts up properly.
[1/3/22 9:53:31:316 MST] 000000ec webapp        I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [my-application#my-application-service.war]:.Initializing Spring root WebApplicationContext
[1/3/22 9:53:32:011 MST] 000000ec webapp        I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [my-application#my-application-service.war]:.Initializing Spring FrameworkServlet 'rest'
[1/3/22 9:53:33:235 MST] 000000ec ServletWrappe I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [my-application] [/voice/cornerstone] [rest]: Initialization successful.
[1/3/22 9:53:33:261 MST] 000000ec ApplicationMg A   WSVR0221I: Application started: my-application
[1/3/22 9:53:33:261 MST] 000000ec CompositionUn A   WSVR0191I: Composition unit WebSphere:cuname=my-application in BLA WebSphere:blaname=my-application started.
[1/3/22 9:53:45:967 MST] 000001d9 SystemOut     O 2022-01-03 09:53:45,967 WebContainer : 2 DEBUG Log4jServletFilter initialized.

Log4j2.xml file:-

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout
                pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="com.myapp" level="debug">
          <AppenderRef ref="Console"/>
        </Logger>
        <Root level="debug">
            <AppenderRef ref="Console" />
        </Root>
    </Loggers>
</Configuration>

Please let me what I am doing wrong here.

Pom.xml

<dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <!-- <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> 
        <version>${slf4j.version}</version> </dependency> <dependency> <groupId>log4j</groupId> 
        <artifactId>log4j</artifactId> <version>1.2.16</version> </dependency> -->
    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-web -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-web</artifactId>
        <version>2.17.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.17.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.17.1</version>
        <scope>test</scope>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.17.1</version>
    </dependency>
yadav_1992
  • 43
  • 2
  • 11

0 Answers0