Skip to content

Commit

Permalink
fix SLF4J-394
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Feb 26, 2017
1 parent 898e222 commit 509c344
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions slf4j-simple/src/main/java/org/slf4j/impl/SimpleLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ public class SimpleLogger extends MarkerIgnoringBase {
private static long START_TIME = System.currentTimeMillis();
private static final Properties SIMPLE_LOGGER_PROPS = new Properties();

private static final int LOG_LEVEL_TRACE = LocationAwareLogger.TRACE_INT;
private static final int LOG_LEVEL_DEBUG = LocationAwareLogger.DEBUG_INT;
private static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT;
private static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT;
private static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT;
protected static final int LOG_LEVEL_TRACE = LocationAwareLogger.TRACE_INT;
protected static final int LOG_LEVEL_DEBUG = LocationAwareLogger.DEBUG_INT;
protected static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT;
protected static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT;
protected static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT;
// The OFF level can only be used in configuration files to disable logging. It has
// no printing method associated with it in o.s.Logger interface.
private static final int LOG_LEVEL_OFF = LOG_LEVEL_ERROR + 10;
protected static final int LOG_LEVEL_OFF = LOG_LEVEL_ERROR + 10;

private static boolean INITIALIZED = false;

Expand Down Expand Up @@ -353,23 +353,8 @@ private void log(int level, String message, Throwable t) {
buf.append('[');

// Append a readable representation of the log level
switch (level) {
case LOG_LEVEL_TRACE:
buf.append("TRACE");
break;
case LOG_LEVEL_DEBUG:
buf.append("DEBUG");
break;
case LOG_LEVEL_INFO:
buf.append("INFO");
break;
case LOG_LEVEL_WARN:
buf.append(WARN_LEVEL_STRING);
break;
case LOG_LEVEL_ERROR:
buf.append("ERROR");
break;
}
String levelStr = renderLevel(level);
buf.append(levelStr);
if (LEVEL_IN_BRACKETS)
buf.append(']');
buf.append(' ');
Expand All @@ -390,19 +375,36 @@ private void log(int level, String message, Throwable t) {

}

protected String renderLevel(int level) {
switch (level) {
case LOG_LEVEL_TRACE:
return "TRACE";
case LOG_LEVEL_DEBUG:
return("DEBUG");
case LOG_LEVEL_INFO:
return "INFO";
case LOG_LEVEL_WARN:
return WARN_LEVEL_STRING;
case LOG_LEVEL_ERROR:
return "ERROR";
}
throw new IllegalStateException("Unrecognized level ["+level+"]");
}

void write(StringBuilder buf, Throwable t) {
PrintStream targetStream = OUTPUT_CHOICE.getTargetPrintStream();

targetStream.println(buf.toString());
if (t != null) {
t.printStackTrace(targetStream);
}
writeThrowable(t, targetStream);
targetStream.flush();
}

Object t;
protected void writeThrowable(Throwable t, PrintStream targetStream) {
if (t != null) {
t.printStackTrace(targetStream);
}
}


private String getFormattedDate() {
Date now = new Date();
String dateText;
Expand Down

0 comments on commit 509c344

Please sign in to comment.