提交 1a4e8312 编写于 作者: S Stephen Connolly

Use logging API correctly and introduce the ability to differentiate between...

Use logging API correctly and introduce the ability to differentiate between the logging level for task execution taking too long
上级 2eb43ff9
......@@ -9,6 +9,7 @@ import org.acegisecurity.context.SecurityContextHolder;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.LogRecord;
/**
* {@link PeriodicWork} that takes a long time to run.
......@@ -38,12 +39,12 @@ public abstract class AsyncPeriodicWork extends PeriodicWork {
public final void doRun() {
try {
if(thread!=null && thread.isAlive()) {
logger.log(this.getNormalLoggingLevel(), name+" thread is still running. Execution aborted.");
logger.log(this.getSlowLoggingLevel(), "{0} thread is still running. Execution aborted.", name);
return;
}
thread = new Thread(new Runnable() {
public void run() {
logger.log(getNormalLoggingLevel(), "Started "+name);
logger.log(getNormalLoggingLevel(), "Started {0}", name);
long startTime = System.currentTimeMillis();
StreamTaskListener l = createListener();
......@@ -59,13 +60,16 @@ public abstract class AsyncPeriodicWork extends PeriodicWork {
l.closeQuietly();
}
logger.log(getNormalLoggingLevel(), "Finished "+name+". "+
(System.currentTimeMillis()-startTime)+" ms");
logger.log(getNormalLoggingLevel(), "Finished {0}. {1,number} ms",
new Object[]{name, (System.currentTimeMillis()-startTime)});
}
},name+" thread");
thread.start();
} catch (Throwable t) {
logger.log(this.getErrorLoggingLevel(), name+" thread failed with error", t);
LogRecord lr = new LogRecord(this.getErrorLoggingLevel(), "{0} thread failed with error");
lr.setThrown(t);
lr.setParameters(new Object[]{name});
logger.log(lr);
}
}
......@@ -96,6 +100,18 @@ public abstract class AsyncPeriodicWork extends PeriodicWork {
return Level.INFO;
}
/**
* Returns the logging level at which previous task still executing messages is displayed.
*
* @return
* The logging level as @Level.
*
* @since 1.565
*/
protected Level getSlowLoggingLevel() {
return getNormalLoggingLevel();
}
/**
* Returns the logging level at which error messages are displayed.
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册