FileDocCategorySizeDatePackage
DirectJDKLog.javaAPI DocApache Tomcat 6.0.146275Fri Jul 20 04:20:36 BST 2007org.apache.juli.logging

DirectJDKLog

public class DirectJDKLog extends Object implements Log
Hardcoded java.util.logging commons-logging implementation. In addition, it curr

Fields Summary
public Logger
logger
private static final String
SIMPLE_FMT
Alternate config reader and console format
private static final String
SIMPLE_CFG
Constructors Summary
public DirectJDKLog(String name)


     
        if( System.getProperty("java.util.logging.config.class") ==null  &&
                System.getProperty("java.util.logging.config.file") ==null ) {
            // default configuration - it sucks. Let's override at least the 
            // formatter for the console
            try {
                Class.forName(SIMPLE_CFG).newInstance();                
            } catch( Throwable t ) {                
            }
            try {
                Formatter fmt=(Formatter)Class.forName(SIMPLE_FMT).newInstance();
                // it is also possible that the user modifed jre/lib/logging.properties - 
                // but that's really stupid in most cases
                Logger root=Logger.getLogger("");
                Handler handlers[]=root.getHandlers();
                for( int i=0; i< handlers.length; i++ ) {
                    // I only care about console - that's what's used in default config anyway
                    if( handlers[i] instanceof  ConsoleHandler ) {
                        handlers[i].setFormatter(fmt);
                    }
                }
            } catch( Throwable t ) {
                // maybe it wasn't included - the ugly default will be used.
            }
            
        }
    
        logger=Logger.getLogger(name);        
    
Methods Summary
public final voiddebug(java.lang.Object message)

        log(Level.FINE, String.valueOf(message), null);
    
public final voiddebug(java.lang.Object message, java.lang.Throwable t)

        log(Level.FINE, String.valueOf(message), t);
    
public final voiderror(java.lang.Object message)

        log(Level.SEVERE, String.valueOf(message), null);
    
public final voiderror(java.lang.Object message, java.lang.Throwable t)

        log(Level.SEVERE, String.valueOf(message), t);
    
public final voidfatal(java.lang.Object message)

        log(Level.SEVERE, String.valueOf(message), null);
    
public final voidfatal(java.lang.Object message, java.lang.Throwable t)

        log(Level.SEVERE, String.valueOf(message), t);
    
static LoggetInstance(java.lang.String name)

        return new DirectJDKLog( name );
    
public final voidinfo(java.lang.Object message)

        log(Level.INFO, String.valueOf(message), null);
    
public final voidinfo(java.lang.Object message, java.lang.Throwable t)

        
        log(Level.INFO, String.valueOf(message), t);
    
public final booleanisDebugEnabled()

        return logger.isLoggable(Level.FINE);
    
public final booleanisErrorEnabled()

        return logger.isLoggable(Level.SEVERE);
    
public final booleanisFatalEnabled()

        return logger.isLoggable(Level.SEVERE);
    
public final booleanisInfoEnabled()

        return logger.isLoggable(Level.INFO);
    
public final booleanisTraceEnabled()

        return logger.isLoggable(Level.FINER);
    
public final booleanisWarnEnabled()

        return logger.isLoggable(Level.WARNING); 
    
private voidlog(java.util.logging.Level level, java.lang.String msg, java.lang.Throwable ex)

        if (logger.isLoggable(level)) {
            // Hack (?) to get the stack trace.
            Throwable dummyException=new Throwable();
            StackTraceElement locations[]=dummyException.getStackTrace();
            // Caller will be the third element
            String cname="unknown";
            String method="unknown";
            if( locations!=null && locations.length >2 ) {
                StackTraceElement caller=locations[2];
                cname=caller.getClassName();
                method=caller.getMethodName();
            }
            if( ex==null ) {
                logger.logp( level, cname, method, msg );
            } else {
                logger.logp( level, cname, method, msg, ex );
            }
        }
    
static voidrelease()

        
    
public final voidtrace(java.lang.Object message)

        log(Level.FINER, String.valueOf(message), null);
    
public final voidtrace(java.lang.Object message, java.lang.Throwable t)

        log(Level.FINER, String.valueOf(message), t);
    
public final voidwarn(java.lang.Object message)

        log(Level.WARNING, String.valueOf(message), null);
    
public final voidwarn(java.lang.Object message, java.lang.Throwable t)

        log(Level.WARNING, String.valueOf(message), t);