Could you suggest me a pattern to log exceptions during java application lifecycle? -
i want use simple java.util.logging.* package log exceptions. suggestions, links, articles in basic elegant way? should implement in java ee application.
i thinking singleton class... think?
the following doesn't handle case of logging exceptions automatically might closer. @ current company extended exception companyexception supported list of callbacks. like:
public abstract class companyexception extends exception { private static final list<exceptioncallback> callbacks = new arraylist<exceptioncallback>(); public companyexception(string message) { super(message); invokecallbacks(); } // register class called whenever exception constructed public static void registercallback(exceptioncallback callback) { // expect registers done long before first exception thrown list<exceptioncallback> newcallbacks = new arraylist<exceptioncallback>(); newcallbacks.addall(callbacks); newcallbacks.add(callback); callbacks = newcallbacks; } private void invokecallbacks() { (exceptioncallback callback : callbacks) { try { callback.exceptionconstructed(this); } catch (throwable th) { // ignore because can't go recursive } } } } the callback simple interface:
public interface exceptioncallback { public void exceptionconstructed(exception exception); } then of our internal exceptions throw these or rethrow/wrap external exceptions. register logging class log exceptions using log4j or our internal logging mechanisms. exception logging wanted separation. our logger had dedicated thread in background , send central logging server. need very careful recursion if throw while logging.
Comments
Post a Comment