-
-
Save sunnygleason/595163 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.logging.LogFactory; | |
@SuppressWarnings({"UnusedDeclaration"}) | |
public class Log | |
{ | |
private final org.apache.commons.logging.Log log; | |
private Log(String name) | |
{ | |
log = LogFactory.getLog(name); | |
} | |
public static Log getLogger() | |
{ | |
return getLogger(getCallerClassName()); | |
} | |
public static Log getLogger(Class clazz) | |
{ | |
return getLogger(clazz.getName()); | |
} | |
public static Log getLogger(String name) | |
{ | |
return new Log(name); | |
} | |
public void debug(Throwable t) | |
{ | |
log.debug(t.getMessage(), t); | |
} | |
public void info(Throwable t) | |
{ | |
log.info(t.getMessage(), t); | |
} | |
public void warn(Throwable t) | |
{ | |
log.warn(t.getMessage(), t); | |
} | |
public void error(Throwable t) | |
{ | |
log.error(t.getMessage(), t); | |
} | |
public void debug(String format, Object... args) | |
{ | |
if (log.isDebugEnabled()) { | |
log.debug(String.format(format, args)); | |
} | |
} | |
public void info(String format, Object... args) | |
{ | |
if (log.isInfoEnabled()) { | |
log.info(String.format(format, args)); | |
} | |
} | |
public void warn(String format, Object... args) | |
{ | |
if (log.isWarnEnabled()) { | |
log.warn(String.format(format, args)); | |
} | |
} | |
public void error(String format, Object... args) | |
{ | |
if (log.isErrorEnabled()) { | |
log.error(String.format(format, args)); | |
} | |
} | |
public void debug(Throwable t, String format, Object... args) | |
{ | |
if (log.isDebugEnabled()) { | |
log.debug(String.format(format, args), t); | |
} | |
} | |
public void info(Throwable t, String format, Object... args) | |
{ | |
if (log.isInfoEnabled()) { | |
log.info(String.format(format, args), t); | |
} | |
} | |
public void warn(Throwable t, String format, Object... args) | |
{ | |
if (log.isWarnEnabled()) { | |
log.warn(String.format(format, args), t); | |
} | |
} | |
public void error(Throwable t, String format, Object... args) | |
{ | |
if (log.isErrorEnabled()) { | |
log.error(String.format(format, args), t); | |
} | |
} | |
private static String getCallerClassName() | |
{ | |
return Thread.currentThread().getStackTrace()[3].getClassName(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment