cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [17/19] cayenne git commit: CAY-2280 + custom modeler logger
Date Wed, 26 Apr 2017 10:09:31 GMT
CAY-2280 + custom modeler logger


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/a6f272bd
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/a6f272bd
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/a6f272bd

Branch: refs/heads/master
Commit: a6f272bd2ef9e33b847fca6f0859250ea70ad10e
Parents: 1f17edb
Author: Maxim Petrusevich <maks1464@gmail.com>
Authored: Fri Apr 21 14:47:39 2017 +0300
Committer: Maxim Petrusevich <maks1464@gmail.com>
Committed: Fri Apr 21 14:47:39 2017 +0300

----------------------------------------------------------------------
 maven-plugins/cayenne-maven-plugin/pom.xml      |   1 +
 modeler/cayenne-modeler/pom.xml                 |   5 -
 .../java/org/apache/cayenne/modeler/Main.java   |   1 -
 .../cayenne/modeler/util/ModelerLogFactory.java |  15 +-
 .../cayenne/modeler/util/ModelerLogger.java     | 244 +++++++++++++------
 .../java/org/slf4j/impl/StaticLoggerBinder.java |  29 +++
 pom.xml                                         |   1 +
 7 files changed, 206 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/a6f272bd/maven-plugins/cayenne-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/maven-plugins/cayenne-maven-plugin/pom.xml b/maven-plugins/cayenne-maven-plugin/pom.xml
index 0142946..bb70da8 100644
--- a/maven-plugins/cayenne-maven-plugin/pom.xml
+++ b/maven-plugins/cayenne-maven-plugin/pom.xml
@@ -97,6 +97,7 @@
 		<dependency>
 			<groupId>org.slf4j</groupId>
 			<artifactId>slf4j-simple</artifactId>
+			<scope>test</scope>
 		</dependency>
 
 		<dependency>

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a6f272bd/modeler/cayenne-modeler/pom.xml
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/pom.xml b/modeler/cayenne-modeler/pom.xml
index 9735c15..921e0ca 100644
--- a/modeler/cayenne-modeler/pom.xml
+++ b/modeler/cayenne-modeler/pom.xml
@@ -48,11 +48,6 @@
 		</dependency>
 
 		<dependency>
