No (slf4j) log messages from executed java class


(tulsoba) #1

In my build script I execute a java class:

task myTask << {
        // No effect
  // logging.captureStandardOutput LogLevel.INFO
 javaexec {
  classpath = sourceSets.main.runtimeClasspath
  main = 'com.samples.MyClass'
  jvmArgs = ['-XX:MaxPermSize=128m']
 }
}

And the class:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
  public class MyClass {
 private final static Logger log = LoggerFactory.getLogger(MyClass.class);
   public static void main(String[] args) throws IOException {
      log.error("Print this error");
  log.info("Print this info");
  log.warn("Print this warn");
  System.out.println("test");
 }

But only the sysout message is printed in the console when I run the build file:

gradle clean install myTask

How do I enable slf4j output when running a java class from gradle?