How to change the default or package log levels

Article ID:115003914391
1 minute readKnowledge base

Issue

  • How we can change the default log level?

  • How we can change a package log level?

Resolution

If you want to change the default/package log level temporally you have to go to Manage Jenkins > System Log > Log Levels and set the level that you want. The logger with no name is the default logger. All the loggers without a configured level inherit the level of the default logger. This change will be lost when you restart the Jenkins instance.

If you want to make this change permanent, you have to create a groovy file in JENKINS_HOME/init.groovy.d to set up a Logger programmatically. Below is an example of how to set the log level INFO to the default logger and to the package org.apache.commons.httpclient.

import java.util.logging.LogManager
import java.util.logging.Logger
import jenkins.model.Jenkins
import java.util.logging.Level

Logger.getGlobal().setLevel(Level.INFO);

def logger = Logger.getLogger("org.apache.commons.httpclient")
logger.setLevel(Level.INFO)
LogManager.getLogManager().addLogger(logger)

You also can configure the Java logger using a logging.properties file by setting the Java property -Djava.util.logging.config.file=logging.properties on your startup Jenkins properties.

Example of logging.properties file

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

java.util.logging.FileHandler.level = INFO
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.pattern=support/jenkins-cli-%u.log
java.util.logging.FileHandler.limit = 1000000
java.util.logging.FileHandler.count = 25

hudson.level = INFO
org.apache.sshd.level = INFO
winstone.level = INFO

org.apache.commons.httpclient.level = INFO