Added logging level methods to AsyncPeriodicWork.

This commit is contained in:
boev committed 2014-02-03 16:24:17 +01:00
1 parent 48a2c9c119
commit 8d74b3cd5e
1 file changed
+25 -5
@@ -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.
*