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
- Cached loggers
- SL4J implementation
- Aggregated logger
<dependency>
<groupId>com.reposilite</groupId>
<!-- Default -->
<artifactId>journalist</artifactId>
<!-- For SL4J based implementations -->
<artifactId>journalist-sl4j</artifactId>
<version>1.0.12</version>
</dependency>
Repository:
<repository>
<id>panda-repository</id>
<url>https://maven.reposilite.com/releases</url>
</repository>
PrintStream printStream = logger.toPrintStream();
throwable.printStackTrace(printStream); // pass logger as printstream
printStream.close();
Logger logger = // logger with INFO level
logger.debug("message"); // filtered
logger.setThreshold(Channel.DEBUG);
logger.debug("message"); // displayed
Channel bugs = new Channel("bugs", 100.0, ChannelIntention.NEGATIVE)
logger.log(bugs, "Should not happen");
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<Channel, String /* messsage */>
.filter(entry -> Channel.ERROR.equals(entry.getKey()))
.filter(entry -> entry.getValue().contains("Exception"))
.findAny())
Logger logger = new AggregatedLogger(
customLogger,
new SystemLogger(),
new Slf4jLogger(LoggerFactory.getLogger("Default logger"), Channel.ALL)
);