Enabling AWS SDK logging to custom logfile via java logging framework -
i trying enable amazon web services sdk logging using java.util.logging framework instead of log4j. have managed working , logs go file specified java.util.logging.filehandler.pattern in properties file.
my log.properties file
org.apache.commons.logging.log=org.apache.commons.logging.impl.jdk14logger handlers=java.util.logging.filehandler com.amazonaws.request.level=fine java.util.logging.filehandler.formatter=java.util.logging.simpleformatter java.util.logging.filehandler.pattern=./javalog.log
what looking way set file name @ runtime.
i tried following options
option 1: in properties file: set following java.util.logging.filehandler.pattern=${mylogfile}
and in main() function of java program, call system.setproperty("mylogfile", logname);
option 2: delete line "java.util.logging.filehandler.pattern" properties file.
instead, call system.setproperty("java.util.logging.filehandler.pattern", logname);
both these options not work.
ps: in case of log4j, option 1 works fine.
any idea how can customize log file sdk logging dynamically ?
thanks vijay
the logmanager supports arbitrary configuration code. per documentation:
a property "config". property intended allow arbitrary configuration code run. property defines whitespace or comma separated list of class names. new instance created each named class. default constructor of each class may execute arbitrary code update logging configuration, such setting logger levels, adding handlers, adding filters, etc.
for example can compile following:
package somepackage; public class config { public config() throws exception { string pattern = system.getproperty("mylogfile", "javalog.log"); filehandler f = new filehandler(pattern); logger.getlogger("").addhandler(f); } }
then install using following config file:
config=somepackage.config com.amazonaws.request.level=fine
you can create subclass or proxy handler control how , when log file name generated @ runtime.
Comments
Post a Comment