public class ProgressLogger extends Object
Utility class for logging progress of some long-running process.
Modifier and Type | Method and Description |
---|---|
void |
advance()
Record that an item has been completed.
|
static ProgressLogger |
create(org.slf4j.Logger log)
Create a new progress logger.
|
String |
elapsedTime()
Get a string representation of the elapsed time.
|
double |
finish()
Log that the process has finished.
|
static String |
formatElapsedTime(double seconds)
Format elapsed time.
|
void |
logProgress()
Log the current progress to the logger.
|
ProgressLogger |
setCount(int n)
Set the number of total items to be processed.
|
ProgressLogger |
setLabel(String lbl)
Set the label to be used in log messages.
|
ProgressLogger |
setPeriod(int p)
Set the period for progress messages.
|
ProgressLogger |
setWindow(int w)
Set the window to use for smoothing averages.
|
ProgressLogger |
start()
Start the progress logger’s timer.
|
public static ProgressLogger create(org.slf4j.Logger log)
Create a new progress logger.
log
- The logger to which progress should be logged.public ProgressLogger setLabel(String lbl)
Set the label to be used in log messages.
lbl
- The label.public ProgressLogger setCount(int n)
Set the number of total items to be processed.
n
- The total number of items to be processed.public ProgressLogger setPeriod(int p)
Set the period for progress messages.
p
- The progress message period.public ProgressLogger setWindow(int w)
Set the window to use for smoothing averages.
w
- The window size, in number of periods.public ProgressLogger start()
Start the progress logger’s timer.
public void advance()
Record that an item has been completed.
public void logProgress()
Log the current progress to the logger.
public double finish()
Log that the process has finished.
public String elapsedTime()
Get a string representation of the elapsed time.
public static String formatElapsedTime(double seconds)
Format elapsed time.
seconds
- The number of seconds that have elapsed.