i'm using log4j (via slf4j) configured log4j.xml. know how can disable messages log4j displays itself. example, if log file specified in log4j.xml can't created, log4j shows following messages on console:
log4j:error setfile(null,true) call failed. java.io.filenotfoundexception: \logfile.log (accesso negato) @ java.io.fileoutputstream.open(native method) @ java.io.fileoutputstream.<init>(fileoutputstream.java:212) @ java.io.fileoutputstream.<init>(fileoutputstream.java:136) @ org.apache.log4j.fileappender.setfile(fileappender.java:294) @ org.apache.log4j.rollingfileappender.setfile(rollingfileappender.java:207) @ org.apache.log4j.fileappender.activateoptions(fileappender.java:165) @ org.apache.log4j.config.propertysetter.activate(propertysetter.java:307) @ org.apache.log4j.xml.domconfigurator.parseappender(domconfigurator.java:295) @ org.apache.log4j.xml.domconfigurator.findappenderbyname(domconfigurator.java:176) @ org.apache.log4j.xml.domconfigurator.findappenderbyreference(domconfigurator.java:191) @ org.apache.log4j.xml.domconfigurator.parsechildrenofloggerelement(domconfigurator.java:523) @ org.apache.log4j.xml.domconfigurator.parseroot(domconfigurator.java:492) @ org.apache.log4j.xml.domconfigurator.parse(domconfigurator.java:1006) @ org.apache.log4j.xml.domconfigurator.doconfigure(domconfigurator.java:872) @ org.apache.log4j.xml.domconfigurator.doconfigure(domconfigurator.java:778) @ org.apache.log4j.helpers.optionconverter.selectandconfigure(optionconverter.java:526) @ org.apache.log4j.logmanager.<clinit>(logmanager.java:127) @ org.slf4j.impl.log4jloggerfactory.getlogger(log4jloggerfactory.java:66) @ org.slf4j.loggerfactory.getlogger(loggerfactory.java:270) @ org.slf4j.loggerfactory.getlogger(loggerfactory.java:281)
i don't want users see full exception stack. in advance
a solution writing com.myapp.silenterrorhandler
implements org.apache.log4j.spi.errorhandler
nothing.
configuration in log4j.xml
:
<appender name="file" class="org.apache.log4j.rollingfileappender"> <errorhandler class="com.myapp.silenterrorhandler" /> <param name="file" value="\logfile.log"/> <layout class="org.apache.log4j.patternlayout"> ... </layout> </appender>
note silently ignoring errors bad thing. may consider using fallbackerrorhandler
allows specify fallback appender if primary appender fails.
Comments
Post a Comment