Fields Summary |
---|
protected static final String | systemPrefixAll system properties used by SimpleLog start with this |
protected static final Properties | simpleLogPropsProperties loaded from simplelog.properties |
protected static final String | DEFAULT_DATE_TIME_FORMATThe default format to use when formating dates |
protected static boolean | showLogNameInclude the instance name in the log message? |
protected static boolean | showShortNameInclude the short name ( last component ) of the logger in the log
message. Defaults to true - otherwise we'll be lost in a flood of
messages without knowing who sends them. |
protected static boolean | showDateTimeInclude the current time in the log message |
protected static String | dateTimeFormatThe date and time format to use in the log message |
protected static DateFormat | dateFormatterUsed to format times |
public static final int | LOG_LEVEL_TRACE"Trace" level logging. |
public static final int | LOG_LEVEL_DEBUG"Debug" level logging. |
public static final int | LOG_LEVEL_INFO"Info" level logging. |
public static final int | LOG_LEVEL_WARN"Warn" level logging. |
public static final int | LOG_LEVEL_ERROR"Error" level logging. |
public static final int | LOG_LEVEL_FATAL"Fatal" level logging. |
public static final int | LOG_LEVEL_ALLEnable all logging levels |
public static final int | LOG_LEVEL_OFFEnable no logging levels |
protected String | logNameThe name of this simple log instance |
protected int | currentLogLevelThe current log level |
private String | shortLogNameThe short name of this simple log instance |
Methods Summary |
---|
public final void | debug(java.lang.Object message)Logs a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG)) {
log(SimpleLog.LOG_LEVEL_DEBUG, message, null);
}
|
public final void | debug(java.lang.Object message, java.lang.Throwable t)Logs a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG)) {
log(SimpleLog.LOG_LEVEL_DEBUG, message, t);
}
|
public final void | error(java.lang.Object message)Logs a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_ERROR .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR)) {
log(SimpleLog.LOG_LEVEL_ERROR, message, null);
}
|
public final void | error(java.lang.Object message, java.lang.Throwable t)Logs a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_ERROR .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR)) {
log(SimpleLog.LOG_LEVEL_ERROR, message, t);
}
|
public final void | fatal(java.lang.Object message)Log a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_FATAL .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL)) {
log(SimpleLog.LOG_LEVEL_FATAL, message, null);
}
|
public final void | fatal(java.lang.Object message, java.lang.Throwable t)Logs a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_FATAL .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL)) {
log(SimpleLog.LOG_LEVEL_FATAL, message, t);
}
|
private static boolean | getBooleanProperty(java.lang.String name, boolean dephault)
String prop = getStringProperty(name);
return (prop == null) ? dephault : "true".equalsIgnoreCase(prop);
|
private static java.lang.ClassLoader | getContextClassLoader()Return the thread context class loader if available.
Otherwise return null.
The thread context class loader is available for JDK 1.2
or later, if certain security conditions are met.
ClassLoader classLoader = null;
if (classLoader == null) {
try {
// Are we running on a JDK 1.2 or later system?
Method method = Thread.class.getMethod("getContextClassLoader",
(Class[]) null);
// Get the thread context class loader (if there is one)
try {
classLoader = (ClassLoader)method.invoke(Thread.currentThread(),
(Object[]) null);
} catch (IllegalAccessException e) {
; // ignore
} catch (InvocationTargetException e) {
/**
* InvocationTargetException is thrown by 'invoke' when
* the method being invoked (getContextClassLoader) throws
* an exception.
*
* getContextClassLoader() throws SecurityException when
* the context class loader isn't an ancestor of the
* calling class's class loader, or if security
* permissions are restricted.
*
* In the first case (not related), we want to ignore and
* keep going. We cannot help but also ignore the second
* with the logic below, but other calls elsewhere (to
* obtain a class loader) will trigger this exception where
* we can make a distinction.
*/
if (e.getTargetException() instanceof SecurityException) {
; // ignore
} else {
// Capture 'e.getTargetException()' exception for details
// alternate: log 'e.getTargetException()', and pass back 'e'.
throw new LogConfigurationException
("Unexpected InvocationTargetException", e.getTargetException());
}
}
} catch (NoSuchMethodException e) {
// Assume we are running on JDK 1.1
; // ignore
}
}
if (classLoader == null) {
classLoader = SimpleLog.class.getClassLoader();
}
// Return the selected class loader
return classLoader;
|
public int | getLevel() Get logging level.
return currentLogLevel;
|
private static java.io.InputStream | getResourceAsStream(java.lang.String name)
return (InputStream)AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
ClassLoader threadCL = getContextClassLoader();
if (threadCL != null) {
return threadCL.getResourceAsStream(name);
} else {
return ClassLoader.getSystemResourceAsStream(name);
}
}
});
|
private static java.lang.String | getStringProperty(java.lang.String name)
// ------------------------------------------------------------ Initializer
String prop = null;
try {
prop = System.getProperty(name);
} catch (SecurityException e) {
; // Ignore
}
return (prop == null) ? simpleLogProps.getProperty(name) : prop;
|
private static java.lang.String | getStringProperty(java.lang.String name, java.lang.String dephault)
String prop = getStringProperty(name);
return (prop == null) ? dephault : prop;
|
public final void | info(java.lang.Object message)Logs a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_INFO .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_INFO)) {
log(SimpleLog.LOG_LEVEL_INFO,message,null);
}
|
public final void | info(java.lang.Object message, java.lang.Throwable t)Logs a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_INFO .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_INFO)) {
log(SimpleLog.LOG_LEVEL_INFO, message, t);
}
|
public final boolean | isDebugEnabled() Are debug messages currently enabled?
This allows expensive operations such as String
concatenation to be avoided when the message will be ignored by the
logger.
return isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG);
|
public final boolean | isErrorEnabled() Are error messages currently enabled?
This allows expensive operations such as String
concatenation to be avoided when the message will be ignored by the
logger.
return isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR);
|
public final boolean | isFatalEnabled() Are fatal messages currently enabled?
This allows expensive operations such as String
concatenation to be avoided when the message will be ignored by the
logger.
return isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL);
|
public final boolean | isInfoEnabled() Are info messages currently enabled?
This allows expensive operations such as String
concatenation to be avoided when the message will be ignored by the
logger.
return isLevelEnabled(SimpleLog.LOG_LEVEL_INFO);
|
protected boolean | isLevelEnabled(int logLevel)Is the given log level currently enabled?
// log level are numerically ordered so can use simple numeric
// comparison
return (logLevel >= currentLogLevel);
|
public final boolean | isTraceEnabled() Are trace messages currently enabled?
This allows expensive operations such as String
concatenation to be avoided when the message will be ignored by the
logger.
return isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE);
|
public final boolean | isWarnEnabled() Are warn messages currently enabled?
This allows expensive operations such as String
concatenation to be avoided when the message will be ignored by the
logger.
return isLevelEnabled(SimpleLog.LOG_LEVEL_WARN);
|
protected void | log(int type, java.lang.Object message, java.lang.Throwable t) Do the actual logging.
This method assembles the message
and then calls write() to cause it to be written.
// Use a string buffer for better performance
StringBuffer buf = new StringBuffer();
// Append date-time if so configured
if(showDateTime) {
buf.append(dateFormatter.format(new Date()));
buf.append(" ");
}
// Append a readable representation of the log level
switch(type) {
case SimpleLog.LOG_LEVEL_TRACE: buf.append("[TRACE] "); break;
case SimpleLog.LOG_LEVEL_DEBUG: buf.append("[DEBUG] "); break;
case SimpleLog.LOG_LEVEL_INFO: buf.append("[INFO] "); break;
case SimpleLog.LOG_LEVEL_WARN: buf.append("[WARN] "); break;
case SimpleLog.LOG_LEVEL_ERROR: buf.append("[ERROR] "); break;
case SimpleLog.LOG_LEVEL_FATAL: buf.append("[FATAL] "); break;
}
// Append the name of the log instance if so configured
if( showShortName) {
if( shortLogName==null ) {
// Cut all but the last component of the name for both styles
shortLogName = logName.substring(logName.lastIndexOf(".") + 1);
shortLogName =
shortLogName.substring(shortLogName.lastIndexOf("/") + 1);
}
buf.append(String.valueOf(shortLogName)).append(" - ");
} else if(showLogName) {
buf.append(String.valueOf(logName)).append(" - ");
}
// Append the message
buf.append(String.valueOf(message));
// Append stack trace if not null
if(t != null) {
buf.append(" <");
buf.append(t.toString());
buf.append(">");
java.io.StringWriter sw= new java.io.StringWriter(1024);
java.io.PrintWriter pw= new java.io.PrintWriter(sw);
t.printStackTrace(pw);
pw.close();
buf.append(sw.toString());
}
// Print to the appropriate destination
write(buf);
|
public void | setLevel(int currentLogLevel) Set logging level.
this.currentLogLevel = currentLogLevel;
|
public final void | trace(java.lang.Object message)Logs a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_TRACE .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
log(SimpleLog.LOG_LEVEL_TRACE, message, null);
}
|
public final void | trace(java.lang.Object message, java.lang.Throwable t)Logs a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_TRACE .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
log(SimpleLog.LOG_LEVEL_TRACE, message, t);
}
|
public final void | warn(java.lang.Object message)Logs a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_WARN .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_WARN)) {
log(SimpleLog.LOG_LEVEL_WARN, message, null);
}
|
public final void | warn(java.lang.Object message, java.lang.Throwable t)Logs a message with
org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_WARN .
if (isLevelEnabled(SimpleLog.LOG_LEVEL_WARN)) {
log(SimpleLog.LOG_LEVEL_WARN, message, t);
}
|
protected void | write(java.lang.StringBuffer buffer)Write the content of the message accumulated in the specified
StringBuffer to the appropriate output destination. The
default implementation writes to System.err .
System.err.println(buffer.toString());
|