From 8d74b3cd5e7c2eaa5e2e6328edbb6403168bf4aa Mon Sep 17 00:00:00 2001 From: boev Date: Mon, 3 Feb 2014 16:24:17 +0100 Subject: [PATCH] Added logging level methods to AsyncPeriodicWork. --- .../java/hudson/model/AsyncPeriodicWork.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/hudson/model/AsyncPeriodicWork.java b/core/src/main/java/hudson/model/AsyncPeriodicWork.java index f678e1425e..abe863afb2 100644 --- a/core/src/main/java/hudson/model/AsyncPeriodicWork.java +++ b/core/src/main/java/hudson/model/AsyncPeriodicWork.java @@ -38,12 +38,12 @@ public abstract class AsyncPeriodicWork extends PeriodicWork { public final void doRun() { try { if(thread!=null && thread.isAlive()) { - logger.log(Level.INFO, name+" thread is still running. Execution aborted."); + logger.log(this.getNormalLoggingLevel(), name+" thread is still running. Execution aborted."); return; } thread = new Thread(new Runnable() { public void run() { - logger.log(Level.INFO, "Started "+name); + logger.log(getNormalLoggingLevel(), "Started "+name); long startTime = System.currentTimeMillis(); StreamTaskListener l = createListener(); @@ -59,13 +59,13 @@ public abstract class AsyncPeriodicWork extends PeriodicWork { l.closeQuietly(); } - logger.log(Level.INFO, "Finished "+name+". "+ + logger.log(getNormalLoggingLevel(), "Finished "+name+". "+ (System.currentTimeMillis()-startTime)+" ms"); } },name+" thread"); thread.start(); } catch (Throwable t) { - logger.log(Level.SEVERE, name+" thread failed with error", t); + logger.log(this.getErrorLoggingLevel(), name+" thread failed with error", t); } } @@ -83,7 +83,27 @@ public abstract class AsyncPeriodicWork extends PeriodicWork { protected File getLogFile() { return new File(Jenkins.getInstance().getRootDir(),name+".log"); } - + + /** + * Returns the logging level at which normal messages are displayed. + * + * @return + * The logging level as @Level. + */ + protected Level getNormalLoggingLevel() { + return Level.INFO; + } + + /** + * Returns the logging level at which error messages are displayed. + * + * @return + * The logging level as @Level. + */ + protected Level getErrorLoggingLevel() { + return Level.SEVERE; + } + /** * Executes the task. *