[Arakhnę-Dev] [70] - Add more loggers.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 70
Author:   galland
Date:     2009-05-20 21:32:00 +0200 (Wed, 20 May 2009)

Log Message:
-----------
- Add more loggers.
- Add logging source.

Added Paths:
-----------
    trunk/arakhneLog4J/src/
    trunk/arakhneLog4J/src/main/
    trunk/arakhneLog4J/src/main/java/
    trunk/arakhneLog4J/src/main/java/org/
    trunk/arakhneLog4J/src/main/java/org/arakhne/
    trunk/arakhneLog4J/src/main/java/org/arakhne/logging/
    trunk/arakhneLog4J/src/main/java/org/arakhne/logging/ApacheLogger.java


Added: trunk/arakhneLog4J/src/main/java/org/arakhne/logging/ApacheLogger.java
===================================================================
--- trunk/arakhneLog4J/src/main/java/org/arakhne/logging/ApacheLogger.java	                        (rev 0)
+++ trunk/arakhneLog4J/src/main/java/org/arakhne/logging/ApacheLogger.java	2009-05-20 19:32:00 UTC (rev 70)
@@ -0,0 +1,115 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2004-2009 Stéphane GALLAND and Nicolas GAUD
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * This program is free software; you can redistribute it and/or modify
+ */
+package org.arakhne.logging;
+
+import org.apache.log4j.Level;
+
+/**
+ * This class provides the concrete implementation of the <code>Logger</code>
+ * interface. This impl is based on the Apache's Logging Facade for Java, aka.
+ * Log4J.
+ * 
+ * @author St&eacute;phane GALLAND &lt;galland@xxxxxxxxxxx&gt;
+ * @version $Name$ $Revision$ $Date$
+ * @see Logger
+ */
+public class ApacheLogger extends AbstractLogger {
+
+	private final org.apache.log4j.Logger bindedLogger;
+
+	/**
+	 * Create an unamed logger based of Apache's logging system.
+	 */
+	public ApacheLogger() {
+		this.bindedLogger = org.apache.log4j.Logger.getRootLogger();
+		this.bindedLogger.setLevel(Level.ALL);
+	}
+
+	/**
+	 * Create a named logger based of Apache's logging system.
+	 * 
+	 * @param name is the name of the logger.
+	 */
+	public ApacheLogger(String name) {
+		this.bindedLogger = org.apache.log4j.Logger.getLogger(name);
+		this.bindedLogger.setLevel(toApacheLevel(getLogLevel()));
+	}
+
+//	**************************************************************************************//
+
+	/** Translate a logging level into the same thing for Apache's logging system.
+	 * 
+	 * @param level is the level to translate
+	 * @return the Sun's level
+	 */
+	protected Level toApacheLevel(LogLevel level) {
+		switch(level) {
+		case NONE:
+			return Level.OFF;
+		case ERROR:
+			return Level.ERROR;
+		case WARNING:
+			return Level.WARN;
+		case INFO:
+			return Level.INFO;
+		case DEBUG:
+			return Level.DEBUG;
+		}
+		return Level.OFF;
+	}
+	
+	/** {@InheritDoc}
+	 */
+	@Override
+	public void log(Object source, LogLevel level, String msg) {
+		this.bindedLogger.log(toApacheLevel(level),msg);
+		fireLoggerEvent(source, level, msg);
+	}
+
+	/** {@InheritDoc}
+	 */
+	public void log(Object source, LogLevel level, String msg, Throwable exception) {
+		this.bindedLogger.log(toApacheLevel(level),msg,exception);
+		fireLoggerEvent(source, level, msg);
+	}
+
+	
+//	**************************************************************************************//	
+
+	/** {@InheritDoc}
+	 * 
+	 * @return {@InheritDoc}
+	 */
+	public String getName() {
+		return this.bindedLogger.getName();
+	}
+
+	/** Set the minimum log level.
+	 * 
+	 * @param level
+	 */
+	@Override
+	public void setLogLevel(LogLevel level) {
+		super.setLogLevel(level);
+		this.bindedLogger.setLevel(toApacheLevel(level));
+	}
+
+}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/