Logging

Skip to end of metadata
Go to start of metadata

Jenkins uses java.util.logging for logging. The j.u.l system by default sends every log above INFO to stdout, but unfortunately, most servlet containers alter this behavior, making it difficult for us to tell you exactly where you should look at. Also, they tend to bundle all the logs from the entire JVM into a single place, making it difficult to follow a particular aspect of the system.

Because of these reasons, Jenkins is equipped with a GUI for configuring/collecting/reporting log records of your choosing. This page shows you how to do this.

First, select the "system log" from the "Manage Jenkins" page:

From there, you can create a custom log recorder, which helps you group relevant logs together while filtering out the noise.

Choose a name that makes sense to you.

You'll be then asked to configure loggers and their levels whose output you'd like to collect. Depending on which part of Jenkins you monitor, you'll need to specify different loggers. Tell us the symptom of your problem in the users list and we should be able to tell you where you need to look at. Also, this is really just a wrapper around the java.util.logging package, so if you program in Java, you might be able to guess what to look at.

Once the set up is complete, Jenkins will start collecting data. The collected logs are available from the web UI.

Making logs available outside of the web UI

Some people have a need to send log messages to files or a central log server. Another problem with making logs available only in the web UI can arise in case login to Jenkins is broken and therefore you cannot access the log view page which would show you the exceptions that would help you to find out why you cannot login successfully.

Unfortunately, there is no simple way in Jenkins to send log messages generated by Jenkins himself or by any plugins to the console, to a file or anywhere else. No matter what command line options you will use, you just won't succeed. It won't even help if you inject a java.util.logging configuration file directly into the JVM as Jenkins will override any settings in there programmatically.

Technically speaking, Jenkins instantiates a logger called hudson.WebAppMain in the the WebAppMain class and attaches one and only one handler to it: A hudson.util.RingBufferLogHandler. That handler just collects log records in memory and makes them accessible to the log view view in the web UI. All of Jenkins and its plugins inherit from the hudson.WebAppMain logger, which is why nothing being logged there (not even exceptions) ever make it to the console or any log files by default. And as you browse the source code, you'll learn there are absolutely no hooks available at all to allow log output to go anywhere else.

One solution is to use a little known mechanism available in Jenkins: Groovy Hook Script. One can write a piece of Groovy code which will be executed by Jenkins as an init script, i.e. every time Jenkins starts; right when it will be fully initialized and ready to start work. As that Groovy script will execute in the same JVM as Jenkins himself, one can access and manipulate all objects in that VM. So just four lines of Groovy code will be enough to add another handler to the hudson.WebAppMain logger to receive a copy of any log entries generated inside Jenkins and direct them whereevery you want them to show up.

For example, put the following Groovy script into a file called.jenkins/init.groovy.d/extralogging.groovy

import java.util.logging.ConsoleHandler
import java.util.logging.LogManager

def logger = LogManager.getLogManager().getLogger("hudson.WebAppMain")
logger.addHandler (new ConsoleHandler())

This will just copy all log records generated by Jenkins and any plugins to the console. They will still be available in the log view in th web UI.

Of course, you can edit the Groovy script to add other or more handlers, set their levels, etc. Just refer to the java.util.logging documentation.

A much simpler solution (though with no configurability) is to install the Support Core Plugin, which causes custom logs to be written to disk automatically.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Apr 03, 2009

    Thomas Guieu says:

    I don't really know where to tell this, but as it's this page that shows it, I'l...

    I don't really know where to tell this, but as it's this page that shows it, I'll post there.

    This new way of putting things under the lights (the red rectangles) is really easy to follow, we can instantly see where to change things. Please continue with this.

    1. May 26, 2009

      Kohsuke Kawaguchi says:

      Thanks! We'll keep doing that.

      Thanks! We'll keep doing that.

  2. Jun 16, 2009

    Ankit Mittal says:

    I am not sure why , but the Logs that I get when my build fails are different (m...

    I am not sure why , but the Logs that I get when my build fails are different (more detailed), rather than the logs I can see on the output console in Hudson ,How can I see full logs on output console?

    I tried using logger utility to see more logs for Sonar , but it seems its not working out , can you tell me how should I configure logger to get more logs on Sonar ?

    I want to add an environment variable to Hudson that I can set using a shell script , how can I do that ?

  3. Sep 17, 2009

    Karl Baum says:

    Viewing logs through the web is not always ideal.  Can these logs also be w...

    Viewing logs through the web is not always ideal.  Can these logs also be written to the filesystem?

  4. Mar 19, 2010

    fpbremen - says:

    In version 1.351 the help mark beside the 'Log Recorders' text goes to a not (an...

    In version 1.351 the help mark beside the 'Log Recorders' text goes to a not (any more) existing link.

  5. Aug 04, 2011

    Xav DELAS says:

    Need to update this page to remove hudson references. replace hudson.plugins...

    Need to update this page to remove hudson references.

    replace

    hudson.plugins.
    

    by

    org.jenkinsci.plugins.
    
  6. Sep 21, 2011

    Arthur Dias says:

    My UI is logging in INFO level as expected. But in  my catalina.out log fi...

    My UI is logging in INFO level as expected.

    But in  my catalina.out log file ( from Hudson server) I get all INFO log messages, PLUS loads of unnecessary messages like: 

    "

    'name   <host_name>.'

    'name <another_hostname>'

    ...

    "

    Is it Hudson logging ? 

  7. Jul 26, 2012

    Jesse Glick says:

    Not explained here: interaction with "Log Levels" / "Logger Configuration" pag...

    Not explained here:

    • interaction with "Log Levels" / "Logger Configuration" page (/log/levels)
    • how inheritance works in the context of this GUI - does it work? does the order of loggers in a recorder matter?
  8. Jul 11, 2013

    Sorin Sbarnea says:

    Can anyone explain what namespaces are available and how to enable logging for a...

    Can anyone explain what namespaces are available and how to enable logging for all of them? So far my new logger is always empty even if I put ALL and:L"hudson." "org.jenkinsci.plugins."

    1. Jul 11, 2013

      Jesse Glick says:

      Check https://issues.jenkins-ci.org/browse/JENKINS-18274 and https://issues.jenk...
      1. Jul 11, 2013

        Sorin Sbarnea says:

        Thank toy Jesse. Still, all of these are marked as fixed, so I gues there are ot...

        Thank toy Jesse. Still, all of these are marked as fixed, so I gues there are other problems. Also I discovered that if I change the logging level using -Djava.util.logging=DEBUG it will increase the log level on Jenkins web console but not on the JENKINS_LOG... quite unexpected. Using this I was able to fix my problem but the logging is still an issue.

        1. Jul 11, 2013

          Jesse Glick says:

          Fixed in some version of Jenkins, not necessarily yours unless you are running a...

          Fixed in some version of Jenkins, not necessarily yours unless you are running a dev build.

          This is not the best place to have a discussion; use the developers’ list.

  9. Feb 26, 2014

    Zachary Young says:

    Hello, What is the logger name for the Subversion plugin, please? Thank you, ...

    Hello,

    What is the logger name for the Subversion plugin, please?

    Thank you,

    Zach