Configure Loggers for Jenkins

Issue

  • I want to adjust the log levels in Jenkins for specific packages / classes

Environment

Resolution

There are different ways of configuring the logging level of Jenkins loggers. This article describe some of them.

Solution 1: use a post initialization script:

Jenkins provides a way to run groovy script during initialization: Post-initialization script. So you can create a script that set the logging levels appropriately on startup. For example, the following script set the level of hudson.security.csrf.CrumbFilter and hudson.plugins.git.GitStatus to the SEVERE level:

import java.util.logging.Level
import java.util.logging.Logger

Logger.getLogger("hudson.plugins.git.GitStatus").setLevel(Level.SEVERE)
Logger.getLogger("hudson.security.csrf.CrumbFilter").setLevel(Level.SEVERE)

Solution 2: use java.util.logging

Create a file logging.properties in which you define the logging levels and a ConsoleHandler. Then pass this file to the JVM by adding the system property -Djava.util.logging.config.file=<pathTo>/logging.properties. A file like the following would apply the same configuration as in Solution 1:

.level = INFO
handlers= java.util.logging.ConsoleHandler

java.util.logging.ConsoleHandler.level=INFO
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

hudson.security.csrf.CrumbFilter.level = SEVERE
hudson.plugins.git.GitStatus.level = SEVERE

See the Java Logging Overview for more details about this method.

(Note: This solution works for classes that use java.util.logging. For classes that use a different implementation - for example org.apache.commons.logging - the level will not be changed)

Solution 3: From the Jenkins UI

You can set the logging level of the Loggers under Manage Jenkins > System Logs > Log Levels. Simply copy/paste the logger or package you want to adjust the level for, select the logging Level and click on Submit. For example, the following matches the same configuration as in Solution 1::

(Note: This solution does not survive a restart)

References

For more information about Jenkins logging and loggers, please have a look at the following articles:

https://wiki.jenkins.io/display/JENKINS/Logging
https://wiki.jenkins.io/display/JENKINS/Logger+Configuration

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.