Git Product home page Git Product logo

Comments (18)

AlexCzar avatar AlexCzar commented on May 15, 2024 2

I tried adding test-logback.xml (and logback-test.xml) with following content:

<configuration>
	<root level="warn"/>
</configuration>

This doesn't seem to affect logging in any way, my log is still full of [Test worker] DEBUG io.mockk.impl... lines.
How do I disable this?

from mockk.

laxa88 avatar laxa88 commented on May 15, 2024 2

For those curious:

Mockk uses Logback.

You need to add an logback-test.xml or logback.xml file in the resource folder. Any other filename won't be recognised.
Screen Shot 2022-03-01 at 11 33 24

Then, in the xml, add something like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%msg%n</pattern>
        </encoder>
    </appender>
    <root level="debug">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

Notes:

  • Set debug="false" if you want to turn off logging completely.
  • Change the value to level="info" or "warn" as you see fit.
  • You need to define an <appender> first, then use it in the <appender-ref>.
  • You need to define the message pattern in <pattern>
  • Note the the ref can be any arbitrary value instead of STDOUT.

Some links for reference:

from mockk.

tomkoptel avatar tomkoptel commented on May 15, 2024

👍 +1 I am looking for the same option. What about?

val dependency = mockk<Dependency>(logging = false)

from mockk.

oleksiyp avatar oleksiyp commented on May 15, 2024

from mockk.

tomkoptel avatar tomkoptel commented on May 15, 2024

What do you propose? To disable info and debug logging? I don't think it is a good idea to remove logs. I would still prefer to see the option to enable/disable logs.

from mockk.

oleksiyp avatar oleksiyp commented on May 15, 2024

I propose to not have info logs, so by default nothing is shown. There is just one info message saying what is an answer. On the other hand you always can disable/show logging in logback.xml(any other SLF4J framework) anyway. Doing it per mock is not an option because it would need to revisit each logging message and somehow link it to this flag.

from mockk.

tomkoptel avatar tomkoptel commented on May 15, 2024

It sounds like it is required to have SLF4J on the classpath and then to include logback.xml in the resources folder. Is it correct?

from mockk.

oleksiyp avatar oleksiyp commented on May 15, 2024

Yes, logback-test.xml even better

from mockk.

excitement-engineer avatar excitement-engineer commented on May 15, 2024

I like the idea of not showing any logs by default. Frameworks like mockito also don't do this for example. I think that the logs are only useful when debugging the code so being able to easily turn this on/off would be a win I think.

from mockk.

oleksiyp avatar oleksiyp commented on May 15, 2024

The idea was to keep one top-level info message. It can help to see what has answered actually in your tests by mocking library. But I think this easily can be switched to DEBUG

from mockk.

tomkoptel avatar tomkoptel commented on May 15, 2024

Me personally not against the logging it was a good idea, but when you put additional logs in the source code to see sequence call with your tests it becomes a little bit noisy from the mock instances. I would still prefer to have logs, but with an option to disable them on demand. To use SLF4J sounds like a solution, but it requires to add yet another lib just for the sake of disabling logs, which sounds like an overkill.

from mockk.

oleksiyp avatar oleksiyp commented on May 15, 2024

Version 1.7.10 released, please check if by default has no logging and close the ticket.

from mockk.

excitement-engineer avatar excitement-engineer commented on May 15, 2024

Awesome thanks so much, it works:) Really appreciate it!

from mockk.

charlesritchea avatar charlesritchea commented on May 15, 2024

@oleksiyp I'm confused by this. I don't want mockk logging and I use slf4j myself, but my logback is handled by dropwizard, so I don't have a logback.xml or test-logback.xml. Do I still need to create and configure a test-logback.xml to disable logging. It makes finding build failures in gradle output frustrating because there are all these mock DEBUG statements I have to wade through

from mockk.

oleksiyp avatar oleksiyp commented on May 15, 2024

Unfortunately, DEBUG is what MockK cannot live without. I usually request to turn on DEBUG logging to capture what is happening on the other side. It is pretty weird that it is turned on by default for tests with Dropwizard. So you need to configure test-logback.xml to fix it.

I can think of a switch in MockK properties, but you will still need to create some file with settings, so that is almost the same as creation of test-logback.xml

from mockk.

charlesritchea avatar charlesritchea commented on May 15, 2024

from mockk.

erksch avatar erksch commented on May 15, 2024

After multiple hours I am still unable to turn off the DEBUG logs of mockk in my multiplatform project.

I enabled standard streams for my test logging:

testLogging {
  showStandardStreams = true
}

I tried to add the logback.xml or logback-test.xml to shared/src/commonTest/resources/.
I also tried to only enable standard streams for INFO log level only:

testLogging {
  info { 
    showStandardStreams = true
  }
}

But nothing seems to work. I want logging for all my INFO level logs but not the DEBUG level logs from mockk.
Has anyone found a solution, or could explain how to verify that the logback setup works?

from mockk.

erksch avatar erksch commented on May 15, 2024

I got it to work in my multiplatform project where I have tests in commonTest.
The trick was to not add logback.xml to shared/src/commonTest/resources/ but to shared/src/test/resources/!

from mockk.

Related Issues (20)

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.