How to Turn on DEBUG Logging for Individual Classes and Loggers

Sometimes you may not want to turn on DEBUG logging for the whole Yellowfin application because of the copious amounts of log files this will create - especially if you have to leave the DEBUG logging on for a long time.

Never fear! The answer is here!

Yellowfin now uses Log4j2, which replaces the old log4j.properties file with log4j2.xml found in yellowfin/appserver/webapps/ROOT/WEB-INF.

Changing Logging Modes for Log Files

To switch a particular existing log file to debug mode, change the level = INFO to DEBUG.

For example,

<Logger name="com.hof.pool.DBConnectionPool.jdbclog" additivity="false" level="DEBUG">
<AppenderRef ref="jdbclog" />
</Logger>

A table of the log files and their Logger sections in log42.xml can be found below.

Desired Log File
Logger Section in log4j2.xml
yellowfin.log <Root level="INFO">
jdbc.log <Logger name="com.hof.pool.DBConnectionPool.jdbclog" ... >
source.log <Logger name="com.hof.pool.DBConnectionPool.sourcelog" ... >
email.log <Logger name="com.hof.util.Email.emaillog" ... >
transformations.log <Logger name="com.hof.mi.etl" ... >

Class Specific Logging

To enable granular DEBUG logging for a single specific Java class, or to route a specific class's output to its own dedicated log file, there are two methods you can use. 

Logging a Class to the yellowfin.log

The first method outputs the class to the yellowfin.log.

In Log4j2, declare a <Logger> element inside the <Loggers> block at the bottom of the file.

For example, to output DEBUG logs for ReportBroadcastProcess, add the following <Logger> element.

<Loggers>
   <Logger name="com.hof.mi.process.ReportBroadcastProcess" level="DEBUG" />
</Loggers>

Logging a Class to a New Log File

To isolate a class's logs to its own dedicated log file, you must perform two steps:

  1. Define a new <Appender> (where the file lives and how it rolls over).
  2. Define a new <Logger> that links the class name to that appender.

Add the Appender like so, replacing names where appropriate:

<RollingFile name="rptBroadcastLog" fileName="${logDir}/reportbroadcastprocess.log" filePattern="${logDir}/reportbroadcastprocess.log.%i">
   <PatternLayout pattern="${appenderPatternLayout}" />
   <Policies>
      <SizeBasedTriggeringPolicy size="${maxFileSize}" />
   </Policies>
   <DefaultRolloverStrategy fileIndex="min" max="${maxFiles}"/>
</RollingFile>

Add the Logger inside the <Loggers> block and map the class to the new appender:

Note: Set additivity="false" so these debug messages only go to the new file, rather than spamming the main log as well.

<Logger name="com.hof.mi.process.ReportBroadcastProcess" additivity="false" level="DEBUG">
   <AppenderRef ref="rptBroadcastLog" />
</Logger>

We have included the old log4j method here for posterity

It is possible to turn on DEBUG logging for individual classes, just add the following line to the log4j.properties file:

log4j.category.com.hof.mi.process.ReportBroadcastProcess=DEBUG

or more generally:

log4j.category.<insert full class name here>=DEBUG

To enable reportformat debug logging.
#Report Format logs in specific file.
log4j.appender.rptFormatLog=org.apache.log4j.RollingFileAppender
log4j.appender.rptFormatLog.File=${catalina.home}/logs/reportformat.log
log4j.appender.rptFormatLog.MaxFileSize=10240KB
log4j.appender.rptFormatLog.MaxBackupIndex=9
log4j.appender.rptFormatLog.layout = org.apache.log4j.PatternLayout
log4j.appender.rptFormatLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %5p: %m%n
log4j.category.com.hof.mi.manager.ReportFormatManager=DEBUG

Is this article helpful?
1 0 0