Skip to content

Tiny logging wrapper dedicated for CLI-oriented applications with dynamic channels and easily testable components

License

Notifications You must be signed in to change notification settings

reposilite-playground/journalist

Repository files navigation

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.10</version>
</dependency>

Repository:

<repository>
    <id>panda-repository</id>
    <url>https://repo.panda-lang.org/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

About

Tiny logging wrapper dedicated for CLI-oriented applications with dynamic channels and easily testable components

Topics

Resources

License

Stars

Watchers

Forks

Languages