Commits

Stephen McKamey committed cef967f

moving all logging to SLF4J; piping SLF4J in maven-plugin to maven logger; reving to v0.7.0

Comments (0)

Files changed (13)

duel-compiler/pom.xml

 
 	<groupId>org.duelengine</groupId>
 	<artifactId>duel-compiler</artifactId>
-	<version>0.6.3</version>
+	<version>0.7.0</version>
 	<packaging>jar</packaging>
 
 	<name>DUEL Compiler</name>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
 		<rhino.version>1.7R3</rhino.version>
+		<slf4j.version>1.6.4</slf4j.version>
 		<junit.version>4.8.2</junit.version>
 		<jvm.version>1.6</jvm.version>
 	</properties>
 			<artifactId>duel-runtime</artifactId>
 			<version>${project.version}</version>
 		</dependency>
+
 		<dependency>
 			<groupId>org.mozilla</groupId>
 			<artifactId>rhino</artifactId>
 			<version>${rhino.version}</version>
 		</dependency>
+
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+			<version>${slf4j.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-jdk14</artifactId>
+			<version>${slf4j.version}</version>
+			<scope>test</scope>
+		</dependency>
+
 		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>

duel-compiler/src/main/java/org/duelengine/duel/compiler/DuelCompiler.java

 import org.duelengine.duel.ast.*;
 import org.duelengine.duel.codegen.*;
 import org.duelengine.duel.parsing.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class DuelCompiler {
 
+	private final Logger log = LoggerFactory.getLogger(DuelCompiler.class);
 	private boolean verbose;
 	private File inputDir;
 	private File outputClientDir;
 				}
 			}
 
