I cannot find the logging for my plugin

7,169 views
Skip to first unread message

mike

unread,
Oct 29, 2012, 10:33:55 AM10/29/12
to jenkin...@googlegroups.com
Hi,

I have made a plugin ( that works most of the time). I have added logging using:

private static final Logger LOG = Logger.getLogger(TestResults.class
                                                       .getName());

  LOG.info("matchLevel() totalValue "+totalValue.toString());

I checked the log in Jenkins ( I know the code has been executed) but I cannot find this output but I find other INFO traces:

INFO: Completed initialization
Oct 29, 2012 12:14:24 PM jenkins.InitReactorRunner$1 onAttained
INFO: Loaded all jobs
Oct 29, 2012 12:13:21 PM jenkins.InitReactorRunner$1 onAttained
INFO: Augmented all extensions
Oct 29, 2012 12:13:21 PM jenkins.InitReactorRunner$1 onAttained
INFO: Started all plugins
Oct 29, 2012 12:13:21 PM jenkins.InitReactorRunner$1 onAttained
INFO: Prepared all plugins
Oct 29, 2012 12:13:10 PM jenkins.InitReactorRunner$1 onAttained
INFO: Listed all plugins


How come I do not find the traces for my plugin in Jenkins log? Do I need to do anything in Jenkins to enable them?

br,

//Mike

Bruno P. Kinoshita

unread,
Oct 29, 2012, 10:37:26 AM10/29/12
to jenkin...@googlegroups.com
Hi Mike, 

You have to create a logger for your plug-in with the right level.

I believe this will help you: https://wiki.jenkins-ci.org/display/JENKINS/Logging

Cheers,

Bruno P. Kinoshita
http://kinoshita.eti.br
http://tupilabs.com


>________________________________
> From: mike <mikaelpe...@gmail.com>
>To: jenkin...@googlegroups.com
>Sent: Monday, 29 October 2012 12:33 PM
>Subject: I cannot find the logging for my plugin

mike

unread,
Oct 29, 2012, 11:20:49 AM10/29/12
to jenkin...@googlegroups.com, Bruno P. Kinoshita
Thanks that helped.

br,

//mike

Scott Cowan

unread,
Feb 14, 2013, 9:59:21 AM2/14/13
to jenkin...@googlegroups.com, Bruno P. Kinoshita
Hi,

I've been able to follow the instructions @ https://wiki.jenkins-ci.org/display/JENKINS/Logging to create a log specifically for my plugin.  But I think I want my log messages to also be logged in the Jenkins log.  If a user of a plugin encounters a problem that was unhandled by the plugin developer, and it only happens once, what is the strategy for capturing the correct information for the user to open an issue?  I'd like to be able to log a stack trace at that point if the issue is severe.  If it only happens once, or is very difficult to reproduce then it is too late to tell the user to add a logger and try again, and the stack trace will be lost.

Thanks in advance,
Scott

Jesse Glick

unread,
Feb 14, 2013, 11:49:20 AM2/14/13
to jenkin...@googlegroups.com
On 02/14/2013 09:59 AM, Scott Cowan wrote:
> I'd like to be able to log a stack trace at that point if the issue is severe.

private static final Logger LOGGER = Logger.getLogger(ThisClass.class.getName());

} catch (Exception x) {
LOGGER.log(Level.WARNING, "optional info", x);
}

Anything over INFO will be sent to the master log by default. You only need to configure custom loggers if you want to enable FINE/FINER/FINEST logging in some components.

Scott Cowan

unread,
Feb 14, 2013, 12:06:32 PM2/14/13
to jenkin...@googlegroups.com
Hmmm...  That is what I'm trying, and the my messages are getting logged with the ConsoleLogger, but they're not appearing in the Jenkins log at http://localhost:8080/log/all.  I'm launching with hpi:run.  I also expected INFO level messages to be logged, not just "Anything over INFO".

Got any other test ideas?  Thanks,
Scott

Scott Cowan

unread,
Feb 21, 2013, 4:28:03 PM2/21/13
to jenkin...@googlegroups.com

Hi Jesse,

