public class IntervalProgressLogger extends Object implements ProgressLogger
ProgressLogger while showing the progress as messages in the console.
Instead of printing all messages immediately and unnecessarily spamming the console output, it rate limits the amount
of messages shown and only prints updates in a pre-defined interval.| Constructor and Description |
|---|
IntervalProgressLogger(String taskName,
Class<?> clazz)
Does the same as
IntervalProgressLogger(String, Class, int) but defaults to
DEFAULT_LOG_INTERVAL for the interval. |
IntervalProgressLogger(String taskName,
Class<?> clazz,
int logInterval)
Creates a
ProgressLogger that shows its progress in a pre-defined interval. |
IntervalProgressLogger(String taskName,
org.slf4j.Logger logger)
Does the same as
IntervalProgressLogger(String, Logger, int) but defaults to
DEFAULT_LOG_INTERVAL for the interval. |
IntervalProgressLogger(String taskName,
org.slf4j.Logger logger,
int logInterval)
Creates a
ProgressLogger that shows its progress in a pre-defined interval. |
| Modifier and Type | Method and Description |
|---|---|
IntervalProgressLogger |
abort()
Marks the task as failed and triggers the output of a status message informing us about the failure.
|
IntervalProgressLogger |
abort(Throwable cause)
Marks the task as failed and triggers the output of a status message informing us about the failure.
|
IntervalProgressLogger |
finish()
Sets the current step to the expected step count and triggers the output of the current progress.
|
int |
getCurrentStep()
Returns the current finished step of this logger.
|
boolean |
getEnabled()
This method is the getter for the enabled flag of the logger.
|
int |
getStepCount()
Returns the expected step count of this logger.
|
IntervalProgressLogger |
progress()
Increases the current step by one and triggers the output of the current progress.
|
IntervalProgressLogger |
progress(int currentStep)
Sets the current step to the given value and triggers the output of the current progress.
|
IntervalProgressLogger |
setCurrentStep(int currentStep)
Sets the current step to the given value without triggering an output.
|
IntervalProgressLogger |
setEnabled(boolean enabled)
This method is the setter for the enabled flag of the logger.
|
IntervalProgressLogger |
setStepCount(int stepCount)
Sets the expected step count to the given value without triggering an output.
|
IntervalProgressLogger |
start()
Starts the logging by (re)setting the current step to 0 and trigger the output of the current progress.
|
IntervalProgressLogger |
start(int stepCount)
Does the same as
ProgressLogger.start() but sets the expected step count to the given value. |
public IntervalProgressLogger(String taskName, Class<?> clazz)
IntervalProgressLogger(String, Class, int) but defaults to
DEFAULT_LOG_INTERVAL for the interval.taskName - name of the task that shall be shown on the screenclazz - class that is used to identify the origin of the log messagespublic IntervalProgressLogger(String taskName, org.slf4j.Logger logger)
IntervalProgressLogger(String, Logger, int) but defaults to
DEFAULT_LOG_INTERVAL for the interval.taskName - name of the task that shall be shown on the screenlogger - logback logger for issuing the messagespublic IntervalProgressLogger(String taskName, Class<?> clazz, int logInterval)
ProgressLogger that shows its progress in a pre-defined interval.taskName - name of the task that shall be shown on the screenclazz - class that is used to identify the origin of the log messageslogInterval - the time in milliseconds between consecutive log messagespublic IntervalProgressLogger(String taskName, org.slf4j.Logger logger, int logInterval)
ProgressLogger that shows its progress in a pre-defined interval.taskName - name of the task that shall be shown on the screenlogger - logback logger for issuing the messageslogInterval - the time in milliseconds between consecutive log messagespublic IntervalProgressLogger start()
start in interface ProgressLoggerpublic IntervalProgressLogger start(int stepCount)
ProgressLogger.start() but sets the expected step count to the given value.
This allows us to initialize and start the logging in a single call.start in interface ProgressLoggerstepCount - number of steps that the task involvespublic IntervalProgressLogger progress()
progress in interface ProgressLoggerpublic IntervalProgressLogger progress(int currentStep)
progress in interface ProgressLoggercurrentStep - the current step that was just finishedpublic IntervalProgressLogger finish()
finish in interface ProgressLoggerpublic IntervalProgressLogger abort()
abort in interface ProgressLoggerpublic IntervalProgressLogger abort(Throwable cause)
Exception.
It will show the message immediately instead of waiting for the interval to pass.abort in interface ProgressLoggercause - reason for the failurepublic int getCurrentStep()
getCurrentStep in interface ProgressLoggerpublic IntervalProgressLogger setCurrentStep(int currentStep)
setCurrentStep in interface ProgressLoggercurrentStep - the current step that was just finishedpublic int getStepCount()
getStepCount in interface ProgressLoggerpublic IntervalProgressLogger setStepCount(int stepCount)
setStepCount in interface ProgressLoggerstepCount - the expected step count of this loggerpublic boolean getEnabled()
getEnabled in interface ProgressLoggerpublic IntervalProgressLogger setEnabled(boolean enabled)
setEnabled in interface ProgressLoggerenabled - true if the logger shall output messages and false otherwise (the logger is enabled by default)Copyright © 2019. All rights reserved.