A testing library for asserting logging messages
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Build Status Maven Central codecov


LogCapture is a testing library for asserting logging messages.

How it works

Using the DSL:

captureLogEvents(() -> log.info("a message"))
    .withMessage("a message"))

Using JUnit Rule:

public LogCaptureRule logCaptureRule = new LogCaptureRule();

public void verify_logs_using_rule() {
  log.info("a message");

  logCaptureRule.logged(aLog().info().withMessage("a message"));

More example how to use the library at ExampleShould.java


Binaries and dependency information for Maven, Ivy, Gradle and others can be found at http://search.maven.org.

Example for Maven:


Why LogCapture?

Logging should be a first class citizen in every system that aims to be easily diagnosed and maintained. Logging/testing first could help you to drive production code. At the same time it is easy to log object references and objects that includes private information like passwords or tokens and not realising until we actually read production logs.

We should test how robust are our non-functional capabilities, and not only our functional features. Being able to diagnose, and ultimately fix, issues is a non-functional dimension that should be subject to the same standards as performance, reliability or security.

Logging first development could give you the following benefits:

  • Help you to come up with some useful logging that makes sense in context, that exposes enough, and just enough, semantic information and that does not leak secure information.
  • Help you to understand beforehand what are the high level technical details that your design will implement.
  • Provide insights to security, support or operations engineers that could have different needs and drivers that application developers.
  • Help you to come up with rules for your logging monitoring system.


This project is licensed under MIT license.


Github is for social coding: if you want to write code, I encourage contributions through pull requests from forks of this repository. Create Github tickets for bugs and new features and comment on the ones that you are interested in.