In my project classes I've used java.util.logging.Logger
and added various log output's throughout my code, using various log levels ie.
src/main/java/Run.java
import java.util.logging.Level;
import java.util.logging.Logger;
public class Run{
public static void main( String args[] ){
System.out.println("Hello World");
logger.log(Level.CONFIG, "Just some config info");
Logger logger = Logger.getLogger(Run.class.getName());
logger.log(Level.INFO, "Just logging some info");
logger.log(Level.FINE, "Fine logging");
logger.log(Level.FINER, "Finer logging");
logger.log(Level.WARNING, "This is a warning log!");
}
}
Currently when I run gradle -i test
all log messages with the Level.INFO
defined are shown but none of the config, warn or fine messages are output.
I've tried updating my build.gradle file such that:
apply plugin: 'java'
apply plugin:'application'
mainClassName = "Run"
repositories {
mavenCentral()
}
dependencies {
testCompile "junit:junit:4.11"
}
run{
systemProperties = ['java.util.logging.config.file' : 'logging.properties']
}
I've included:
systemProperties = ['java.util.logging.config.file' : 'logging.properties']
Then created /src/main/resource/logging.propertiess
handlers= java.util.logging.ConsoleHandler
.level= CONFIG
java.util.logging.ConsoleHandler.level = FINER
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
Running:
gradle run
I get:
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:run
Hello World
BUILD SUCCESSFUL
And when running gradle -i run I get: Successfully started process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/bin/java'' Hello World :run (Thread[main,5,main]) completed. Took 0.202 secs.
BUILD SUCCESSFUL
ie. no logging information. However commenting out the system.properties from within the run task and re-running gradle -i run I get:
Successfully started process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/bin/java''
Hello World
Nov 05, 2014 12:07:42 PM Run main
INFO: Just logging some info
Nov 05, 2014 12:07:42 PM Run main
WARNING: This is a warning log!
:run (Thread[main,5,main]) completed. Took 0.229 secs.
BUILD SUCCESSFUL
The info and warning level logs, but not the fine or finer ones.
tldr;
How do I get the config, fine & finer level logs to log to the console in a generic gradle java project ?