-			<groupId>org.slf4j</groupId>
-			<artifactId>slf4j-simple</artifactId>
-		</dependency>
-
-		<dependency>
 			<groupId>org.apache.velocity</groupId>
 			<artifactId>velocity</artifactId>
 		</dependency>

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a6f272bd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Main.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Main.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Main.java
index e8193a3..a431cc9 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Main.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Main.java
@@ -69,7 +69,6 @@ public class Main {
 
         // TODO: use module auto-loading...
         final Injector injector = DIBootstrap.createInjector(appendModules(new ArrayList<Module>()));
-
         logger.info("Starting CayenneModeler.");
         logger.info("JRE v."
                 + System.getProperty("java.version")

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a6f272bd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerLogFactory.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerLogFactory.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerLogFactory.java
index 56a4d97..1a2aec0 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerLogFactory.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerLogFactory.java
@@ -21,14 +21,12 @@ package org.apache.cayenne.modeler.util;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.slf4j.Logger;
-import org.slf4j.impl.SimpleLoggerFactory;
+import org.slf4j.ILoggerFactory;
 
 /**
- * Factory for creating ModelerLogger instances. LogFactoryImpl is subclassed to
- * save default behavior
+ * Factory for creating ModelerLogger instances.
  */
-public class ModelerLogFactory extends SimpleLoggerFactory {
+public class ModelerLogFactory implements ILoggerFactory {
 
 	/**
 	 * Local cache of modeler loggers
@@ -39,13 +37,14 @@ public class ModelerLogFactory extends SimpleLoggerFactory {
 		localCache = new HashMap<>();
 	}
 
-	public Logger getInstance(String name) {
+	public ModelerLogger getLogger(String name) {
 		ModelerLogger local = localCache.get(name);
 		if (local == null) {
-			Logger def = super.getLogger(name);
-			local = new ModelerLogger(name, def);
+			//Logger def = LoggerFactory.getLogger(name);
+			local = new ModelerLogger(name);
 			localCache.put(name, local);
 		}
 		return local;
 	}
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a6f272bd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerLogger.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerLogger.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerLogger.java
index 9dcc224..739cd7a 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerLogger.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ModelerLogger.java
@@ -21,307 +21,401 @@ package org.apache.cayenne.modeler.util;
 import org.apache.cayenne.modeler.dialog.LogConsole;
 import org.slf4j.Logger;
 import org.slf4j.Marker;
+import org.slf4j.helpers.FormattingTuple;
+import org.slf4j.helpers.MessageFormatter;
 
 import javax.swing.text.AttributeSet;
+import java.io.PrintStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 /**
- * ModelerLogger is a Log implementation, which performs output
- * to the LogConsole. Default behavior is saved since they are delegated
- * to default Log instance. 
+ * ModelerLogger is a Logger implementation, which performs output
+ * to the LogConsole.
  */
 public class ModelerLogger implements Logger {
-    /**
-     * 'Default' Log instance (i.e. Log4jLogger, Jdk14Logger, or other)
-     */
-    Logger delegate;
+
+    private static final int BUFFER_SIZE = 32;
+    private static final byte LOG_LEVEL_INFO = 2;
+    private static final byte LOG_LEVEL_DEBUG = 1;
+    private static final byte LOG_LEVEL_TRACE = 0;
+    private static final byte LOG_LEVEL_WARNING = 3;
+    private static final byte LOG_LEVEL_ERROR = 4;
+
+    private static final String INFO_LOG_NAME = "INFO";
+    private static final String DEBUG_LOG_NAME = "DEBUG";
+    private static final String TRACE_LOG_NAME = "TRACE";
+    private static final String WARNING_LOG_NAME = "WARNING";
+    private static final String ERROR_LOG_NAME = "ERROR";
+    private static final String DATE_FORMAT = "yyyy/MM/dd HH.mm.ss";
     
     /** 
      * Logger name 
      */
-    String name;
-    
-    public ModelerLogger(String name, Logger delegate) {
+    private String name;
+    private int currentLogLevel = LOG_LEVEL_INFO;
+
+    public ModelerLogger(String name) {
         this.name = name;
-        this.delegate = delegate;
+    }
+
+    private String getLogLevel(byte level) {
+        switch (level) {
+            case LOG_LEVEL_INFO:
+                return INFO_LOG_NAME;
+
+            case LOG_LEVEL_DEBUG:
+                return DEBUG_LOG_NAME;
+
+            case LOG_LEVEL_TRACE:
+                return TRACE_LOG_NAME;
+
+            case LOG_LEVEL_WARNING:
+                return WARNING_LOG_NAME;
+
+            case LOG_LEVEL_ERROR:
+                return ERROR_LOG_NAME;
+
+            default:
+                throw new IllegalStateException("Unregistered log level - " + level);
+
+        }
+    }
+
+    private void consoleLog(byte level, String message, Throwable throwable) {
+        if(this.isLevelEnabled(level)) {
+            StringBuilder buffer = new StringBuilder(BUFFER_SIZE);
+            buffer.append(this.getFormattedDate());
+            buffer.append(' ');
+
+            buffer.append('[');
+            buffer.append(Thread.currentThread().getName());
+            buffer.append("] ");
+
+            buffer.append('[');
+            String levelStr = this.getLogLevel(level);
+            buffer.append(levelStr);
+            buffer.append(']');
+
+            buffer.append(' ');
+            buffer.append(message);
+            this.write(buffer, throwable);
+        }
+    }
+    
+    private void consoleLog(byte level, String message) {
+        consoleLog(level, message, (Throwable) null);
+    }
+
+    private void consoleLog(byte level, String format, Object... arguments) {
+        if(this.isLevelEnabled(level)) {
+            FormattingTuple tuple = MessageFormatter.arrayFormat(format, arguments);
+            this.consoleLog(level, tuple.getMessage(), tuple.getThrowable());
+        }
+    }
+
+    private String getFormattedDate() {
+        Date currentDate = new Date();
+        SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
+        String dateText = formatter.format(currentDate);
+        return dateText;
+    }
+
+    private void write(StringBuilder buffer, Throwable throwable) {
+        PrintStream targetStream = System.err;
+        targetStream.println(buffer.toString());
+        this.writeThrowable(throwable, targetStream);
+        targetStream.flush();
+    }
+
+    private void writeThrowable(Throwable throwable, PrintStream targetStream) {
+        if(throwable != null) {
+            throwable.printStackTrace(targetStream);
+        }
+
+    }
+
+    private boolean isLevelEnabled(int logLevel) {
+        return (logLevel >= this.currentLogLevel);
     }
 
     @Override
     public void debug(String message) {
-        delegate.debug(message);
+        consoleLog(LOG_LEVEL_DEBUG, message);
         log("DEBUG", message, null, LogConsole.WARN_STYLE);
     }
 
     @Override
     public void debug(String message, Object object) {
-        delegate.debug(message, object);
+        consoleLog(LOG_LEVEL_DEBUG, message, object);
         log("DEBUG", message, null, LogConsole.WARN_STYLE, object);
     }
 
     @Override
     public void debug(String message, Object object, Object secondObject) {
-        delegate.debug(message, object, secondObject);
+        consoleLog(LOG_LEVEL_DEBUG, message, object, secondObject);
         log("DEBUG", message, null, LogConsole.WARN_STYLE, object, secondObject);
     }
 
     @Override
     public void debug(String message, Object... objects) {
-        delegate.debug(message, objects);
+        consoleLog(LOG_LEVEL_DEBUG, message, objects);
         log("DEBUG", message, null, LogConsole.WARN_STYLE, objects);
     }
 
     @Override
     public void debug(String message, Throwable throwable) {
-        delegate.debug(message, throwable);
+        consoleLog(LOG_LEVEL_DEBUG, message, throwable);
         log("DEBUG", message, throwable, LogConsole.WARN_STYLE);
     }
 
     @Override
     public boolean isDebugEnabled(Marker marker) {
-        return delegate.isDebugEnabled(marker);
+        return isLevelEnabled(LOG_LEVEL_DEBUG);
     }
 
     @Override
     public void debug(Marker marker, String message) {
-        delegate.debug(marker, message);
+        consoleLog(LOG_LEVEL_DEBUG, message);
         log("DEBUG", message, null, LogConsole.WARN_STYLE);
     }
 
     @Override
     public void debug(Marker marker, String message, Object object) {
-        delegate.debug(marker, message, object);
+        consoleLog(LOG_LEVEL_DEBUG, message, object);
         log("DEBUG", message, null, LogConsole.WARN_STYLE, object);
     }
 
     @Override
     public void debug(Marker marker, String message, Object object, Object secondObject)
{
-        delegate.debug(marker, message, object, secondObject);
+        consoleLog(LOG_LEVEL_DEBUG, message, object, secondObject);
         log("DEBUG", message, null, LogConsole.WARN_STYLE, object, secondObject);
     }
 
     @Override
     public void debug(Marker marker, String message, Object... objects) {
-        delegate.debug(marker, message, objects);
+        consoleLog(LOG_LEVEL_DEBUG, message, objects);
         log("DEBUG", message, null, LogConsole.WARN_STYLE, objects);
     }
 
     @Override
     public void debug(Marker marker, String message, Throwable throwable) {
-        delegate.debug(marker, message, throwable);
+        consoleLog(LOG_LEVEL_DEBUG, message, throwable);
         log("DEBUG", message, throwable, LogConsole.WARN_STYLE);
     }
 
     @Override
     public boolean isInfoEnabled() {
-        return delegate.isInfoEnabled();
+        return isLevelEnabled(LOG_LEVEL_INFO);
     }
 
     @Override
     public void error(String message) {
-        delegate.error(message);
+        consoleLog(LOG_LEVEL_ERROR, message);
         log("ERROR", message, null, LogConsole.ERROR_STYLE);
     }
 
     @Override
     public void error(String message, Object object) {
-        delegate.error(message, object);
+        consoleLog(LOG_LEVEL_ERROR, message, object);
         log("ERROR", message, null, LogConsole.ERROR_STYLE, object);
     }
 
     @Override
     public void error(String message, Object object, Object secondObject) {
-        delegate.error(message, object, secondObject);
+        consoleLog(LOG_LEVEL_ERROR, message, object, secondObject);
         log("ERROR", message, null, LogConsole.ERROR_STYLE, object, secondObject);
     }
 
     @Override
     public void error(String message, Object... objects) {
-        delegate.error(message, objects);
+        consoleLog(LOG_LEVEL_ERROR, message, objects);
         log("ERROR", message, null, LogConsole.ERROR_STYLE, objects);
     }
 
     @Override
     public void error(String message, Throwable throwable) {
-        delegate.error(message, throwable);
+        consoleLog(LOG_LEVEL_ERROR, message, throwable);
         log("ERROR", message, throwable, LogConsole.ERROR_STYLE);
     }
 
     @Override
     public boolean isErrorEnabled(Marker marker) {
-        return delegate.isErrorEnabled(marker);
+        return isLevelEnabled(LOG_LEVEL_ERROR);
     }
 
     @Override
     public void error(Marker marker, String message) {
-        delegate.error(marker, message);
+        consoleLog(LOG_LEVEL_ERROR, message);
         log("ERROR", message, null, LogConsole.ERROR_STYLE);
     }
 
     @Override
     public void error(Marker marker, String message, Object object) {
-        delegate.error(marker, message , object);
+        consoleLog(LOG_LEVEL_ERROR, message, object);
         log("ERROR", message, null, LogConsole.ERROR_STYLE, object);
     }
 
     @Override
     public void error(Marker marker, String message, Object object, Object secondObject)
{
-        delegate.error(marker, message , object, secondObject);
+        consoleLog(LOG_LEVEL_ERROR, message, object, secondObject);
         log("ERROR", message, null, LogConsole.ERROR_STYLE, object, secondObject);
     }
 
     @Override
     public void error(Marker marker, String message, Object... objects) {
-        delegate.error(marker, message, objects);
+        consoleLog(LOG_LEVEL_ERROR, message, objects);
         log("ERROR", message, null, LogConsole.ERROR_STYLE, objects);
     }
 
     @Override
     public void error(Marker marker, String message, Throwable throwable) {
-        delegate.error(marker, message, throwable);
+        consoleLog(LOG_LEVEL_ERROR, message, throwable);
         log("ERROR", message, throwable, LogConsole.ERROR_STYLE);
     }
 
     @Override
     public void info(String message) {
-        delegate.info(message);
+        consoleLog(LOG_LEVEL_INFO, message);
         log("INFO", message, null, LogConsole.INFO_STYLE);
     }
 
     @Override
     public void info(String message, Object object) {
-        delegate.info(message, object);
+        consoleLog(LOG_LEVEL_INFO, message, object);
         log("INFO", message, null, LogConsole.INFO_STYLE, object);
     }
 
     @Override
     public void info(String message, Object object, Object secondObject) {
-        delegate.info(message, object, secondObject);
+        consoleLog(LOG_LEVEL_INFO, message, object, secondObject);
         log("INFO", message, null, LogConsole.INFO_STYLE, object, secondObject);
     }
 
     @Override
     public void info(String message, Object... objects) {
-        delegate.info(message, objects);
+        consoleLog(LOG_LEVEL_INFO, message, objects);
         log("INFO", message, null, LogConsole.INFO_STYLE, objects);
     }
 
     @Override
     public void info(String message, Throwable throwable) {
-        delegate.info(message, throwable);
+        consoleLog(LOG_LEVEL_INFO, message, throwable);
         log("INFO", message, throwable, LogConsole.INFO_STYLE);
     }
 
     @Override
     public boolean isInfoEnabled(Marker marker) {
-        return delegate.isInfoEnabled(marker);
+        return isLevelEnabled(LOG_LEVEL_INFO);
     }
 
     @Override
     public void info(Marker marker, String message) {
-        delegate.info(marker, message);
+        consoleLog(LOG_LEVEL_INFO, message);
         log("INFO", message, null, LogConsole.INFO_STYLE);
     }
 
     @Override
     public void info(Marker marker, String message, Object object) {
-        delegate.info(marker, message, object);
+        consoleLog(LOG_LEVEL_INFO, message, object);
         log("INFO", message, null, LogConsole.INFO_STYLE, object);
     }
 
     @Override
     public void info(Marker marker, String message, Object object, Object secondObject) {
-        delegate.info(marker, message, object, secondObject);
+        consoleLog(LOG_LEVEL_INFO, message, object, secondObject);
         log("INFO", message, null, LogConsole.INFO_STYLE, object, secondObject);
     }
 
     @Override
     public void info(Marker marker, String message, Object... objects) {
-        delegate.info(marker, message, objects);
+        consoleLog(LOG_LEVEL_INFO, message, objects);
         log("INFO", message, null, LogConsole.INFO_STYLE, objects);
     }
 
     @Override
     public void info(Marker marker, String message, Throwable throwable) {
-        delegate.info(marker, message, throwable);
+        consoleLog(LOG_LEVEL_INFO, message, throwable);
         log("INFO", message, throwable, LogConsole.INFO_STYLE);
     }
 
     @Override
     public boolean isWarnEnabled() {
-        return delegate.isWarnEnabled();
+        return isLevelEnabled(LOG_LEVEL_WARNING);
     }
 
     @Override
     public String getName() {
-        return delegate.getName();
+        return name;
     }
 
     @Override
     public boolean isTraceEnabled() {
-        return delegate.isTraceEnabled();
+        return isLevelEnabled(LOG_LEVEL_TRACE);
     }
 
     @Override
     public void trace(String message) {
-        delegate.trace(message);
+        consoleLog(LOG_LEVEL_TRACE, message);
         log("TRACE", message, null, LogConsole.DEBUG_STYLE);
     }
 
     @Override
     public void trace(String message, Object object) {
-        delegate.trace(message, object);
+        consoleLog(LOG_LEVEL_TRACE, message, object);
         log("TRACE", message, null, LogConsole.DEBUG_STYLE, object);
     }
 
     @Override
     public void trace(String message, Object object, Object secondObject) {
-        delegate.trace(message, object, secondObject);
+        consoleLog(LOG_LEVEL_TRACE, message, secondObject);
         log("TRACE", message, null, LogConsole.DEBUG_STYLE, object, secondObject);
     }
 
     @Override
     public void trace(String message, Object... objects) {
-        delegate.trace(message, objects);
+        consoleLog(LOG_LEVEL_TRACE, message, objects);
         log("TRACE", message, null, LogConsole.DEBUG_STYLE, objects);
     }
 
     @Override
     public void trace(String message, Throwable throwable) {
-        delegate.trace(message, throwable);
+        consoleLog(LOG_LEVEL_TRACE, message, throwable);
         log("TRACE", message, throwable, LogConsole.DEBUG_STYLE);
     }
 
     @Override
     public boolean isTraceEnabled(Marker marker) {
-        return delegate.isTraceEnabled(marker);
+        return isLevelEnabled(LOG_LEVEL_TRACE);
     }
 
     @Override
     public void trace(Marker marker, String message) {
-        delegate.trace(marker, message);
+        consoleLog(LOG_LEVEL_TRACE, message);
         log("TRACE", message, null, LogConsole.DEBUG_STYLE);
     }
 
     @Override
     public void trace(Marker marker, String message, Object object) {
-        delegate.trace(marker, message, object);
+        consoleLog(LOG_LEVEL_TRACE, message, object);
         log("TRACE", message, null, LogConsole.DEBUG_STYLE, object);
     }
 
     @Override
     public void trace(Marker marker, String message, Object object, Object secondObject)
{
-        delegate.trace(marker, message, object, secondObject);
+        consoleLog(LOG_LEVEL_TRACE, message, object, secondObject);
         log("TRACE", message, null, LogConsole.DEBUG_STYLE, object, secondObject);
     }
 
     @Override
     public void trace(Marker marker, String message, Object... objects) {
-        delegate.trace(marker, message, objects);
+        consoleLog(LOG_LEVEL_TRACE, message, objects);
         log("TRACE", message, null, LogConsole.DEBUG_STYLE, objects);
     }
 
     @Override
     public void trace(Marker marker, String message, Throwable throwable) {
-        delegate.trace(marker, message, throwable);
+        consoleLog(LOG_LEVEL_TRACE, message, throwable);
         log("TRACE", message, throwable, LogConsole.DEBUG_STYLE);
     }
 
@@ -332,83 +426,81 @@ public class ModelerLogger implements Logger {
 
     @Override
     public void warn(String message) {
-        delegate.warn(message);
+        consoleLog(LOG_LEVEL_WARNING, message);
         log("WARN", message, null, LogConsole.WARN_STYLE);
     }
 
     @Override
     public void warn(String message, Object object) {
-        delegate.warn(message, object);
+        consoleLog(LOG_LEVEL_WARNING, message, object);
         log("WARN", message, null, LogConsole.WARN_STYLE, object);
     }
 
     @Override
     public void warn(String message, Object... objects) {
-        delegate.warn(message, objects);
+        consoleLog(LOG_LEVEL_WARNING, message, objects);
         log("WARN", message, null, LogConsole.WARN_STYLE, objects);
     }
 
     @Override
     public void warn(String message, Object object, Object secondObject) {
-        delegate.warn(message, object, secondObject);
+        consoleLog(LOG_LEVEL_WARNING, message, secondObject);
         log("WARN", message, null, LogConsole.WARN_STYLE, object, secondObject);
     }
 
     @Override
     public void warn(String message, Throwable throwable) {
-        delegate.warn(message, throwable);
+        consoleLog(LOG_LEVEL_WARNING, message, throwable);
         log("WARN", message, throwable, LogConsole.WARN_STYLE);
     }
 
     @Override
     public boolean isWarnEnabled(Marker marker) {
-        return delegate.isWarnEnabled(marker);
+        return isLevelEnabled(LOG_LEVEL_WARNING);
     }
 
     @Override
     public void warn(Marker marker, String message) {
-        delegate.warn(marker, message);
+        consoleLog(LOG_LEVEL_WARNING, message);
         log("WARN", message, null, LogConsole.WARN_STYLE);
     }
 
     @Override
     public void warn(Marker marker, String message, Object object) {
-        delegate.warn(marker, message, object);
+        consoleLog(LOG_LEVEL_WARNING, message, object);
         log("WARN", message, null, LogConsole.WARN_STYLE, object);
     }
 
     @Override
     public void warn(Marker marker, String message, Object object, Object secondObject) {
-        delegate.warn(marker, message, object, secondObject);
+        consoleLog(LOG_LEVEL_WARNING, message, object, secondObject);
         log("WARN", message, null, LogConsole.WARN_STYLE, object, secondObject);
     }
 
     @Override
     public void warn(Marker marker, String message, Object... objects) {
-        delegate.warn(marker, message, objects);
+        consoleLog(LOG_LEVEL_WARNING, message, objects);
         log("WARN", message, null, LogConsole.WARN_STYLE, objects);
     }
 
     @Override
     public void warn(Marker marker, String message, Throwable throwable) {
-        delegate.warn(marker, message, throwable);
+        consoleLog(LOG_LEVEL_WARNING, message, throwable);
         log("WARN", message, throwable, LogConsole.WARN_STYLE);
     }
 
     @Override
     public boolean isErrorEnabled() {
-        return delegate.isErrorEnabled();
+        return isLevelEnabled(LOG_LEVEL_ERROR);
     }
 
     /**
-     * Prints common message to the console
+     * Prints common message to the modeler console
      */
 
     private void log(String level, String message, Throwable throwable, AttributeSet style,
Object... parameters) {
-        for (Object parameter : parameters) {
-            message.replaceFirst("\\{\\}", String.valueOf(parameter));
-        }
-        getLogConsole().appendMessage(level, message, throwable, style);
+        FormattingTuple tuple = MessageFormatter.arrayFormat(message, parameters);
+        getLogConsole().appendMessage(level, tuple.getMessage(), throwable, style);
     }
 
     private void log(String level, Object message, Throwable throwable, AttributeSet style)
{

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a6f272bd/modeler/cayenne-modeler/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
b/modeler/cayenne-modeler/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
new file mode 100644
index 0000000..7dd03aa
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
@@ -0,0 +1,29 @@
+package org.slf4j.impl;
+
+import org.apache.cayenne.modeler.util.ModelerLogFactory;
+import org.slf4j.ILoggerFactory;
+import org.slf4j.spi.LoggerFactoryBinder;
+
+/*
+*   StaticLoggerBinder bind and replace standard SLF4J LoggerFactory to ModelerLogFactory.
+*   This is used because in Cayenne Modeler we use custom logger implementation (ModelerLogger)
+*   for logging in System.err and modeler logger.
+* */
+public class StaticLoggerBinder implements LoggerFactoryBinder {
+
+    private final static StaticLoggerBinder singleton = new StaticLoggerBinder();
+    private final ILoggerFactory loggerFactory = new ModelerLogFactory();
+    private static final String loggerFactoryClassStr = ModelerLogFactory.class.getName();
+
+    public static StaticLoggerBinder getSingleton() {
+        return singleton;
+    }
+
+    public ILoggerFactory getLoggerFactory() {
+        return this.loggerFactory;
+    }
+
+    public String getLoggerFactoryClassStr() {
+        return this.loggerFactoryClassStr;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/a6f272bd/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0c8da83..6ed6a6b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -454,6 +454,7 @@
     			<groupId>org.slf4j</groupId>
     			<artifactId>slf4j-simple</artifactId>
     			<version>${slf4j.version}</version>
+				<scope>test</scope>
 			</dependency>
 		</dependencies>
 	</dependencyManagement>


Mime
View raw message