question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create a SLF4J-compatible logging extension, which can be used to sniff logs

See original GitHub issue
class MyTest : FunSpec(
  {
    val logs = install(LogSniffer) { minLevel = Level.INFO }

    test("check that logs are on correct level and contains id") {
       logs.forOne {
         it.level shouldBe Level.WARN
         it.message shouldContain "myId"
      }
    }
  }
)

Do you think it’s worth adding as an extension (kotest-extensions-logging?)?

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
sksamuelcommented, Apr 30, 2022

What about just saying this was a good idea that didn’t work out 😃

1reaction
Kantiscommented, Apr 28, 2022

@jschneidereit i meant to monitor the logs of the production code. 😃

for instance:

class Greeter {
  fun sayHello(name: String) {
    if (name.startsWith("jim")) { logger.warn("Jim was here") }
    println("Hello $name")
  }

  companion object {
    val logger = LoggerFactory.getLogger(Greeter::class.java)
  }
}

test:

test("Warns when jim is here") {
   Greeter().sayHello("jim")
   logs.forOne {
     it.level shouldBe Level.WARN
   }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

SLF4J extensions
The log() method logs at level DEBUG using a marker named "PROFILER". If your logging system supports markers, e.g. logback, you could specifically...
Read more >
Support the lambda expression in the Logger - QOS.ch JIRA
I just went and tested this and sure enough...it does not work .(but I mean, it should be obvious since slf4j uses the...
Read more >
SLF4J Tutorial: Configuration Example for Logging in Java
Learn what is SLF4J and how to configure it using different Java logging libraries, from Log4j and Log4j2 to Logback and Jakarta Commons ......
Read more >
Loggers should be "private static final" and should share a ...
Noncompliant Code Example. With a default regular expression of LOG(?:GER)? : public Logger logger = LoggerFactory. · Compliant Solution. private static final ...
Read more >
SLF4J: 10 Reasons Why You Should Be Using It - Stackify
You can use Markers in 'special' events or log entries that you want to make them stand out from regular records. Even though...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found