Skip to end of metadata
Go to start of metadata

Logs on the system

When running jenkins.war manually with java -jar jenkins.war, all logging information by default is output to standard out. Many Jenkins native packages modify this behavior to ensure logging information is output in a more conventional location for the platform.

Linux

By default logs should be made available in /var/log/jenkins/jenkins.log, unless customized in /etc/default/jenkins (for *.deb) or via /etc/sysconfig/jenkins (for */rpm)

Windows

By default logs should be at %JENKINS_HOME%/jenkins.out and %JENKINS_HOME%/jenkins.err, unless customized in %JENKINS_HOME%/jenkins.xml

Mac OS X

Log files should be at /var/log/jenkins/jenkins.log, unless customized in org.jenkins-ci.plist

Docker

If you run Jenkins inside docker as a detached container, you can use docker logs containerId to collect jenkins log

Logs in Jenkins

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 where every 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.FileHandler
import java.util.logging.SimpleFormatter
import java.util.logging.LogManager
import jenkins.model.Jenkins

// Log into the console
def WebAppMainLogger = LogManager.getLogManager().getLogger("hudson.WebAppMain")
WebAppMainLogger.addHandler (new ConsoleHandler())

// Log into a file
def RunLogger = LogManager.getLogManager().getLogger("hudson.model.Run")
def logsDir = new File(Jenkins.instance.rootDir, "logs")
if(!logsDir.exists()){logsDir.mkdirs()}
FileHandler handler = new FileHandler(logsDir.absolutePath+"/hudson.model.Run-%g.log", 1024 * 1024, 10, true);
handler.setFormatter(new SimpleFormatter());
RunLogger.addHandler(handler)

This will just copy all log records generated by Jenkins and any plugins to the console and all logs from hudson.model.Run into a file. They will still be available in the log view in the 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.

19 Comments

  1. Unknown User (t.guieu)

    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. Thanks! We'll keep doing that.

  2. Unknown User (alookachaloo)

    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. Unknown User (karl.baum@gmail.com)

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

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

  5. Need to update this page to remove hudson references.

    replace

    hudson.plugins.
    

    by

    org.jenkinsci.plugins.
    
    1. That would be nice, but many plugins still use the old reference, for instance hudson.plugins.disk_usage as in the screenshot above.

  6. 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. 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. 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. 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. 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. Hello,

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

    Thank you,

    Zach

  10. Is it possible? I think (I hope) I found a _partial_ way around the restriction mentioned above...

    >>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.<<

    In this case, I am invoking the build process (on Configure page) with Windows batch command (although this _could_ work with other methods)... After the last batch command I added the following command:

    type %WORKSPACE%\..\builds\%BUILD_NUMBER%\log > myoutput.txt

    which gets the contents of the current build's log file and outputs it to another file (in the Workspace).Of course in real life, it would more sophisticated than a simple file named 'myoutput.txt'

  11. Is there a way to disable (or at least limit) stderr/stdout logging? I have a case where the tomcat stderr log got bloated to 22 GB as a result from Jenkins.

  12. Hi,

    I successfully installed the jenkins docker on my Mac OS system. Unfortunately I couldn't find the jenkins.log file as specified.

    Even I executed find / -name 'jenkins.log' and it didn't find it.

    May I, please, ask you how to locate it? Thanks

  13. Hi, thanks for the very informative article first. but I need to know is it safe to delete the "jenkins.log" file if it gets very huge!! this happens a lot to me. there is no configuration in it or anything that will be lost I guess. Thanks in advance.

  14. How can I push all our build logs after every build to S3?I tried S3 plugin but that pushes only artifactory and not build log.s

Write a comment…