Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Build Status Sonatype Nexus codecov Known Vulnerabilities


LogCapture is a testing library for asserting logging messages.

How it works

Using JUnit Rule:

public LogCaptureRule logCaptureRule = new LogCaptureRule();

public void verify_logs_using_rule() {"a message");

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

Using JUnit 5 Extension:

public LogCaptureExtension logCaptureExtension = new LogCaptureExtension();

public void verify_logs_using_extension() {"a message");

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

Using Spock:

class LogCaptureSpecShould extends LogCaptureSpec {

  @Shared log = LoggerFactory.getLogger(getClass())

  def "verify log message"() {
    expect:"a message");

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

Using Kotest:

class LogCaptureListenerSpec : StringSpec({
  val logCaptureListener = LogCaptureListener()
  listener(logCaptureListener)  // Add LogCaptureListener

  val log: Logger = LoggerFactory.getLogger(

  "verify log messages" {"a message")

    logCaptureListener.logged(aLog().info().withMessage("a message"))

More example how to use the library at


Binaries and dependency information for Maven, Ivy, Gradle and others can be found at


testImplementation 'org.logcapture:logcapture-core:x.y.z'

add one of the test library dependency

testImplementation 'org.logcapture:logcapture-junit4:x.y.z'
testImplementation 'org.logcapture:logcapture-junit5:x.y.z'
testImplementation 'org.logcapture:logcapture-spock:x.y.z'
testImplementation 'org.logcapture:logcapture-kotest:x.y.z'



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.