Search code examples
javamavenlogginglog4jweblogic12c

Weblogic12 + Log4j logging not writing to server logs


I know there are lots of Q's regarding this, but I did go through all of them, and kinda confused myself more, I am listing the steps I followed, please let me know where I messed it up.

1) I just want to use Log4j on application level, so need to copy WL_HOME/server/lib/wllog4j.jar, and the log4j.jar in Domail_Home/Lib?

2) I am using Maven, I added the Log4j dependency in my pom.xml [war].I have my WAR wrapped in EAR.

3) Since I want to write the logs in weblogic managed server logs file, I created a custom appender, to use weblogic, NonCatalogAppender as mention in the link - https://blog.desgrange.net/2010/02/15/logging-in-weblogic-console-with-log4j.html

4) I copied the log file in my war/src/main/resources and i see maven added them to classpath i.e war/target/classes, see below for my lo4j xml http://jakarta.apache.org/log4j/'>

  <!-- stdout appender settings -->
  <appender name="STDOUT" class="com.xyz.logging.util.WeblogicAppender">
      <param name="Threshold" value="DEBUG"/>
      <layout class="org.apache.log4j.PatternLayout">
          <!-- notes on patterns:
              %p - priority (i.e. level) of message
              %c - class that threw error 
              %m - message in logger's method, e.g. "Exiting application HERE..." 
              %n - carriage return
              %d - date information
          -->
          <param name="ConversionPattern" value="%c{1} %m"/>
      </layout>
</appender>

<!-- settings for root debugger -->
<root>
    <level value="DEBUG"/>
    <appender-ref ref="STDOUT"/>
</root>

5) Now I didn't change anything on the config level, but I don't see anything appending to server logs. When I initialize NonCatlogLogger manually and call the logger it works fine:

NonCatalogLogger logger =new NonCatalogLogger("XYZ");
logger.debug("This is the debug message")

6) When I debug the application in eclipse, it looks like my custom appender is never called.


Solution

  • Got it, just need to put below into arguments under "server start".

    -Dweblogic.log.Log4jLoggingEnabled=true