-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1751 from jplag/feature/cliLogLevel
Added command line option for log-level
- Loading branch information
Showing
7 changed files
with
102 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
cli/src/main/java/de/jplag/cli/logger/VoidProgressBar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package de.jplag.cli.logger; | ||
|
||
import de.jplag.logging.ProgressBar; | ||
|
||
/** | ||
* An empty {@link ProgressBar} implementation, used to hide the progress bar depending on the log level. | ||
*/ | ||
public class VoidProgressBar implements ProgressBar { | ||
@Override | ||
public void step(int number) { | ||
// does nothing see class description | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
// does nothing see class description | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
cli/src/test/java/de/jplag/cli/logger/VoidProgressBarTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package de.jplag.cli.logger; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.slf4j.event.Level; | ||
|
||
import de.jplag.logging.ProgressBar; | ||
import de.jplag.logging.ProgressBarType; | ||
|
||
class VoidProgressBarTest { | ||
@Test | ||
void testVoidProgressBarBehaviour() { | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
PrintStream originalOutput = System.out; | ||
System.setOut(new PrintStream(outputStream)); | ||
|
||
VoidProgressBar progressBar = new VoidProgressBar(); | ||
progressBar.step(); | ||
progressBar.step(2); | ||
progressBar.dispose(); | ||
|
||
System.setOut(originalOutput); | ||
|
||
Assertions.assertEquals("", outputStream.toString()); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("getRelevantLogLevels") | ||
void testVoidProgressBarCreated(Level logLevel) { | ||
Level originalLogLevel = CollectedLogger.getLogLevel(); | ||
CollectedLogger.setLogLevel(logLevel); | ||
|
||
ProgressBar progressBar = new CliProgressBarProvider().initProgressBar(ProgressBarType.CLUSTERING, 10); | ||
progressBar.dispose(); | ||
|
||
Assertions.assertInstanceOf(VoidProgressBar.class, progressBar); | ||
|
||
CollectedLogger.setLogLevel(originalLogLevel); | ||
} | ||
|
||
public static Level[] getRelevantLogLevels() { | ||
return new Level[] {Level.TRACE, Level.DEBUG, Level.ERROR, Level.WARN}; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.