Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //
  //  ========================================================================
  //  Copyright (c) 1995-2013 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;
 

Implementation of Jetty Logger based on java.util.logging.Logger.

You can also set the logger level using standard java.util.logging configuration.

 
 public class JavaUtilLog extends AbstractLogger
 {
     private Level configuredLevel;
     private java.util.logging.Logger _logger;
 
     public JavaUtilLog()
     {
         this("org.eclipse.jetty.util.log");
     }
 
     public JavaUtilLog(String name)
     {
          = java.util.logging.Logger.getLogger(name);
         if (Boolean.parseBoolean(..getProperty("org.eclipse.jetty.util.log.DEBUG""false")))
         {
             .setLevel(.);
         }
          = .getLevel();
     }
 
     public String getName()
     {
         return .getName();
     }
 
     public void warn(String msgObject... args)
     {
         .log(.format(msgargs));
     }
 
     public void warn(Throwable thrown)
     {
         warn(""thrown);
     }
 
     public void warn(String msgThrowable thrown)
     {
         .log(.msgthrown);
     }
 
     public void info(String msgObject... args)
     {
         .log(.format(msgargs));
     }
 
     public void info(Throwable thrown)
     {
         info(""thrown);
     }
 
     public void info(String msgThrowable thrown)
     {
         .log(.msgthrown);
     }
 
     public boolean isDebugEnabled()
     {
         return .isLoggable(.);
     }
 
     public void setDebugEnabled(boolean enabled)
     {
         if (enabled)
         {
              = .getLevel();
             .setLevel(.);
         }
        else
        {
            .setLevel();
        }
    }
    public void debug(String msgObject... args)
    {
        .log(.format(msgargs));
    }
    public void debug(Throwable thrown)
    {
        debug(""thrown);
    }
    public void debug(String msgThrowable thrown)
    {
        .log(.msgthrown);
    }

    
Create a Child Logger of this Logger.
    protected Logger newLogger(String fullname)
    {
        return new JavaUtilLog(fullname);
    }
    public void ignore(Throwable ignored)
    {
        if (Log.isIgnored())
        {
            warn(.ignored);
        }
    }
    private String format(String msgObject... args)
    {
        msg = String.valueOf(msg); // Avoids NPE
        String braces = "{}";
        StringBuilder builder = new StringBuilder();
        int start = 0;
        for (Object arg : args)
        {
            int bracesIndex = msg.indexOf(bracesstart);
            if (bracesIndex < 0)
            {
                builder.append(msg.substring(start));
                builder.append(" ");
                builder.append(arg);
                start = msg.length();
            }
            else
            {
                builder.append(msg.substring(startbracesIndex));
                builder.append(String.valueOf(arg));
                start = bracesIndex + braces.length();
            }
        }
        builder.append(msg.substring(start));
        return builder.toString();
    }
New to GrepCode? Check out our FAQ X