How do I create a logger in Jenkins for troubleshooting and diagnostic information?

Issue

  • How do I create a logger?
  • How can I get more detailed diagnostic information?

Environment

  • CloudBees Jenkins Enterprise
  • CloudBees Jenkins Operations Center
  • DEV@cloud

Resolution

To view logs from a specific action exposed by Jenkins, or a plugin not typically monitored, you can add a logger under Manage Jenkins -> System Log -> Add new log recorder

To add a new logger you will be asked to provide it a name and choose a function to monitor. You’ll also have the ability to change the verbosity.

To find what loggers are available you can simply start typing a keyword. For instance, typing ‘git’ will provide you with a list of loggers that may be relevant. You can also look at the source code for Jenkins and its plugins to identify class names which you can get logs from.

logger.png

After saving the log recorder, there are two ways to see the resulting log entries. One is to refresh the log recorder’s page. Logs will only be displayed there while the page is open. If you need to manipulate the Jenkins UI in order to trigger the logging you want to see, you would need to do that in a separate tab or window while continuing to view the log recorder page. The other way to observe these logs is to install the Support Core plugin. When Support Core is installed, custom log recorders will write to $JENKINS_HOME/logs/custom/ on the Jenkins master’s filesystem. You can then tail the relevant file to see updates to it. (Jenkins 2.114 introduced a system property which allows you to specify a different location to store Jenkins logs. Support Core plugin 2.47 supports this, so you may need to check if that property has been set if you are not seeing logs in the default location.)

Finally, it is recommended that you remove any log recorders you have added once they are no longer needed. Depending on how much data they are capturing, they can have a significant impact on Jenkins’s performance.

Have more questions? Submit a request

4 Comments

  • 0
    Avatar
    Sorin Sbarnea

    This doesn't tell anything about log files. As part of the debugging process we need to be able to save specialized logs like this to files. Where are these logs saved and that would be their filenames?

    It is essential to have lots that survive Jenkins restart.

  • 1
    Avatar
    Arnaud Heritier

    Hi Sorin,

      If you have the Support plugin installed, they'll be automatically stored under $JENKINS_HOME/logs/custom/

    Best regards

  • 1
    Avatar
    Chris Weiss

    Logs created by this function turn over quickly - Is there a way to increase the log size or (better yet) pipe the logs to an external logger?

  • 0
    Avatar
    Denys Digtiar

    Hi Chris,

    Jenkins wiki also provides a way to make logs available outside of the web UI. It should probably give you enough flexibility to achieve what you need.

Please sign in to leave a comment.