KB Article #178977

Find log4j category to change log level

Problem

There might be a need to change the log level of some logging in the log4j configuration. For different reasons, for example:


-- INFO logging is to verbose and needs to be reduced to WARN or ERROR

-- More verbose logging is required for troubleshooting, but the exact log4j category is unknown


If Issue shows a log line in the logs (FATAL, ERROR, WARN, or INFO), there are two possible ways to get the correct category.



Resolution

** In general, log4j categories/loggers are the same as the class-packages with or without class-names.


Solution 1)

If the issue is reproducible at will, one can change the log4j appender ConversionPattern.

  • Per default the ConversionPattern shows "%c{1}". Removing the {1}, changing it to "%c", will display the complete logging category/logger.

For example, given the current setting is:

%d{ISO8601} - %-5p [%t] (%c{1}.%M:%L) - %m%n

Change it to:

%d{ISO8601} - %-5p [%t] (%c.%M:%L) - %m%n
  • This would for example result in this log line:
2017-10-19 10:42:23,456 -  - INFO  [Startup] (com.axway.HelloWorld..main:23) - HelloWorld

The logger/category (%c) here is "com.axway.HelloWorld", while the method (%M) is main and the line (%L) is '23'.

  • Search the log4j config file for the found catagory/logger. If it exists, update it to the desired setting, otherwise create a new category and configure it appropriately.


** More information about Log4j conversion pattern can be found at https://logging.apache.org/log4j/1.2/apidocs/org/a... and https://logging.apache.org/log4j/2.x/manual/layout...



Solution 2)

With the default setting, you only see the last part of the logger/category name. This usually is the classname.

  • One needs to find the jar that contains this classfile. This can be done by using the Linux "find" command (on Windows, Cygwin can be used to accomplish the same) and execute it form the installation base folder (or the folder containing the suspected jar):
find -name '*.jar' -exec grep -Hls [classname] {} \;
  • Once the jar is found, unzip the jar (unzip, winzip, 7zip etc):
unzip [class_containing_jar].jar -d [path/to/destination/]
  • Change to the destination folder and find the class again within the unzipped folders:
find * -name [classname]*
  • For example:
$ find * -name HelloWorld
com/axway/HelloWorld.class
  • Replace the slashes (/) with a dot (.) and remove the filename extension (.class) to get the correct category. Following above example:
com.axway.HelloWorld
  • Search the log4j config file for the found catagory. If it exists, update it to the desired setting, otherwise create a new category and configure it appropriately.