Enable custom logging

You can add custom loggers and appender in the log4j2.xml file to enable custom logging.

Procedure

Use the following steps to enable custom logging.

  1. Go to the $TOP/etc/default folder.
  2. Edit the log4j2.xml file.
  3. Go to the <Loggers> section.
  4. Add the following custom logger.
    <Loggers>
    <Logger name="package_name" level="debug" additivity="false">
    <AppenderRef ref="DEFAULT" />
    </Logger>
    </Loggers>
    The default appender in the log4j2.xml file is configured to log the logging events in the ipm.log file.
  5. Optional: To log the custom logs in a different log file (example custom.log), you can add the following logger and appender.
    
    <RollingFile name="CUSTOM" fileName="/opt/MDM/logs/${svc_name}/custom.log" append="true" 
    	filePattern="%LOG_DIR%/${svc_name}/ipm-%d{MM-dd-yyyy}-%i.log">
    		<PatternLayout>
    			<ScriptPatternSelector defaultPattern="%d [%t] %-5p %c %x- %m%n">
    				<ScriptRef ref="decideLoggingPattern"/>
    					<PatternMatch key="showIpAddressAndUserName" pattern="%d 
    ip_address=[%X{loggedInUserIp}] user=[%X{UserName}] [%t] %-5p %c %x- %m%n"/> </ScriptPatternSelector> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy /> <SizeBasedTriggeringPolicy size="10 MB" /> </Policies> <DefaultRolloverStrategy max="2" /> </RollingFile>
    loggedInUserIp - Visible if the enable_client_ip_username_logging property is enabled in the common.properties file. For more information, see common.properties file parameters. This logs user details like IP address and username into the ipm.log file of the app server. You need to overwrite the log4j2.xml file to enable this. When you run the configureEnv.sh script file, you must enter y as an input when prompted for the log4j2.xml file.

Example

<Loggers>
<Logger name="com.test" level="debug" additivity="false">
<AppenderRef ref="DEFAULT" />
</Logger>
</Loggers>