Simple implementation of Log that sends all enabled log messages, for all defined loggers, to System.err. The following system properties are supported to configure the behavior of this logger:
org.apache.commons.logging.simplelog.defaultlog
- Default logging detail level for all instances of SimpleLog. Must be one of ("trace", "debug", "info", "warn", "error", or "fatal"). If not specified, defaults to "info". org.apache.commons.logging.simplelog.log.xxxxx
- Logging detail level for a SimpleLog instance named "xxxxx". Must be one of ("trace", "debug", "info", "warn", "error", or "fatal"). If not specified, the default logging detail level is used. org.apache.commons.logging.simplelog.showlogname
- Set to true
if you want the Log instance name to be included in output messages. Defaults to false
. org.apache.commons.logging.simplelog.showShortLogname
- Set to true
if you want the last component of the name to be included in output messages. Defaults to true
. org.apache.commons.logging.simplelog.showdatetime
- Set to true
if you want the current date and time to be included in output messages. Default is false
. org.apache.commons.logging.simplelog.dateTimeFormat
- The date and time format to be used in the output messages. The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat
. If the format is not specified or is invalid, the default format is used. The default format is yyyy/MM/dd HH:mm:ss:SSS zzz
. In addition to looking for system properties with the names specified above, this implementation also checks for a class loader resource named "simplelog.properties"
, and includes any matching definitions from this resource (if it exists).
The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.
/* * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
Public Member Functions | |
SimpleLog (String name) | |
Construct a simple log with given name. More... | |
void | setLevel (int currentLogLevel) |
int | getLevel () |
final void | debug (Object message) |
Logs a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG . More... | |
final void | debug (Object message, Throwable t) |
Logs a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG . More... | |
final void | trace (Object message) |
Logs a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_TRACE . More... | |
final void | trace (Object message, Throwable t) |
Logs a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_TRACE . More... | |
final void | info (Object message) |
Logs a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_INFO . More... | |
final void | info (Object message, Throwable t) |
Logs a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_INFO . More... | |
final void | warn (Object message) |
Logs a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_WARN . More... | |
final void | warn (Object message, Throwable t) |
Logs a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_WARN . More... | |
final void | error (Object message) |
Logs a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_ERROR . More... | |
final void | error (Object message, Throwable t) |
Logs a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_ERROR . More... | |
final void | fatal (Object message) |
Log a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_FATAL . More... | |
final void | fatal (Object message, Throwable t) |
Logs a message with org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_FATAL . More... | |
final boolean | isDebugEnabled () |
final boolean | isErrorEnabled () |
final boolean | isFatalEnabled () |
final boolean | isInfoEnabled () |
final boolean | isTraceEnabled () |
final boolean | isWarnEnabled () |
Static Public Attributes | |
static final int | LOG_LEVEL_TRACE = 1 |
"Trace" level logging. More... | |
static final int | LOG_LEVEL_DEBUG = 2 |
"Debug" level logging. More... | |
static final int | LOG_LEVEL_INFO = 3 |
"Info" level logging. More... | |
static final int | LOG_LEVEL_WARN = 4 |
"Warn" level logging. More... | |
static final int | LOG_LEVEL_ERROR = 5 |
"Error" level logging. More... | |
static final int | LOG_LEVEL_FATAL = 6 |
"Fatal" level logging. More... | |
static final int | LOG_LEVEL_ALL = (LOG_LEVEL_TRACE - 1) |
Enable all logging levels. | |
static final int | LOG_LEVEL_OFF = (LOG_LEVEL_FATAL + 1) |
Enable no logging levels. | |
Protected Member Functions | |
void | log (int type, Object message, Throwable t) |
void | write (StringBuffer buffer) |
boolean | isLevelEnabled (int logLevel) |
Is the given log level currently enabled? More... | |
Protected Attributes | |
String | logName = null |
The name of this simple log instance. | |
int | currentLogLevel |
The current log level. | |
Static Protected Attributes | |
static final String | systemPrefix |
All system properties used by SimpleLog start with this. | |
static final Properties | simpleLogProps = new Properties() |
Properties loaded from simplelog.properties. | |
static final String | DEFAULT_DATE_TIME_FORMAT |
The default format to use when formating dates. | |
static boolean | showLogName = false |
Include the instance name in the log message? | |
static boolean | showShortName = true |
Include the short name ( last component ) of the logger in the log message. More... | |
static boolean | showDateTime = false |
Include the current time in the log message. | |
static String | dateTimeFormat = DEFAULT_DATE_TIME_FORMAT |
The date and time format to use in the log message. | |
static DateFormat | dateFormatter = null |
Used to format times. | |
SimpleLog | ( | String | name | ) |
name | log name |
void setLevel | ( | int | currentLogLevel | ) |
Set logging level.
currentLogLevel | new logging level |
int getLevel | ( | ) |
Get logging level.
|
protected |
Do the actual logging. This method assembles the message and then calls write()
to cause it to be written.
type | One of the LOG_LEVEL_XXX constants defining the log level |
message | The message itself (typically a String) |
t | The exception whose stack trace should be logged |
|
protected |
Write the content of the message accumulated in the specified StringBuffer
to the appropriate output destination. The default implementation writes to System.err
.
buffer | A StringBuffer containing the accumulated text to be logged |
|
protected |
logLevel | is this level enabled? |
final void debug | ( | Object | message | ) |
final void debug | ( | Object | message, |
Throwable | t | ||
) |
message | to log |
t | log this cause |
Implements Log.
final void trace | ( | Object | message | ) |
final void trace | ( | Object | message, |
Throwable | t | ||
) |
message | to log |
t | log this cause |
Implements Log.
final void info | ( | Object | message | ) |
final void info | ( | Object | message, |
Throwable | t | ||
) |
message | to log |
t | log this cause |
Implements Log.
final void warn | ( | Object | message | ) |
final void warn | ( | Object | message, |
Throwable | t | ||
) |
message | to log |
t | log this cause |
Implements Log.
final void error | ( | Object | message | ) |
final void error | ( | Object | message, |
Throwable | t | ||
) |
message | to log |
t | log this cause |
Implements Log.
final void fatal | ( | Object | message | ) |
final void fatal | ( | Object | message, |
Throwable | t | ||
) |
message | to log |
t | log this cause |
Implements Log.
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.
Implements Log.
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.
Implements Log.
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.
Implements Log.
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.
Implements Log.
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.
Implements Log.
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.
Implements Log.
|
staticprotected |
Defaults to true - otherwise we'll be lost in a flood of messages without knowing who sends them.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |