8 OBAPI Logging Configuration

Logging Level Configuration with SLF4J & Logback in Weblogic

Logging at package and class levels can be externalized/customized by maintaining a common logback file outside the application for all the wars. This file will be configured as a server start argument.

  1. Use the attached sample reference file and copy it to any physical path. (For example, /scratch/obapi/domains/obapi_domain/logbackOverride.xml)

    logbackOverride.xml

    <configuration scan="true"
            scanPeriod="10 minutes">    
               
            <appender name="STDOUT"
            class="ch.qos.logback.core.ConsoleAppender">        
    <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by
            default -->        
    <encoder>            
    <pattern>%date{dd MMM yyyy;HH:mm:ss.SSS} [%thread] %X{ecid}
            %-5level %logger{100}[%X{FILE_IDENTIFIER} %X{FILE_REF_ID}] -
            %msg%n</pattern>        </encoder>   
            </appender>      
        <!--   <logger name="com.ofss.digx.app.sms.service.user.login"
            level="info"/>   <logger name="com.ofss.digx.app.sms.service.user.User" level="debug"/>   
            -->   
            <root level="ERROR">        
    <appender-ref ref="STDOUT" />   
            </root>     
     </configuration>
  2. Configure the same above path in server start arguments as follows.

    -Dlogback.configurationFile=/scratch/obapi/domains/obapi_domain/logbackOverride.xml

    Enable package and class level logging :

    If you want to change the logging level of a particular class or a package, you can do so by adding the following snippet in the external logback file and taking managed server restart. (Refer to the sample file)

    1. To configure package logging level:

      <logger name="com.ofss.digx.app.sms.service.user.login" level="info"/>

    2. To configure class logging level :

      <logger name="com.ofss.digx.app.sms.service.user.User" level="debug"/>

Note:

In order to get the changes reflected without server restart, you can add a "scan" attribute to the <configuration> element in the external logback file. By default, the configuration file will be scanned for changes once every minute. To configure your desired scan period, add the attribute "scanPeriod" with value in milliseconds, seconds, minutes, or hours.

For example,

<configuration scan="true" scanPeriod="2 minutes">

This will scan for the configuration file every 2 minutes for any changes.

Redirecting stdout and stderr logs into a log file :

To redirect standard out and error logs to a log file, please follow the below steps.

Login to Weblogic console → Take Lock & Edit session → Go to Servers inside Environment menu à

Click on the managed server → Go to Logging tab → Advanced → Check the boxes “Redirect stdout logging enabled” and “Redirect stderr logging enabled” as shown below.