Skip to content

Commit

Permalink
Fixes 310603 (Make Logger interface consistent).
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1570 7e9141cc-0065-0410-87d8-b60c137991c4
  • Loading branch information
sbordet committed Apr 27, 2010
1 parent 19f96a8 commit 19368f3
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 360 deletions.
1 change: 1 addition & 0 deletions VERSION.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jetty-7.1.0-SNAPSHOT
+ Fix jetty-plus.xml reference to addLifeCycle
+ Add AnnotationConfiguration to jetty-plus.xml
+ 310467 Allow SocketConnector to create generic Connection objects
+ 310603 Make Logger interface consistent

jetty-7.0.2.v20100331 31 March 2010
+ 297552 Don't call Continuation timeouts from acceptor tick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
* <p>
* Implementation of Jetty {@link Logger} based on {@link java.util.logging.Logger}.
* </p>
*
*
* <p>
* Honors the standard jetty system property <code>"org.eclipse.jetty.util.log.DEBUG"</code> to set logger into debug
* mode (defaults to false, set to "true" to enable)
* </p>
*
*
* <p>
* You can also set the logger level using <a href="http://java.sun.com/j2se/1.5.0/docs/guide/logging/overview.html">
* standard java.util.logging configuration</a> against the name <code>"org.eclipse.jetty.util.log"</code>.
Expand All @@ -46,44 +46,42 @@ public JavaUtilLog(String name)
{
_logger = java.util.logging.Logger.getLogger(name);
if (Boolean.getBoolean("org.eclipse.jetty.util.log.DEBUG"))
{
_logger.setLevel(Level.FINE);
}
}

public String getName()
{
return _logger.getName();
}

public void debug(String msg)
public void warn(String msg, Object... args)
{
_logger.log(Level.FINE,msg);
_logger.log(Level.WARNING, format(msg, args));
}

public void debug(String msg, Throwable th)
public void warn(Throwable thrown)
{
_logger.log(Level.FINE,msg,th);
warn("", thrown);
}

public void debug(String msg, Object arg0, Object arg1)
public void warn(String msg, Throwable thrown)
{
_logger.log(Level.FINE,format(msg,arg0,arg1));
_logger.log(Level.WARNING, msg, thrown);
}

public Logger getLogger(String name)
public void info(String msg, Object... args)
{
return new JavaUtilLog(name);
_logger.log(Level.INFO, format(msg, args));
}

public void info(String msg)
public void info(Throwable thrown)
{
_logger.log(Level.INFO,msg);
info("", thrown);
}

public void info(String msg, Object arg0, Object arg1)
public void info(String msg, Throwable thrown)
{
_logger.log(Level.INFO,format(msg,arg0,arg1));
_logger.log(Level.INFO, msg, thrown);
}

public boolean isDebugEnabled()
Expand All @@ -96,30 +94,42 @@ public void setDebugEnabled(boolean enabled)
_logger.setLevel(Level.FINE);
}

public void warn(String msg)
public void debug(String msg, Object... args)
{
_logger.log(Level.WARNING,msg);
_logger.log(Level.FINE, format(msg, args));
}

public void warn(String msg, Object arg0, Object arg1)
public void debug(Throwable thrown)
{
_logger.log(Level.WARNING,format(msg,arg0,arg1));
debug("", thrown);
}

public void warn(String msg, Throwable th)
public void debug(String msg, Throwable thrown)
{
_logger.log(Level.WARNING,msg,th);
_logger.log(Level.FINE, msg, thrown);
}

private String format(String msg, Object arg0, Object arg1)
public Logger getLogger(String name)
{
int i0 = msg.indexOf("{}");
int i1 = i0 < 0?-1:msg.indexOf("{}",i0 + 2);
return new JavaUtilLog(name);
}

if (arg1 != null && i1 >= 0)
msg = msg.substring(0,i1) + arg1 + msg.substring(i1 + 2);
if (arg0 != null && i0 >= 0)
msg = msg.substring(0,i0) + arg0 + msg.substring(i0 + 2);
return msg;
private String format(String msg, Object... args)
{
msg = String.valueOf(msg); // Avoids NPE
String braces = "{}";
StringBuilder builder = new StringBuilder();
int start = 0;
for (Object arg : args)
{
int bracesIndex = msg.indexOf(braces, start);
if (bracesIndex < 0)
break;
builder.append(msg.substring(start, bracesIndex));
builder.append(String.valueOf(arg));
start = bracesIndex + braces.length();
}
builder.append(msg.substring(start));
return builder.toString();
}
}
101 changes: 82 additions & 19 deletions jetty-util/src/main/java/org/eclipse/jetty/util/log/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,102 @@
// 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
// 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.
// You may elect to redistribute this code under either of these licenses.
// ========================================================================

package org.eclipse.jetty.util.log;

/** Logging Facade
* A simple logging facade that is intended simply to capture the style
* of logging as used by Jetty.
*
/**
* A simple logging facade that is intended simply to capture the style of logging as used by Jetty.
*/
public interface Logger
{
/**
* @return the name of this logger
*/
public String getName();

/**
* Formats and logs at warn level.
* @param msg the formatting string
* @param arg the first argument
* @param args the optional arguments
*/
public void warn(String msg, Object... args);

/**
* Logs the given Throwable information at warn level
* @param thrown the Throwable to log
*/
public void warn(Throwable thrown);

/**
* Logs the given message at warn level, with Throwable information.
* @param msg the message to log
* @param thrown the Throwable to log
*/
public void warn(String msg, Throwable thrown);

/**
* Formats and logs at info level.
* @param msg the formatting string
* @param arg the first argument
* @param args the optional arguments
*/
public void info(String msg, Object... args);

/**
* Logs the given Throwable information at info level
* @param thrown the Throwable to log
*/
public void info(Throwable thrown);

/**
* Logs the given message at info level, with Throwable information.
* @param msg the message to log
* @param thrown the Throwable to log
*/
public void info(String msg, Throwable thrown);

/**
* @return whether the debug level is enabled
*/
public boolean isDebugEnabled();

/** Mutator used to turn debug on programatically.
* Implementations operation in which case an appropriate
* warning message shall be generated.
/**
* Mutator used to turn debug on programmatically.
* @param enabled whether to enable the debug level
*/
public void setDebugEnabled(boolean enabled);

public void info(String msg);
public void info(String msg,Object arg0, Object arg1);
public void debug(String msg);
public void debug(String msg,Throwable th);
public void debug(String msg,Object arg0, Object arg1);
public void warn(String msg);
public void warn(String msg,Object arg0, Object arg1);
public void warn(String msg, Throwable th);
/**
* Formats and logs at debug level.
* @param msg the formatting string
* @param arg the first argument
* @param args the optional arguments
*/
public void debug(String msg, Object... args);

/**
* Logs the given Throwable information at debug level
* @param thrown the Throwable to log
*/
public void debug(Throwable thrown);

/**
* Logs the given message at debug level, with Throwable information.
* @param msg the message to log
* @param thrown the Throwable to log
*/
public void debug(String msg, Throwable thrown);

/**
* @param name the name of the logger
* @return a logger with the given name
*/
public Logger getLogger(String name);

public String getName();
}
Loading

0 comments on commit 19368f3

Please sign in to comment.