Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Pyx4j framework Copyright (C) 2006-2007 pyx4.com. Created on Nov 8, 2004 by michaellif

Author(s):
michaellif
Version:
$Id: Logger.java 100 2007-04-21 01:14:17Z vlads $
  
 package com.pyx4j.log;
 
 
Wrapper for Log4j logger
 
 public class Logger {
 
     static {
         String containerHome = ".";
         if (StringUtils.isStringSet(System.getProperty("catalina.home"))) {
             containerHome = System.getProperty("catalina.home");
         } else if (StringUtils.isStringSet(System.getProperty("jetty.home"))) {
             containerHome = System.getProperty("jetty.home");
         }
         RollingFileAppender.setVariable("container.home"containerHome);
     }
     
     static boolean isshutdown = false;
    
    
The fully qualified name of the Log class.
 
     private static final String FQCN = Logger.class.getName();
     
     private static WeakHashMap<org.apache.log4j.LoggerLoggerinstances = new WeakHashMap<org.apache.log4j.LoggerLogger>();

    
Log to this logger
 
     private org.apache.log4j.Logger logger = null;
     
     private Logger(org.apache.log4j.Logger logger) {
         this. = logger;
     }
    
    
We are in java 1.4 lets save some typing.
 
     public static Logger getLogger() {
         String useName = null;
         StackTraceElement[] ste = new Throwable().getStackTrace();
         for (int i = 0; i < ste.lengthi++ ) {
             if (ste[i].getClassName().equals()) {
                 i ++;
                 useName = ste[i].getClassName();
                 break;
             }
         }
         if (useName == null) {
             throw new Error("Can't find call origin");
         }
         return getLogger(useName);    
     }

    
Return the native Logger instance we are using.
 
     public static Logger getLogger(String name) {
         org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(name);
         if (.containsKey(logger)) {
             return .get(logger);
         } else {
             Logger log = new Logger(logger);
             .put(loggerlog);
             return log;
         }
     }
 
     public static Logger getLog(Class clazz) {
         return getLogger(clazz.getName());
     }
    
    
Check whether the Log4j Logger used is enabled for DEBUG priority.
 
     public boolean isDebugEnabled() {
         return this..isDebugEnabled();
     }

    
Check whether the Log4j Logger used is enabled for ERROR priority.
    public boolean isErrorEnabled() {
        return this..isEnabledFor(.);
    }

    
Check whether the Log4j Logger used is enabled for FATAL priority.
    public boolean isFatalEnabled() {
        return this..isEnabledFor(.);
    }

    
Check whether the Log4j Logger used is enabled for INFO priority.
    public boolean isInfoEnabled() {
        return this..isInfoEnabled();
    }

    
Check whether the Log4j Logger used is enabled for TRACE priority. For Log4J, this returns the value of isDebugEnabled()
    public boolean isTraceEnabled() {
        return this..isDebugEnabled();
    }

    
Check whether the Log4j Logger used is enabled for WARN priority.
    public boolean isWarnEnabled() {
        return this..isEnabledFor(.);
    }
    public String getName() {
        return this..getName();
    }
    private static DecimalFormat ndcFormat = new DecimalFormat("0000");
    
    static {
    }
    
    public void log(String callerFQCNPriority levelObject messageThrowable t) {
        if () {
            return;
        }
        if (.) {
            Long start = (Long)MDC.get(.) ;
            if (start != null) {
                long duration = ((System.nanoTime() - start)/ 1000000);
                MDC.put(..format(duration));
            }
        }
        if (MDC.get(.) == null) {
            MDC.put(."");
        }
        this..log(callerFQCNlevelmessaget);
    }
    
    
Log an error to the Log4j Logger with TRACE priority. Currently logs to DEBUG level in Log4J.
    public void debug(String messageThrowable t) {
        if (isTraceEnabled()) {
            log(.messaget);
        }
    }

    
Overloaded trace method with embedded debug guard.
    public void debug(Object[] value) {
        if (isTraceEnabled()) {
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; i < value.lengthi++) {
                buffer.append(toString(value[i]));
            }
            log(.buffer.toString(), null);
        }
    }

    
Overloaded trace method with embedded debug guard.
    public void debug(String messagelong value) {
        if (isTraceEnabled()) {
            log(.message + "[" + value + "]"null);
        }
    }

    
Overloaded trace method with embedded debug guard.
    public void debug(String messagelong value1long value2) {
        if (isTraceEnabled()) {
            log(.message + "[" + value1 + ", " + value2 + "]"null);
        }
    }

    
