Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd.
  //  ------------------------------------------------------------------------
  //  All rights reserved. This program and the accompanying materials
  //  are made available under the terms of the Eclipse Public License v1.0
  //  and Apache License v2.0 which accompanies this distribution.
  //
  //      The Eclipse Public License is available at
 //      http://www.eclipse.org/legal/epl-v10.html
 //
 //      The Apache License v2.0 is available at
 //      http://www.opensource.org/licenses/apache2.0.php
 //
 //  You may elect to redistribute this code under either of these licenses.
 //  ========================================================================
 //
 
 package org.eclipse.jetty.util.log;
 
 import java.net.URL;
 import java.util.Map;
 
Logging. This class provides a static logging interface. If an instance of the org.slf4j.Logger class is found on the classpath, the static log methods are directed to a slf4j logger for "org.eclipse.log". Otherwise the logs are directed to stderr.

The "org.eclipse.jetty.util.log.class" system property can be used to select a specific logging implementation.

If the system property org.eclipse.jetty.util.log.IGNORED is set, then ignored exceptions are logged in detail.

 
 public class Log
 {
     public final static String EXCEPTION"EXCEPTION ";
     public final static String IGNORED"IGNORED ";

    
Logging Configuration Properties
 
     protected static Properties __props;
    
The Logger implementation class name
 
     public static String __logClass;
    
Legacy flag indicating if ignore(java.lang.Throwable) methods produce any output in the Loggers
 
     public static boolean __ignored;

    
Hold loggers only.
 
     private final static ConcurrentMap<StringLogger__loggers = new ConcurrentHashMap<StringLogger>();
 
 
     static
     {
         /* Instantiate a default configuration properties (empty)
          */
          = new Properties();
 
         AccessController.doPrivileged(new PrivilegedAction<Object>()
         {
             public Object run()
             {
                 /* First see if the jetty-logging.properties object exists in the classpath.
                  * This is an optional feature used by embedded mode use, and test cases to allow for early
                  * configuration of the Log class in situations where access to the System.properties are
                  * either too late or just impossible.
                  */
                 URL testProps = Log.class.getClassLoader().getResource("jetty-logging.properties");
                 if (testProps != null)
                 {
                     InputStream in = null;
                     try
                     {
                        in = testProps.openStream();
                        .load(in);
                    }
                    catch (IOException e)
                    {
                        ..println("Unable to load " + testProps);
                        e.printStackTrace(.);
                    }
                    finally
                    {
                        IO.close(in);
                    }
                }
                /* Now load the System.properties as-is into the __props, these values will override
                 * any key conflicts in __props.
                 */
                @SuppressWarnings("unchecked")
                Enumeration<StringsystemKeyEnum = (Enumeration<String>)System.getProperties().propertyNames();
                while (systemKeyEnum.hasMoreElements())
                {
                    String key = systemKeyEnum.nextElement();
                    String val = System.getProperty(key);
                    //protect against application code insertion of non-String values (returned as null)
                    if (val != null)
                        .setProperty(key,val);
                }
                /* Now use the configuration properties to configure the Log statics
                 */
                 = .getProperty("org.eclipse.jetty.util.log.class","org.eclipse.jetty.util.log.Slf4jLog");
                 = Boolean.parseBoolean(.getProperty("org.eclipse.jetty.util.log.IGNORED","false"));
                return null;
            }
        });
    }
    private static Logger LOG;
    private static boolean __initialized;
    public static boolean initialized()
    {
        if ( != null)
        {
            return true;
        }
        synchronized (Log.class)
        {
            if ()
            {
                return  != null;
            }
             = true;
        }
        try
        {
            Class<?> log_class = Loader.loadClass(Log.class);
            if ( == null || !.getClass().equals(log_class))
            {
                 = (Logger)log_class.newInstance();
                .debug("Logging to {} via {}"log_class.getName());
            }
        }
        catch(Throwable e)
        {
            // Unable to load specified Logger implementation, default to standard logging.
            initStandardLogging(e);
        }
        return  != null;
    }
    private static void initStandardLogging(Throwable e)
    {
        Class<?> log_class;
        if(e != null && )
        {
            e.printStackTrace();
        }
        if ( == null)
        {
            log_class = StdErrLog.class;
             = new StdErrLog();
            .debug("Logging to {} via {}"log_class.getName());
        }
    }
    public static void setLog(Logger log)
    {
        . = log;
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static Logger getLog()
    {
        initialized();
        return ;
    }

    
Get the root logger.

Returns:
the root logger
    public static Logger getRootLogger() {
        initialized();
        return ;
    }
    static boolean isIgnored()
    {
        return ;
    }

    
Set Log to parent Logger.

If there is a different Log class available from a parent classloader, call getLogger(java.lang.String) on it and construct a LoggerLog instance as this Log's Logger, so that logging is delegated to the parent Log.

This should be used if a webapp is using Log, but wishes the logging to be directed to the containers log.

If there is not parent Log, then this call is equivalent to

   Log.setLog(Log.getLogger(name));
 

Parameters:
name Logger name
    public static void setLogToParent(String name)
    {
        ClassLoader loader = Log.class.getClassLoader();
        if (loader.getParent()!=null)
        {
            try
            {
                Class<?> uberlog = loader.getParent().loadClass("org.eclipse.jetty.util.log.Log");
                Method getLogger = uberlog.getMethod("getLogger"new Class[]{String.class});
                Object logger = getLogger.invoke(null,name);
                setLog(new LoggerLog(logger));
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
        else
        {
            setLog(getLogger(name));
        }
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void debug(Throwable th)
    {
        if (!isDebugEnabled())
            return;
        .debug(th);
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void debug(String msg)
    {
        if (!initialized())
            return;
        .debug(msg);
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void debug(String msgObject arg)
    {
        if (!initialized())
            return;
        .debug(msgarg);
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void debug(String msgObject arg0Object arg1)
    {
        if (!initialized())
            return;
        .debug(msgarg0arg1);
    }

    
Ignore an exception unless trace is enabled. This works around the problem that log4j does not support the trace level.

Parameters:
thrown the Throwable to ignore

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void ignore(Throwable thrown)
    {
        if (!initialized())
            return;
        .ignore(thrown);
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void info(String msg)
    {
        if (!initialized())
            return;
        .info(msg);
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void info(String msgObject arg)
    {
        if (!initialized())
            return;
        .info(msgarg);
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void info(String msgObject arg0Object arg1)
    {
        if (!initialized())
            return;
        .info(msgarg0arg1);
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static boolean isDebugEnabled()
    {
        if (!initialized())
            return false;
        return .isDebugEnabled();
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void warn(String msg)
    {
        if (!initialized())
            return;
        .warn(msg);
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void warn(String msgObject arg)
    {
        if (!initialized())
            return;
        .warn(msgarg);
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void warn(String msgObject arg0Object arg1)
    {
        if (!initialized())
            return;
        .warn(msgarg0arg1);
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void warn(String msgThrowable th)
    {
        if (!initialized())
            return;
        .warn(msgth);
    }

    

Deprecated:
anonymous logging is deprecated, use a named Logger obtained from getLogger(java.lang.String)
    @Deprecated
    public static void warn(Throwable th)
    {
        if (!initialized())
            return;
        .warn(th);
    }

    
Obtain a named Logger based on the fully qualified class name.

Parameters:
clazz the class to base the Logger name off of
Returns:
the Logger with the given name
    public static Logger getLogger(Class<?> clazz)
    {
        return getLogger(clazz.getName());
    }

    
Obtain a named Logger or the default Logger if null is passed.

Parameters:
name the Logger name
Returns:
the Logger with the given name
    public static Logger getLogger(String name)
    {
        if (!initialized())
            return null;
        if(name==null)
            return ;
        Logger logger = .get(name);
        if(logger==null)
            logger = .getLogger(name);
        return logger;
    }
    {
        return ;
    }
    
    
Get a map of all configured Logger instances.

Returns:
a map of all configured Logger instances
    public static Map<StringLoggergetLoggers()
    {
        return Collections.unmodifiableMap();
    }
New to GrepCode? Check out our FAQ X