void forceLoggingViaChildLogger ( LogRecord record ) { // Assume that nobody else will configure or manipulate loggers with this "secret" name. Logger forcingLogger = getForcingLogger ( logger ) ; // This logger can be garbage collected at any time, so we must always reset any configuration. // This code is subject to a bunch of unlikely race conditions if the logger is manipulated // while these checks are being made, but there is nothing we can really do about this (the // setting of log levels is not protected by synchronizing the logger instance). try { forcingLogger . setLevel ( Level . ALL ) ; } catch ( SecurityException e ) { // If we're blocked from changing logging configuration then we cannot log "forced" log // statements via the forcingLogger. Fall back to publishing them directly to the handlers // (which may bypass logic present in an overridden log(LogRecord) method). cannotUseForcingLogger = true ; // Log to the root logger to bypass any configuration that might drop this message. Logger . getLogger ( "" ) . log ( Level . SEVERE , "Forcing log statements with Flogger has been partially disabled.\n" + "The Flogger library cannot modify logger log levels, which is necessary to force" + " log statements. This is likely due to an installed SecurityManager.\n" + "Forced log statements will still be published directly to log handlers, but will" + " not be visible to the 'log(LogRecord)' method of Logger sub-classes.\n" ) ; publish ( logger , record ) ; return ; } // Assume any custom behaviour in our logger instance also exists for a child logger. forcingLogger . log ( record ) ; }
subclasses of Logger to be used .