Overloaded trace method with embedded debug guard.
    public void debug(String messagedouble value) {
        if (isTraceEnabled()) {
            log(.message + "[" + value + "]"null);
        }
    }

    
Overloaded trace method with embedded debug guard.
    public void debug(String messagedouble value1double value2) {
        if (isTraceEnabled()) {
            log(.message + "[" + value1 + ", " + value2 + "]"null);
        }
    }

    
Overloaded trace method with embedded debug guard.
    public void debug(String messageboolean value) {
        if (isTraceEnabled()) {
            log(.message + "[" + ValueFormat.valueOf(value) + "]"null);
        }
    }

    
Overloaded trace method with embedded debug guard.
    public void debug(String messageboolean value1boolean value2) {
        if (isTraceEnabled()) {
            log(.message + "[" + ValueFormat.valueOf(value1) + ", " + ValueFormat.valueOf(value2) + "]"null);
        }
    }

    
Overloaded trace method with embedded debug guard.
    public void debug(String messageObject[] value) {
        if (isTraceEnabled()) {
//            StringBuffer buffer = new StringBuffer();
//            buffer.append(message).append(" [");
//            for (int i = 0; i < value.length; i++) {
//                buffer.append(value[i].toString()).append(", ");
//            }
//            buffer.append("]");
            log(.message + ToStringBuilder.reflectionToString(value.), null);
        }
    }
    
    public static String toString(Object value) {
        return DeepToStringStyle.toString(value);
    }
    
    
Overloaded trace method with embedded debug guard.
    public void debug(String messageObject value) {
        if (isTraceEnabled()) {
            log(.message + "[" + toString(value) + "]"null);
        }
    }

    
Overloaded trace method with embedded debug guard.
    public void debug(String messageObject value1Object value2) {
        if (isTraceEnabled()) {
            log(.message + "[" + toString(value1) + ", " + toString(value2) + "]"null);
        }
    }

    
Overloaded trace method with embedded debug guard.
    public void debug(String message1Object value1String message2Object value2) {
        if (isTraceEnabled()) {
            log(.message1 + "[" + toString(value1) + "], " + message2 + " [" + value2 + "]"null);
        }
    }
    
Log a message to the Log4j Logger with DEBUG priority.
    public void debug(Object message) {
        log(.toString(message), null);
    }
    public void debugClassLoader(String messageObject obj) {
        if (obj == null) {
            log(.message + " no class, no object"null);
            return;
        }
        Class klass;
        StringBuffer buf = new StringBuffer();
        buf.append(message).append(" ");
        if (obj instanceof Class) {
            klass = (Classobj;
            buf.append("class ");
        } else {
            klass = obj.getClass();
            buf.append("instance ");
        }
        buf.append(klass.getName() + " loaded by ");
        if (klass.getClassLoader() != null) {
            buf.append(klass.getClassLoader().hashCode());
        } else {
            buf.append("system");
        }
        log(.buf.toString(), null);
    }
    
    
Log an error to the Log4j Logger with DEBUG priority.
    public void debug(Object messageThrowable t) {
        log(.toString(message), t);
        //logNestedException(Level.DEBUG, t);
    }

    
Log a message to the Log4j Logger with INFO priority.
    public void info(Object message) {
        log(.toString(message), null);
    }

    
Log an error to the Log4j Logger with INFO priority.
    public void info(Object messageThrowable t) {
        log(.toString(message), t);
        //logNestedException(Level.INFO, t);
    }

    
Log a message to the Log4j Logger with WARN priority.
    public void warn(Object message) {
        log(.toString(message), null);
    }

    
Log an error to the Log4j Logger with WARN priority.
    public void warn(Object messageThrowable t) {
        log(.toString(message), t);
        //logNestedException(Level.WARN, t);
    }

    
Log a message to the Log4j Logger with ERROR priority.
    public void error(Object message) {
        log(.toString(message), null);
    }

    
Log an error to the Log4j Logger with ERROR priority.
    public void error(Object messageThrowable t) {
        log(.toString(message), t);
        //logNestedException(Level.ERROR, t);
    }

    
Log a message to the Log4j Logger with FATAL priority.
    public void fatal(Object message) {
        log(.toString(message), null);
    }

    
Log an error to the Log4j Logger with FATAL priority.
    public void fatal(Object messageThrowable t) {
        log(.toString(message), t);
        //logNestedException(Level.FATAL, t);
    }
    
    
    public static void setContextName(String name) {
        RollingFileAppender.setContextName(name);
    }
    
    public static void shutdown() {
         = true;
        LogManager.shutdown();
    }
New to GrepCode? Check out our FAQ X