Giter Site home page Giter Site logo

logcapture's Introduction

Build Status Download codecov

LogCapture

LogCapture is a testing library for asserting logging messages.

How it works

Using JUnit Rule:

@Rule
public LogCaptureRule logCaptureRule = new LogCaptureRule();

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

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

Using Spock:

class LogCaptureSpecShould extends LogCaptureSpec {

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

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

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

Using Kotest:

class LogCaptureListenerSpec : StringSpec({

  listener(LogCaptureListener)  // Add LogCaptureListener

  val log: Logger = LoggerFactory.getLogger(LogCaptureListenerSpec::class.java)

  "verify log messages" {
    log.info("a message")

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

More example how to use the library at ExampleShould.java

Binaries

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

Gradle

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

add one of the test library dependency

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

Maven:

<dependency>
    <groupId>com.logcapture</groupId>
    <artifactId>logcapture-core</artifactId>
    <version>x.y.z</version>
</dependency>

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.

License

This project is licensed under MIT license.

Contributing

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.

logcapture's People

Contributors

jsalinaspolo avatar pityq avatar voidshaper avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.