I finally got around to making a simple test.  I generated the HelloWorldBuilder example described here, https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial.

I added these two LOGGER lines to HelloWorldBuilder.java, commented with // NEW LINE.
------------------
...
 * @author Kohsuke Kawaguchi
 */
public class HelloWorldBuilder extends Builder {
    private static final Logger LOGGER = Logger.getLogger(HelloWorldBuilder.class.getName()); // NEW LINE
...
    @Override
    public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {
        LOGGER.warning("Hello, "+name+"!"); // NEW LINE
        // This is where you 'build' the project.
...
------------------

And I'm finding the same problem.  The warning is written to the console, but not the Jenkins Log.  Is this a defect?

Thanks in advance,
Scott

Jesse Glick

unread,
Feb 21, 2013, 5:31:35 PM2/21/13
to jenkin...@googlegroups.com
On 02/21/2013 04:28 PM, Scott Cowan wrote:
> The warning is written to the console, but not the Jenkins Log. Is this a defect?

According to WebAppMain.installLogger, only loggers in the hudson.* or jenkins.* namespaces are kept, so check your logger name.

Scott Cowan

unread,
Feb 22, 2013, 12:23:15 PM2/22/13
to jenkin...@googlegroups.com

Hi Jesse,

Thanks for the tip!  My logger name was "org.jenkinsci.plugins.helloworld.HelloWorldBuilder".  When I changed it to, "jenkins.HelloWorldBuilder" the warning was logged to the Jenkins Log.

------------------
...
    private static final Logger LOGGER = Logger.getLogger("jenkins.HelloWorldBuilder");  // NEW LINE
...
------------------

I supposed this means when a plugin experiences an unexpected error and logs it as SEVERE, the admin would have to add a logger and reproduce the problem to get the stack trace.  The admin would probably have to go to our plugin's wiki page to find the plugin's namespace to know what to log.  Then the admin could report an issue with the plugin.  My concern with this approach is that it encourages us to log the stack trace right in the job's console or return a form validation error with a stack trace to the web UI during validation so the user has enough information to report a problem right away.

Is the the intended approach?  How have users been reporting plugin issues traditionally?  Do they supply a stack trace?

Thanks again for your help,
Scott

Jesse Glick

unread,
Feb 22, 2013, 1:08:04 PM2/22/13
to jenkin...@googlegroups.com
On 02/22/2013 12:23 PM, Scott Cowan wrote:
> I supposed this means when a plugin experiences an unexpected error and logs it as SEVERE, the admin would have to add a logger and reproduce the problem to get the stack
> trace.

I think plugins are just supposed to use loggers in the jenkins.* namespace to begin with, though I acknowledge that this clashes with the usual package name
recommendations for new plugins. I am not sure why WebAppMain.installLogger only registers the jenkins (and hudson) namespace hierarchies, rather than just capturing all
log messages in the JVM; maybe to avoid picking up logging from app containers and the like? But then it would be better to capture all log records by default, and skip
just those whose source class name can be determined to be part of the container (e.g. defined in a class loader which is an ancestor of that used to load Jenkins.class).

Probably best to file a bug report (and pull request if possible).

Scott Cowan

unread,
Feb 25, 2013, 1:46:57 PM2/25/13
to jenkin...@googlegroups.com
Hi Jesse,

I want to open this issue, but I'm waiting for a reply to https://groups.google.com/forum/?fromgroups=#!topic/jenkinsci-dev/dl3OzUx3nIA requesting additional verification for my JIRA account.  Did I request correctly?  Do I need to do anything else to speed it along?

Thanks again,
Scott

Jesse Glick

unread,
Feb 25, 2013, 2:06:04 PM2/25/13
to jenkin...@googlegroups.com
On 02/25/2013 01:46 PM, Scott Cowan wrote:
> I want to open this issue

I went ahead and filed it myself:

https://issues.jenkins-ci.org/browse/JENKINS-16952

> I'm waiting for a […] verification for my JIRA account. Did I request correctly?

Sorry, no idea, hope someone else can help you.
Reply all
Reply to author
Forward
0 new messages