Dynamic Logger
Tiny logging wrapper dedicated for CLI oriented applications with non-static logger that require dynamic threshold/level changes, programmable output formatting, custom levels, print stream redirecting and easily testable output.
Available implementations:
- System logger
- In memory logger
- SL4J implementation
- Aggregated logger
Artifact
<dependency>
<artifactId>dynamic-loggerartifactId>
<artifactId>dynamic-logger-sl4jartifactId>
<groupId>net.dzikoyskgroupId>
<version>1.0.1version>
dependency>
Repository:
<repository>
<id>panda-repositoryid>
<url>https://repo.panda-lang.org/releasesurl>
repository>
Usage
Print stream redirecting
PrintStream printStream = logger.toPrintStream();
throwable.printStackTrace(printStream); // pass logger as printstream
printStream.close();
Dynamic threshold change
Logger logger = // logger with INFO level
logger.debug("message"); // filtered
logger.setThreshold(Channel.DEBUG);
logger.debug("message"); // displayed
Custom logging levels
Channel bugs = new Channel("bugs", 100.0, ChannelIntention.NEGATIVE)
logger.log(bugs, "Should not happen");
.filter(entry -> Channel.ERROR.equals(entry.getKey())) .filter(entry -> entry.getValue().contains("Exception")) .findAny()) "> Testable output
InMemoryLogger logger = new InMemoryLogger(); /* * Some code/app/libs using logger */ assertTrue(inMemory.contains("Exception")) // or using custom filters assertTrue(inMemory.getMessages().stream() // Stream of Entry.filter(entry -> Channel.ERROR.equals(entry.getKey())) .filter(entry -> entry.getValue().contains("Exception")) .findAny())