0


I built an app and build it with the gradle.
But I can't understand how to test in gradle in debug mode.

I enter:

gradle test -d > test.log

but I get only debug messages about building, not messages log.debug() from test.

log.info() messages I can see in builded test result's "Standart error" tab. But how can I see [DEBUG] messages?

wazz
  • 760
  • 2
  • 8
  • 19
  • you need to set the level of root Logger to DEBUG instead of INFO !! which logging framework are you using , if log4j then you need to set this in `log4j.properties file` – Neeraj Jain Mar 18 '15 at 13:06
  • What kind of "app"? What are you using to log? – Jared Burrows Mar 18 '15 at 13:12
  • @JaredBurrows I'm using sfl4j library.
    It's simple java application.
    – wazz Mar 18 '15 at 13:27
  • @Neeraj could you answer me how can I edit this file. Because I only have build.gradle with `dependencies { compile 'org.slf4j:slf4j-api:1.7.10' compile 'org.slf4j:slf4j-jdk14:1.7.8'}` – wazz Mar 18 '15 at 13:30
  • 1
    So now your question becomes [how-to-enable-debug-in-slf4j-logger](http://stackoverflow.com/questions/10847458/how-to-enable-debug-in-slf4j-logger) – Neeraj Jain Mar 18 '15 at 13:36
  • @NeerajJain I'm not asking how programmatically do it using setLevel. I'm asking about how can I say to gradle run java app with debug level. So I would see debug messages in reports without changing code – wazz Mar 18 '15 at 13:39
  • @DavidLevesque I use org.slf4j:slf4j-jdk14:1.7.8
      
    in code:  
    `private static final Logger log = LoggerFactory.getLogger(SearchEngineService.class);`  
    `public void testSomething() {`  
    `log.debug("hello");`
    – wazz Mar 18 '15 at 14:10
  • @DavidLevesque I have `dependencies { compile 'org.slf4j:slf4j-api:1.7.10' compile 'org.slf4j:slf4j-jdk14:1.7.8'}` so I'm using java.util.logging – wazz Mar 18 '15 at 14:49
  • @wazz given your dependencies (org.slf4j), you're NOT using java.util.logging – roomsg Mar 18 '15 at 22:00
  • 1
    @roomsg That's also what I thought first, but after verification `slf4j-jdk14` is actually the binding to use`java.util.logging`. See: http://www.slf4j.org/manual.html – David Levesque Mar 18 '15 at 22:10
  • @DavidLevesque Hmm, I didn't know the slf4j-jdk14, till today ;-) Thx for clarifying, taking back my previous comment... – roomsg Mar 18 '15 at 22:19

2 Answers2

1
  1. slf4j is only an api, you need as well an implementation
  2. Suggest to use logback-classic as implementation, by adding it in your gradle build file as a testRuntime dependency. Ref: http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html

That should do the trick. If you need more control, you can tweak logback by providing a logback(-test).xml. Ref: http://logback.qos.ch/manual/configuration.html

roomsg
  • 1,811
  • 16
  • 22
-1

If you don't want to set the log level programmatically, you can setup a configuration file for java.util.logging. You can find detailed instructions here.

See the property "logger".level. Set it to FINEST to log everything.

David Levesque
  • 22,181
  • 8
  • 67
  • 82