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

Issue

Environment

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.

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.

4 Comments

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?