java - Handle all exceptions -
i used logback
logging java application. how can handle exceptions in app logback
my test config
<appender name="exceptions" class="ch.qos.logback.core.fileappender"> <filter class="ch.qos.logback.core.filter.evaluatorfilter"> <evaluator> <expression>java.lang.exception.class.isinstance(throwable)</expression> </evaluator> <onmatch>accept</onmatch> </filter> <file>exceptions.log</file> <append>true</append> <encoder> <pattern>%d{hh:mm:ss.sss} %-5level %logger{36} - %msg%n</pattern> <immediateflush>false</immediateflush> </encoder> </appender>
assuming mean catching exceptions, not caught: can define uncaught exceptions handler in code, possible:
private static void setdefaultuncaughtexceptionhandler() { try { thread.setdefaultuncaughtexceptionhandler(new thread.uncaughtexceptionhandler() { @override public void uncaughtexception(thread t, throwable e) { logger.error("uncaught exception detected in thread " + t, e); } }); } catch (securityexception e) { logger.error("could not set default uncaught exception handler", e); } }
Comments
Post a Comment