diff --git a/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLogger.java b/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLogger.java index 93638ee82..eaf1a45cf 100644 --- a/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLogger.java +++ b/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLogger.java @@ -43,13 +43,13 @@ * Simple implementation of {@link Logger} that sends all enabled log messages, * for all defined loggers, to the console ({@code System.err}). The following * system properties are supported to configure the behavior of this logger: - * + * * *
org.slf4j.simpleLogger.logFile - The output target which can
* be the path to a file, or the special values "System.out" and
* "System.err". Default is "System.err".org.slf4j.simpleLogger.cacheOutputStream - If the output
* target is set to "System.out" or "System.err" (see preceding entry), by
* default, logs will be output to the latest value referenced by
@@ -57,7 +57,7 @@
* output stream will be cached, i.e. assigned once at initialization time and
* re-used independently of the current value referenced by
* System.out/err.org.slf4j.simpleLogger.defaultLogLevel - Default log level
* for all instances of SimpleLogger. Must be one of ("trace", "debug", "info",
* "warn", "error" or "off"). If not specified, defaults to "info".org.slf4j.simpleLogger.showThreadName -Set to
* true if you want to output the current thread name. Defaults to
* true.org.slf4j.simpleLogger.showThreadId -
+ *
+ * org.slf4j.simpleLogger.showThreadId -
* If you would like to output the current thread id, then set to
* true. Defaults to false.org.slf4j.simpleLogger.showLogName - Set to
* true if you want the Logger instance name to be included in
* output messages. Defaults to true.true if you want the last component of the name to be included
* in output messages. Defaults to false.
*
+ * org.slf4j.simpleLogger.showLogLevel - Set to
+ * true if you want the Logger level to be included in
+ * output messages. Defaults to true.org.slf4j.simpleLogger.levelInBrackets - Should the level
* string be output in brackets? Defaults to false.org.slf4j.simpleLogger.warnLevelString - The string value
* output for the warn level. Defaults to WARN.
@@ -110,18 +114,18 @@
* this implementation also checks for a class loader resource named
* "simplelogger.properties", and includes any matching definitions
* from this resource (if it exists).
- *
+ *
*
*
* With no configuration, the default output includes the relative time in * milliseconds, thread name, the level, logger name, and the message followed * by the line separator for the host. In log4j terms it amounts to the "%r [%t] * %level %logger - %m%n" pattern. - * + * *
* Sample output follows. - * - * + * + * *
* 176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse order.
* 225 [main] INFO examples.SortAlgo - Entered the sort method.
@@ -139,7 +143,7 @@
* This implementation is heavily inspired by
* Apache Commons Logging's
* SimpleLog.
- *
+ *
*
* @author Ceki Gülcü
* @author Scott Sanders
@@ -170,7 +174,7 @@ public class SimpleLogger extends LegacyAbstractLogger {
private static boolean INITIALIZED = false;
static final SimpleLoggerConfiguration CONFIG_PARAMS = new SimpleLoggerConfiguration();
-
+
static void lazyInit() {
if (INITIALIZED) {
return;
@@ -210,10 +214,12 @@ static void init() {
public static final String SHOW_LOG_NAME_KEY = SimpleLogger.SYSTEM_PREFIX + "showLogName";
+ public static final String SHOW_LOG_LEVEL_KEY = SimpleLogger.SYSTEM_PREFIX + "showLogLevel";
+
public static final String SHOW_THREAD_NAME_KEY = SimpleLogger.SYSTEM_PREFIX + "showThreadName";
public static final String SHOW_THREAD_ID_KEY = SimpleLogger.SYSTEM_PREFIX + "showThreadId";
-
+
public static final String DATE_TIME_FORMAT_KEY = SimpleLogger.SYSTEM_PREFIX + "dateTimeFormat";
public static final String SHOW_DATE_TIME_KEY = SimpleLogger.SYSTEM_PREFIX + "showDateTime";
@@ -250,7 +256,7 @@ String recursivelyComputeLevelString() {
/**
* To avoid intermingling of log messages and associated stack traces, the two
* operations are done in a synchronized block.
- *
+ *
* @param buf
* @param t
*/
@@ -261,7 +267,7 @@ void write(StringBuilder buf, Throwable t) {
targetStream.println(buf.toString());
writeThrowable(t, targetStream);
targetStream.flush();
- }
+ }
}
@@ -398,22 +404,24 @@ private void innerHandleNormalizedLoggingCall(Level level, List markers,
buf.append(Thread.currentThread().getName());
buf.append("] ");
}
-
+
if (CONFIG_PARAMS.showThreadId) {
buf.append(TID_PREFIX);
buf.append(Thread.currentThread().getId());
buf.append(SP);
}
- if (CONFIG_PARAMS.levelInBrackets)
- buf.append('[');
+ if (CONFIG_PARAMS.showLogLevel) {
+ if (CONFIG_PARAMS.levelInBrackets)
+ buf.append('[');
- // Append a readable representation of the log level
- String levelStr = level.name();
- buf.append(levelStr);
- if (CONFIG_PARAMS.levelInBrackets)
- buf.append(']');
- buf.append(SP);
+ // Append a readable representation of the log level
+ String levelStr = level.name();
+ buf.append(levelStr);
+ if (CONFIG_PARAMS.levelInBrackets)
+ buf.append(']');
+ buf.append(SP);
+ }
// Append the name of the log instance if so configured
if (CONFIG_PARAMS.showShortLogName) {
diff --git a/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLoggerConfiguration.java b/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLoggerConfiguration.java
index 0a7f1310d..6ef315a16 100755
--- a/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLoggerConfiguration.java
+++ b/slf4j-simple/src/main/java/org/slf4j/simple/SimpleLoggerConfiguration.java
@@ -18,14 +18,14 @@
* This class holds configuration values for {@link SimpleLogger}. The
* values are computed at runtime. See {@link SimpleLogger} documentation for
* more information.
- *
- *
+ *
+ *
* @author Ceki Gülcü
* @author Scott Sanders
* @author Rod Waldhoff
* @author Robert Burrell Donkin
* @author Cédrik LIME
- *
+ *
* @since 1.7.25
*/
public class SimpleLoggerConfiguration {
@@ -52,13 +52,16 @@ public class SimpleLoggerConfiguration {
*/
private static final boolean SHOW_THREAD_ID_DEFAULT = false;
boolean showThreadId = SHOW_THREAD_ID_DEFAULT;
-
+
final static boolean SHOW_LOG_NAME_DEFAULT = true;
boolean showLogName = SHOW_LOG_NAME_DEFAULT;
private static final boolean SHOW_SHORT_LOG_NAME_DEFAULT = false;
boolean showShortLogName = SHOW_SHORT_LOG_NAME_DEFAULT;
+ final static boolean SHOW_LOG_LEVEL_DEFAULT = true;
+ boolean showLogLevel = SHOW_LOG_LEVEL_DEFAULT;
+
private static final boolean LEVEL_IN_BRACKETS_DEFAULT = false;
boolean levelInBrackets = LEVEL_IN_BRACKETS_DEFAULT;
@@ -87,6 +90,7 @@ void init() {
showThreadName = getBooleanProperty(SimpleLogger.SHOW_THREAD_NAME_KEY, SHOW_THREAD_NAME_DEFAULT);
showThreadId = getBooleanProperty(SimpleLogger.SHOW_THREAD_ID_KEY, SHOW_THREAD_ID_DEFAULT);
dateTimeFormatStr = getStringProperty(SimpleLogger.DATE_TIME_FORMAT_KEY, DATE_TIME_FORMAT_STR_DEFAULT);
+ showLogLevel = getBooleanProperty(SimpleLogger.SHOW_LOG_LEVEL_KEY, SimpleLoggerConfiguration.SHOW_LOG_LEVEL_DEFAULT);
levelInBrackets = getBooleanProperty(SimpleLogger.LEVEL_IN_BRACKETS_KEY, LEVEL_IN_BRACKETS_DEFAULT);
warnLevelString = getStringProperty(SimpleLogger.WARN_LEVEL_STRING_KEY, WARN_LEVELS_STRING_DEFAULT);