package de.codecentric.jbehave.junit.monitoring;

import static de.codecentric.jbehave.junit.monitoring.Logger.LogLevel.DEBUG;
import static de.codecentric.jbehave.junit.monitoring.Logger.LogLevel.INFO;
import static de.codecentric.jbehave.junit.monitoring.Logger.LogLevel.NONE;

import java.io.PrintStream;

public class Logger {
	public static final String PROP_JJM_LOGLEVEL = "jjm.loglevel";
	private volatile LogLevel logLevel;
	private PrintStream logStream = System.out;

	public void info(String message, Object... params) {
		if (!isInfoEnabled()) {
			return;
		}
		printMessage(INFO, message, params);
	}

	public void debug(String message, Object... params) {
		if (!isDebugEnabled()) {
			return;
		}
		printMessage(DEBUG, message, params);
	}

	boolean isInfoEnabled() {
		return isLevelEnabled(INFO);
	}

	boolean isLevelEnabled(LogLevel level) {
		return getLogLevel().ordinal() >= level.ordinal();
	}

	private LogLevel getLogLevel() {
		if (logLevel != null) {
			return logLevel;
		}
		synchronized (Logger.class) {
			if (logLevel == null) {
				String configuredLevel = System.getProperty(PROP_JJM_LOGLEVEL);
				if (configuredLevel == null
						|| "".equals(configuredLevel.trim())) {
					logLevel = NONE;
				} else {
					configuredLevel = configuredLevel.trim();
					try {
						logLevel = LogLevel.valueOf(configuredLevel
								.toUpperCase());
					} catch (IllegalArgumentException e) {
						logLevel = NONE;
					}
				}
			}
		}
		return logLevel;

	}

	boolean isDebugEnabled() {
		return isLevelEnabled(DEBUG);
	}

	private void printMessage(LogLevel level, String message, Object... params) {
		String format = message.replace("{}", "%s");
		Object[] strings = new String[params.length];
		for (int i = 0; i < params.length; i++) {
			if (params[i] == null) {
				strings[i] = "null";
			} else {
				strings[i] = params[i].toString();
			}
		}
		logStream.println(level + ": " + String.format(format, strings));
	}

	enum LogLevel {
		NONE, ERROR, WARN, INFO, DEBUG
	}
}

@@ -302,16 +302,62 @@
 tream;%0A%0A
+import org.apache.commons.lang3.StringUtils;%0A%0A
 public c
@@ -575,49 +575,8 @@
 ) %7B%0A
-%09%09if (!isInfoEnabled()) %7B%0A%09%09%09return;%0A%09%09%7D%0A
 %09%09pr
@@ -673,50 +673,8 @@
 ) %7B%0A
-%09%09if (!isDebugEnabled()) %7B%0A%09%09%09return;%0A%09%09%7D%0A
 %09%09pr
@@ -718,70 +718,16 @@
 %7D%0A%0A%09
-boolean isInfoEnabled() %7B%0A%09%09return isLevelEnabled(INFO);%0A%09%7D%0A%0A%09
+private 
 bool
@@ -1043,50 +1043,27 @@
 if (
-configuredLevel == null%0A%09%09%09%09%09%09%7C%7C %22%22.equals
+StringUtils.isBlank
 (con
@@ -1074,23 +1074,16 @@
 redLevel
-.trim()
 )) %7B%0A%09%09%09
@@ -1358,73 +1358,8 @@
 vel;
-%0A%0A%09%7D%0A%0A%09boolean isDebugEnabled() %7B%0A%09%09return isLevelEnabled(DEBUG);
 %0A%09%7D%0A
@@ -1438,16 +1438,48 @@
 rams) %7B%0A
+%09%09if (isLevelEnabled(level)) %7B%0A%09
 %09%09String
@@ -1517,16 +1517,17 @@
  %22%25s%22);%0A
+%09
 %09%09Object
@@ -1568,16 +1568,17 @@
 gth%5D;%0A%09%09
+%09
 for (int
@@ -1616,39 +1616,11 @@
  %7B%0A%09
-%09%09if (params%5Bi%5D == null) %7B%0A
 %09%09%09
-%09
 stri
@@ -1632,64 +1632,32 @@
 %5D = 
-%22null%22;%0A%09%09%09%7D else %7B%0A%09%09%09%09strings%5Bi%5D = params%5Bi%5D.toString(
+String.valueOf(params%5Bi%5D
 );%0A%09
@@ -1661,19 +1661,16 @@
 ;%0A%09%09%09%7D%0A%09
-%09%7D%0A
 %09%09logStr
@@ -1729,16 +1729,20 @@
 ings));%0A
+%09%09%7D%0A
 %09%7D%0A%0A%09enu

Simplify Logger