orarily disables logging. try { ClassInitializer.initializeAll(); // Initializes bootstrap, extensions and classpath classes. } finally { LogContext.exit(LogContext.NULL); // Goes back to default logging. } ... }[/code]
Applications may extend this base class to address specific logging requirements. For example:[code] // This class allows for custom logging of session events. public abstract class SessionLog extends LogContext { public static void start(Session session) { LogContext log = LogContext.current(); if (log instanceof SessionLog.Loggable) { ((SessionLog.Loggable)log).logStart(session); } else if (log.infoLogged()){ log.logInfo("Session " + session.id() + " started"); } } public static void end(Session session) { ... } public interface Loggable { void logStart(Session session); void logEnd(Session session); } }[/code]
The use of interfaces (such as Loggable
above) makes it easy for any context to support customs logging events. For example:[code] class MyLog extends StandardLog implements SessionLog.Loggable, DatabaseLog.Loggable { ... // Specialized logging for session and database events. } MyLog myLog = new MyLog(); LogContext.enter(myLog); try { ... LogContext.info("Informative message"); // Standard logging. ... DatabaseLog.fail(transaction); // Database custom logging. ... SessionLog.start(session); // Session custom logging. ... } finally { LogContext.exit(myLog); }[/code]
@author
Jean-Marie Dautelle
@version 5.3, March 5, 2009