-			System.err.println(String.format(
+			log.error(String.format(
 				"%s:%d: %s",
 				inputFile.getAbsolutePath(),
 				ex.getLine(),
 				text = reader.readLine();
 			}
 
-			System.err.println(text);
+			log.error(text);
 			if (col > 0) {
-				System.err.println(String.format("%"+col+"s", "^"));
+				log.error(String.format("%"+col+"s", "^"));
 			} else {
-				System.err.println("^");
+				log.error("^");
 			}
 
 			if (this.verbose) {
 
 	<groupId>org.duelengine</groupId>
 	<artifactId>duel-js</artifactId>
-	<version>0.6.4</version>
+	<version>0.7.0</version>
 	<packaging>pom</packaging>
 
 	<name>DUEL Client Scripts</name>

duel-js/target/duel.js

 
 /**
  * @fileoverview duel.js: client-side engine
- * @version DUEL v0.6.4 http://duelengine.org
+ * @version DUEL v0.7.0 http://duelengine.org
  * 
  * Copyright (c) 2006-2011 Stephen M. McKamey
  * Licensed under the MIT License (http://duelengine.org/license.txt)

duel-maven-plugin/pom.xml

 
 	<groupId>org.duelengine</groupId>
 	<artifactId>duel-maven-plugin</artifactId>
-	<version>0.6.3</version>
+	<version>0.7.0</version>
 	<packaging>maven-plugin</packaging>
 
 	<name>DUEL Maven Plugin</name>
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
+		<slf4j.version>1.6.4</slf4j.version>
 		<maven.version>3.0.3</maven.version>
 		<junit.version>4.8.2</junit.version>
 		<jvm.version>1.6</jvm.version>
 			<artifactId>duel-compiler</artifactId>
 			<version>${project.version}</version>
 		</dependency>
+
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+			<version>${slf4j.version}</version>
+		</dependency>
+
 		<dependency>
 			<groupId>org.apache.maven</groupId>
 			<artifactId>maven-core</artifactId>
 			<artifactId>maven-plugin-api</artifactId>
 			<version>${maven.version}</version>
 		</dependency>
+
 		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>

duel-maven-plugin/src/main/java/org/duelengine/duel/maven/DuelMojo.java

 package org.duelengine.duel.maven;
 
 import java.io.IOException;
+
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.logging.Log;
 import org.apache.maven.project.MavenProject;
-import org.duelengine.duel.compiler.*;
+import org.duelengine.duel.compiler.DuelCompiler;
 
 /**
  * Generates client-side and server-side sources
 	 */
 	private String serverPrefix;
 
+	@Override
+	public void setLog(Log log) {
+		super.setLog(log);
+
+		MavenLoggerAdapterFactory.setMavenLogger(log);
+	};
+
     public void execute()
         throws MojoExecutionException {
 
 	    Log log = this.getLog();
+
 	    log.info("\tinputDir="+this.inputDir);
 	    log.info("\toutputServerDir="+this.outputServerDir);
 

duel-maven-plugin/src/main/java/org/duelengine/duel/maven/MavenLoggerAdapter.java

+package org.duelengine.duel.maven;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugin.logging.SystemStreamLog;
+import org.slf4j.helpers.MarkerIgnoringBase;
+
+@SuppressWarnings("serial")
+public class MavenLoggerAdapter extends MarkerIgnoringBase {
+
+	private final Log log;
+
+	public MavenLoggerAdapter(String name, Log log) {
+		this.name = name;
+		this.log = (log != null) ? log : new SystemStreamLog();
+	}
+
+	protected Log getLog() {
+		return log;
+	}
+	
+	@Override
+	public void debug(String msg) {
+		getLog().debug(msg);
+	}
+
+	@Override
+	public void debug(String format, Object arg1) {
+		debug(String.format(format, arg1));
+	}
+
+	@Override
+	public void debug(String format, Object[] arg1) {
+		debug(String.format(format, arg1));
+	}
+
+	@Override
+	public void debug(String msg, Throwable t) {
+		getLog().debug(msg, t);
+	}
+
+	@Override
+	public void debug(String format, Object arg1, Object arg2) {
+		debug(String.format(format, arg1, arg2));
+	}
+
+	@Override
+	public void error(String msg) {
+		getLog().error(msg);
+	}
+
+	@Override
+	public void error(String format, Object arg1) {
+		error(String.format(format, arg1));
+	}
+
+	@Override
+	public void error(String format, Object[] arg1) {
+		error(String.format(format, arg1));
+	}
+
+	@Override
+	public void error(String msg, Throwable t) {
+		getLog().error(msg, t);
+	}
+
+	@Override
+	public void error(String format, Object arg1, Object arg2) {
+		error(String.format(format, arg1, arg2));
+	}
+
+	@Override
+	public void info(String msg) {
+		getLog().info(msg);
+	}
+
+	@Override
+	public void info(String format, Object arg1) {
+		info(String.format(format, arg1));
+	}
+
+	@Override
+	public void info(String format, Object[] arg1) {
+		info(String.format(format, arg1));
+	}
+
+	@Override
+	public void info(String msg, Throwable t) {
+		getLog().info(msg, t);
+	}
+
+	@Override
+	public void info(String format, Object arg1, Object arg2) {
+		info(String.format(format, arg1, arg2));
+	}
+
+	@Override
+	public boolean isDebugEnabled() {
+		return getLog().isDebugEnabled();
+	}
+
+	@Override
+	public boolean isErrorEnabled() {
+		return getLog().isErrorEnabled();
+	}
+
+	@Override
+	public boolean isInfoEnabled() {
+		return getLog().isInfoEnabled();
+	}
+
+	@Override
+	public boolean isTraceEnabled() {
+		return false;
+	}
+
+	@Override
+	public boolean isWarnEnabled() {
+		return getLog().isWarnEnabled();
+	}
+
+	@Override
+	public void trace(String msg) {
+		// NOOP
+	}
+
+	@Override
+	public void trace(String msg, Object arg1) {
+		// NOOP
+	}
+
+	@Override
+	public void trace(String msg, Object[] arg1) {
+		// NOOP
+	}
+
+	@Override
+	public void trace(String msg, Throwable t) {
+		// NOOP
+	}
+
+	@Override
+	public void trace(String msg, Object arg1, Object arg2) {
+		// NOOP
+	}
+
+	@Override
+	public void warn(String msg) {
+		getLog().warn(msg);
+	}
+
+	@Override
+	public void warn(String format, Object arg1) {
+		warn(String.format(format, arg1));
+	}
+
+	@Override
+	public void warn(String format, Object[] arg1) {
+		warn(String.format(format, arg1));
+	}
+
+	@Override
+	public void warn(String msg, Throwable t) {
+		getLog().warn(msg, t);
+	}
+
+	@Override
+	public void warn(String format, Object arg1, Object arg2) {
+		warn(String.format(format, arg1, arg2));
+	}
+}

duel-maven-plugin/src/main/java/org/duelengine/duel/maven/MavenLoggerAdapterFactory.java

+package org.duelengine.duel.maven;
+
+import org.apache.maven.plugin.logging.Log;
+import org.slf4j.ILoggerFactory;
+import org.slf4j.Logger;
+
+public class MavenLoggerAdapterFactory implements ILoggerFactory {
+
+	private static Log log;
+
+	static void setMavenLogger(Log log) {
+		MavenLoggerAdapterFactory.log = log;
+	}
+
+	@Override
+	public Logger getLogger(String name) {
+		return new MavenLoggerAdapter(name, log);
+	}
+}

duel-maven-plugin/src/main/java/org/slf4j/impl/StaticLoggerBinder.java

+package org.slf4j.impl;
+
+import org.duelengine.duel.maven.MavenLoggerAdapterFactory;
+import org.slf4j.ILoggerFactory;
+import org.slf4j.LoggerFactory;
+import org.slf4j.spi.LoggerFactoryBinder;
+
+/**
+ * The binding of {@link LoggerFactory} class with an actual instance of
+ * {@link ILoggerFactory} is performed using information returned by this class.
+ */
+public class StaticLoggerBinder implements LoggerFactoryBinder {
+
+	/**
+	 * The unique instance of this class.
+	 * 
+	 */
+	private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
+	
+	/**
+	 * Return the singleton of this class.
+	 * 
+	 * @return the StaticLoggerBinder singleton
+	 */
+	public static final StaticLoggerBinder getSingleton() {
+		return SINGLETON;
+	}
+
+	/**
+	 * Declare the version of the SLF4J API this implementation is compiled
+	 * against. The value of this field is usually modified with each release.
+	 */
+	// to avoid constant folding by the compiler, this field must *not* be final
+	public static String REQUESTED_API_VERSION = "1.6";	 // !final
+	
+	private static final String loggerFactoryClassStr = MavenLoggerAdapterFactory.class.getName();
+
+	/**
+	 * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
+	 * method should always be the same object
+	 */
+	private final ILoggerFactory loggerFactory;
+	
+	private StaticLoggerBinder() {
+		loggerFactory = new MavenLoggerAdapterFactory();
+	}
+	
+	public ILoggerFactory getLoggerFactory() {
+		return loggerFactory;
+	}
+	
+	public String getLoggerFactoryClassStr() {
+		return loggerFactoryClassStr;
+	}		
+}

duel-maven-plugin/src/main/java/org/slf4j/impl/StaticMDCBinder.java

+package org.slf4j.impl;
+
+import org.slf4j.helpers.NOPMDCAdapter;
+import org.slf4j.spi.MDCAdapter;
+
+/**
+ * This implementation is bound to {@link NOPMDCAdapter}.
+ */
+public class StaticMDCBinder {
+
+	/**
+	 * The unique instance of this class.
+	 */
+	public static final StaticMDCBinder SINGLETON = new StaticMDCBinder();
+
+	private StaticMDCBinder() {
+	}
+	
+	/**
+	 * Currently this method always returns an instance of 
+	 * {@link StaticMDCBinder}.
+	 */
+	public MDCAdapter getMDCA() {
+		 return new NOPMDCAdapter();
+	}
+	
+	public String	 getMDCAdapterClassStr() {
+		return NOPMDCAdapter.class.getName();
+	}
+}

duel-maven-plugin/src/main/java/org/slf4j/impl/StaticMarkerBinder.java

+package org.slf4j.impl;
+
+import org.slf4j.IMarkerFactory;
+import org.slf4j.MarkerFactory;
+import org.slf4j.helpers.BasicMarkerFactory;
+import org.slf4j.spi.MarkerFactoryBinder;
+
+/**
+ * 
+ * The binding of {@link MarkerFactory} class with an actual instance of 
+ * {@link IMarkerFactory} is performed using information returned by this class. 
+ */
+public class StaticMarkerBinder implements MarkerFactoryBinder {
+
+	/**
+	 * The unique instance of this class.
+	 */
+	public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder();
+	
+	final IMarkerFactory markerFactory = new BasicMarkerFactory();
+	
+	private StaticMarkerBinder() {
+	}
+	
+	/**
+	 * Currently this method always returns an instance of 
+	 * {@link BasicMarkerFactory}.
+	 */
+	public IMarkerFactory getMarkerFactory() {
+		return markerFactory;
+	}
+	
+	/**
+	 * Currently, this method returns the class name of
+	 * {@link BasicMarkerFactory}.
+	 */
+	public String getMarkerFactoryClassStr() {
+		return BasicMarkerFactory.class.getName();
+	}
+}

duel-runtime/pom.xml

 
 	<groupId>org.duelengine</groupId>
 	<artifactId>duel-runtime</artifactId>
-	<version>0.6.3</version>
+	<version>0.7.0</version>
 	<packaging>jar</packaging>
 
 	<name>DUEL Runtime</name>
 	<properties>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
+		<slf4j.version>1.6.4</slf4j.version>
 		<junit.version>4.8.2</junit.version>
 		<jvm.version>1.6</jvm.version>
 	</properties>
 
 	<dependencies>
 		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+			<version>${slf4j.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-jdk14</artifactId>
+			<version>${slf4j.version}</version>
+			<scope>test</scope>
+		</dependency>
+
+		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
 			<version>${junit.version}</version>

duel-runtime/src/main/java/org/duelengine/duel/CDNLinkInterceptor.java

 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.*;
-import java.util.logging.Logger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class CDNLinkInterceptor implements LinkInterceptor {
 
 			"" :
 			new URI("http", cdnHost, null, null).getRawSchemeSpecificPart();
 
-		Logger log = Logger.getLogger(CDNLinkInterceptor.class.getCanonicalName());
-		log.config("cdnHost="+this.cdnHost);
-		log.config("isDevModet="+this.isDevMode);
+		Logger log = LoggerFactory.getLogger(CDNLinkInterceptor.class);
+		log.info("cdnHost="+this.cdnHost);
+		log.info("isDevModet="+this.isDevMode);
 	}
 
 	public String transformURL(String url) {