Skip to content

Latest commit

 

History

History
90 lines (70 loc) · 2.39 KB

README.md

File metadata and controls

90 lines (70 loc) · 2.39 KB

Journalist CI codecov

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

Artifact

<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>

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");

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<Channel, String /* messsage */>
    .filter(entry -> Channel.ERROR.equals(entry.getKey()))
    .filter(entry -> entry.getValue().contains("Exception"))
    .findAny())

Aggregation

Logger logger = new AggregatedLogger(
        customLogger,
        new SystemLogger(),
        new Slf4jLogger(LoggerFactory.getLogger("Default logger"), Channel.ALL)
);

Used by