eclipse - Where does the java.util.logging log file or output go? -
update i've made mistake overlooked throughout. logging.properties
file had trailing space in filename not aware of. i've no clue how got in there, once deleted space worked. problem was providing wrong name i.e. filename without trailing space.
i don’t understand how java.util.logging
works. i’m trying replicate sample code provided at: java practices -> logging messages
i first created empty java project in eclipse. created class simplelogger.java
in package myapp.business
. under resources
, put logging.properties
. don’t have compilation problems , can step through code, cannot figure out output go?
simplelogger.java
looks like:
package myapp.business; import java.util.logging.level; import java.util.logging.logger; public final class simplelogger { public static void main(string... args) { simplelogger thing = new simplelogger(); thing.dosomething(); } public void dosomething() { // log messages, 1 each level // actual logging output depends on configured // level package. calls "inapplicable" // messages inexpensive. flogger.finest("this finest"); flogger.finer("this finer"); flogger.fine("this fine"); flogger.config("this config"); flogger.info("this info"); flogger.warning("this warning"); flogger.severe("this severe"); // in above style, name of class , // method has generated message placed // in output on best-efforts basis only. // ensure information // included, use following "precise log" // style instead : flogger.logp(level.info, this.getclass().tostring(), "dosomething", "blah"); // common task of logging exceptions, there // method takes throwable : throwable ex = new illegalargumentexception("some exception text"); flogger.log(level.severe, "some message", ex); // there convenience methods exiting , // entering method, @ level.finer : flogger.exiting(this.getclass().tostring(), "dosomething"); // display user.home directory, if desired. // (this directory log files generated.) // system.out.println("user.home dir: " + // system.getproperty("user.home") ); } // private // style has no hard-coded literals, , requires logger // non-static. private final logger flogger = logger.getlogger(this.getclass().getpackage().getname()); // style lets logger static, hard-codes class literal. // private static final logger flogger = // logger.getlogger(simplelogger.class.getpackage().getname()) // ; // style uses hard-coded literal , should avoided: // private static final logger flogger = logger.getlogger("myapp.business"); }
my logging.properties
in resources
directory looks like:
# properties file configures operation of jdk # logging facility. # system config file, first using # system property specified @ startup: # # >java -djava.util.logging.config.file=myloggingconfigfilepath # # if property not specified, config file # retrieved default location at: # # jdk_home/jre/lib/logging.properties # global logging properties. # ------------------------------------------ # set of handlers loaded upon startup. # comma-separated list of class names. # (? logmanager docs no comma here, jdk example has comma.) handlers=java.util.logging.filehandler, java.util.logging.consolehandler # default global logging level. # loggers , handlers may override level .level=info # loggers # ------------------------------------------ # loggers attached packages. # here, level each package specified. # global level used default, levels # specified here act override. myapp.ui.level=all myapp.business.level=config myapp.data.level=severe # handlers # ----------------------------------------- # --- consolehandler --- # override of global logging level java.util.logging.consolehandler.level=severe java.util.logging.consolehandler.formatter=java.util.logging.simpleformatter # --- filehandler --- # override of global logging level java.util.logging.filehandler.level=all # naming style output file: # (the output file placed in directory # defined "user.home" system property.) java.util.logging.filehandler.pattern=%h/java%u.log # limiting size of output file in bytes: java.util.logging.filehandler.limit=50000 # number of output files cycle through, appending # integer base file name: java.util.logging.filehandler.count=1 # style of output (simple or xml): java.util.logging.filehandler.formatter=java.util.logging.simpleformatter
in run configuration in eclipse, have main class myapp.business.simplelogger
, vm arguments -djava.util.logging.config.file=resources/logging.properties
i don't see on console nor can locate *.log file. i'm running on ubuntu 16.10 if helps.
edit: in response pvg i've attempted change vm argument in eclipse to: -djava.util.logging.config.file=/home/myusername/eclipseworkspace/temp/resources/logging.properties
i've tried call via command line in bin
directory:
java -djava.util.logging.config.file=/home/myusername/eclipseworkspace/temp/resources/logging.properties -cp . myapp.business.simplelogger
this not work i.e. don't see output, nor see *.log file anywhere.
for me, works if put whole path in eclipse vm arguments:
-djava.util.logging.config.file=/whole/path/of/logging.properties
then, output file created according what's configured in logging.properties
file. in case:
# naming style output file: # (the output file placed in directory # defined "user.home" system property.) java.util.logging.filehandler.pattern=%h/java%u.log
the output file created in user's home directory. in case, filename created java0.log
- %u
means "unique number resolve conflicts" (a.k.a. auto-generated number avoid having files same name; in case, 0
).
Comments
Post a Comment