Customizing log4j configuration by using differential extensibility

Update the custom log4jconfig.xml file. The system overlays your changes on the application-provided log4jconfig.xml file.

About this task

Next-generation platformDo not change any existing appender elements. Changes to appender elements might stop the log collection process, prevent you from exporting logs in the Self Service, and prevent you from viewing log files in Graylog. Do not add appender elements. The system collects log files from the default appender elements.

Procedure

  1. Create a custom log4jconfig.xml file in the <runtime_sandbox>/extensions/global/resources/deltalog4jconfig directory. The custom log4jconfig.xml file should be a valid XML file in the same format.
  2. In the log4jconfig.xml file, add only the differential overrides and custom categories or appenders.
    Consider the following application-provided appender:
    <appender name="ALL" class="com.sterlingcommerce.woodstock.util.frame.logex.SCIAppender">
            <param name="rotateLogs" value="true" />
            <param name="maxLogSize" value="100000" />
            <param name="maxNumLogs" value="10" />
            <param name="file" value="/opt/OM/runtime/logs/sci${IBM_LOG_FILE}.log" />
            <layout class="com.sterlingcommerce.woodstock.util.frame.logex.SCICommonLayout">
                <param name="ConversionPatternRef" value="appender.ALL.pattern"/>
                <param name="DefaultConversionPattern" value="%d:%-7p:%t: %-60m [%X{AppUserId}]: [%X{TenantId}]: %-25c{1}%n"/>
            </layout>
            <filter class="com.sterlingcommerce.woodstock.util.frame.logex.SCICommonFilter" />
            <filter class="com.sterlingcommerce.woodstock.util.frame.logex.SCIPatternFilter" />
        </appender>
    Note: To remove an element, pass remove = "true" corresponding to the element in the XML.
    To use differential extensibility for the application-provided appender, override the appender in the <runtime_sandbox>/extensions/global/resources/deltalog4jconfig/log4jconfig.xml file.
    <log4jconfigdelta>
       <appender name="ALL" >
            <param name="rotateLogs" value="false" />
            <param name="maxNumLogs" remove="true"/>
            <param name="file" value="/opt/SSFS_9.5/runtime/logs/sci${IBM_LOG_FILE}_custom.log" />
            <layout class="com.sterlingcommerce.woodstock.util.frame.logex.SCICommonLayout">
                <param name="ConversionPatternRef" value="appender.ALL.pattern"/>
                <param name="DefaultConversionPattern" value="%d:%-8p:%t: %-60m [%X{AppUserId}]: [%X{TenantId}]: %-25c{1}%n"/>
            </layout>
            <filter class="com.abcdcorp.CustomFilter" />
        </appender>
    </log4jconfigdelta>
    Note: Merging of elements is done only at the first level of child elements and not their children. Therefore, in the example, even if there is no change to the ConversionPatternRef parameter, the complete layout element be specified in the differential file.
    Consider the following application-provided category:
    <category  name="com.ibm" class="com.yantra.yfc.log.YFCLogCategory" additivity="false" >
            <level class="com.yantra.yfc.log.YFCLogLevel" value="WARN"  />
             <appender-ref ref="CONSOLE" />
            <appender-ref ref="ALL" />
        </category>
    To use differential extensibility for the application-provided category, modify the category in the <runtime_sandbox>/extensions/global/resources/deltalog4jconfig/log4jconfig.xml file.
    <log4jconfigdelta>
       <category name="com.ibm">
            <appender-ref ref="CONSOLE" remove="true"/>
            <appender-ref ref="CUSTOM_APPENDER" />
        </category>
    </log4jconfigdelta>