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

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


Revision: 66
Author:   galland
Date:     2009-05-20 21:30:40 +0200 (Wed, 20 May 2009)

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

Modified Paths:
--------------
    trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractLogger.java
    trunk/arakhneLogger/src/main/java/org/arakhne/logging/ConsoleLogger.java
    trunk/arakhneLogger/src/main/java/org/arakhne/logging/Logger.java
    trunk/arakhneLogger/src/main/java/org/arakhne/logging/LoggerEvent.java
    trunk/arakhneLogger/src/main/java/org/arakhne/logging/LoggingSystem.java
    trunk/arakhneLogger/src/main/java/org/arakhne/logging/SunLogger.java

Added Paths:
-----------
    trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractPrintStreamLogger.java
    trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractStandAloneLogger.java
    trunk/arakhneLogger/src/main/java/org/arakhne/logging/FileLogger.java
    trunk/arakhneLogger/src/main/java/org/arakhne/logging/LogLevel.java


Modified: trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractLogger.java
===================================================================
--- trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractLogger.java	2009-05-20 19:30:27 UTC (rev 65)
+++ trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractLogger.java	2009-05-20 19:30:40 UTC (rev 66)
@@ -1,7 +1,7 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2004-2008 Stéphane GALLAND and Nicolas GAUD
+ * 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
@@ -24,8 +24,8 @@
 import java.util.List;
 
 /**
- * This class provides the concrete implementation of the <code>Logger</code>
- * interface. This impl is based on the Sun's Logging Facade for Java
+ * This class provides the base for a concrete implementation of the <code>Logger</code>
+ * interface.
  * 
  * @author St&eacute;phane GALLAND &lt;galland@xxxxxxxxxxx&gt;
  * @version $Name$ $Revision$ $Date$
@@ -71,13 +71,15 @@
 	 * @param arg0 {@InheritDoc}
 	 * @param arg1 {@InheritDoc}
 	 */
+	@Deprecated
 	public final void debug(String arg0, Throwable arg1) {
-		log(LogLevel.DEBUG,arg0,arg1);
+		log(this,LogLevel.DEBUG,arg0,arg1);
 	}
 
 	/** 
 	 * {@inheritDoc}
 	 */
+	@Deprecated
 	public final void debug(String arg0) {
 		log(LogLevel.DEBUG,arg0);
 	}
@@ -85,47 +87,131 @@
 	/** 
 	 * {@inheritDoc}
 	 */
+	@Deprecated
 	public final void error(String arg0, Throwable arg1) {
-		log(LogLevel.ERROR,arg0,arg1);
+		log(this,LogLevel.ERROR,arg0,arg1);
 	}
 
 	/** 
 	 * {@inheritDoc}
 	 */
+	@Deprecated
 	public final void error(String arg0) {
-		log(LogLevel.ERROR,arg0);
+		log(this,LogLevel.ERROR,arg0);
 	}
 
 	/** 
 	 * {@inheritDoc}
 	 */
+	@Deprecated
 	public final void info(String arg0, Throwable arg1) {
-		log(LogLevel.INFO,arg0,arg1);
+		log(this,LogLevel.INFO,arg0,arg1);
 	}
 
 	/** 
 	 * {@inheritDoc}
 	 */
+	@Deprecated
 	public final void info(String arg0) {
-		log(LogLevel.INFO,arg0);
+		log(this,LogLevel.INFO,arg0);
 	}
 
 	/** 
 	 * {@inheritDoc}
 	 */
+	@Deprecated
 	public final void warn(String arg0, Throwable arg1) {
-		log(LogLevel.WARNING,arg0,arg1);
+		log(this,LogLevel.WARNING,arg0,arg1);
 	}
 
 	/** 
 	 * {@inheritDoc}
 	 */
+	@Deprecated
 	public final void warn(String arg0) {
-		log(LogLevel.WARNING,arg0);
+		log(this,LogLevel.WARNING,arg0);
 	}
 
 	/** {@InheritDoc}
 	 * 
+	 * @param level {@InheritDoc}
+	 * @param msg {@InheritDoc}
+	 */
+	@Deprecated
+	public final void log(LogLevel level, String msg) {
+		log(this, level, msg, null);
+	}
+
+	/** {@InheritDoc}
+	 */
+	@Deprecated
+	public final void log(LogLevel level, String msg, Throwable exception) {
+		log(this,level,msg,exception);
+	}
+
+	/** {@InheritDoc}
+	 */
+	public final void debug(Object source, String arg0, Throwable arg1) {
+		log(source,LogLevel.DEBUG,arg0,arg1);
+	}
+
+	/** 
+	 * {@inheritDoc}
+	 */
+	public final void debug(Object source, String arg0) {
+		log(source, LogLevel.DEBUG,arg0);
+	}
+
+	/** 
+	 * {@inheritDoc}
+	 */
+	public final void error(Object source, String arg0, Throwable arg1) {
+		log(source,LogLevel.ERROR,arg0,arg1);
+	}
+
+	/** 
+	 * {@inheritDoc}
+	 */
+	public final void error(Object source, String arg0) {
+		log(source,LogLevel.ERROR,arg0);
+	}
+
+	/** 
+	 * {@inheritDoc}
+	 */
+	public final void info(Object source, String arg0, Throwable arg1) {
+		log(source,LogLevel.INFO,arg0,arg1);
+	}
+
+	/** 
+	 * {@inheritDoc}
+	 */
+	public final void info(Object source, String arg0) {
+		log(source,LogLevel.INFO,arg0);
+	}
+
+	/** 
+	 * {@inheritDoc}
+	 */
+	public final void warn(Object source, String arg0, Throwable arg1) {
+		log(source,LogLevel.WARNING,arg0,arg1);
+	}
+
+	/** 
+	 * {@inheritDoc}
+	 */
+	public final void warn(Object source, String arg0) {
+		log(source,LogLevel.WARNING,arg0);
+	}
+
+	/** {@InheritDoc}
+	 */
+	public void log(Object source, LogLevel level, String msg) {
+		log(source, level, msg, null);
+	}
+
+	/** {@InheritDoc}
+	 * 
 	 * @return {@InheritDoc}
 	 */
 	public boolean isDebugEnabled() {
@@ -181,21 +267,23 @@
 	
 	/** Notify the logger event listeners.
 	 * 
+	 * @param source is the object which has log the message.
 	 * @param level is the level of the message
 	 * @param message is the text of the message.
 	 */
-	protected final void fireLoggerEvent(LogLevel level, String message) {
-		fireLoggerEvent(level, message, null);
+	protected final void fireLoggerEvent(Object source, LogLevel level, String message) {
+		fireLoggerEvent(source, level, message, null);
 	}
 	
 	/** Notify the logger event listeners.
 	 * 
+	 * @param source is the object which has log the message.
 	 * @param level is the level of the message
 	 * @param message is the text of the message.
 	 * @param exception is the exception associated to the message.
 	 */
-	protected final void fireLoggerEvent(LogLevel level, String message, Throwable exception) {
-		LoggerEvent event = new LoggerEvent(this, level, message, exception);
+	protected final void fireLoggerEvent(Object source, LogLevel level, String message, Throwable exception) {
+		LoggerEvent event = new LoggerEvent(source, this, level, message, exception);
 		if (this.listeners!=null) {
 			for(LoggerEventListener listener : this.listeners) {
 				listener.onLoggedEvent(event);
@@ -204,14 +292,4 @@
 		LoggingSystem.getLoggingSystem().fireLoggerEvent(event);
 	}
 
-	/** {@InheritDoc}
-	 * 
-	 * @param level {@InheritDoc}
-	 * @param msg {@InheritDoc}
-	 */
-	public void log(LogLevel level, String msg) {
-		log(level, msg, null);
-	}
-
-
 }

Added: trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractPrintStreamLogger.java
===================================================================
--- trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractPrintStreamLogger.java	                        (rev 0)
+++ trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractPrintStreamLogger.java	2009-05-20 19:30:40 UTC (rev 66)
@@ -0,0 +1,96 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2009 St&eacute;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 java.io.PrintStream;
+
+/**
+ * This class provides the base for a concrete implementation of the <code>Logger</code>
+ * interface. This logger impl contains the minimal knowledge required to implement
+ * loggers which are writing inside a print stream.
+ * 
+ * @author St&eacute;phane GALLAND &lt;galland@xxxxxxxxxxx&gt;
+ * @version $Name$ $Revision$ $Date$
+ * @see Logger
+ */
+public abstract class AbstractPrintStreamLogger extends AbstractStandAloneLogger {
+
+	/** Output print stream for anomalies.
+	 */
+	protected final PrintStream anomalyStream;
+	
+	/** Output print stream for messages.
+	 */
+	protected final PrintStream noticeStream;
+
+	/**
+	 * Unamed Logger on system console.
+	 * 
+	 * @param anomalyStream is the output stream inside which anomaly logs will be put.
+	 * @param noticeStream is the output stream inside which notice logs will be put.
+	 */
+	public AbstractPrintStreamLogger(PrintStream anomalyStream, PrintStream noticeStream) {
+		this.anomalyStream = anomalyStream;
+		this.noticeStream = noticeStream;
+	}
+
+	/**
+	 * Named Logger on system console.
+	 * 
+	 * @param anomalyStream is the output stream inside which anomaly logs will be put.
+	 * @param noticeStream is the output stream inside which notice logs will be put.
+	 * @param name is the name of the logger.
+	 */
+	public AbstractPrintStreamLogger(PrintStream anomalyStream, PrintStream noticeStream, String name) {
+		super(name);
+		this.anomalyStream = anomalyStream;
+		this.noticeStream = noticeStream;
+	}
+
+	/** {@InheritDoc}
+	 */
+	public void log(Object source, LogLevel level, String msg, Throwable exception) {
+		if (isLoggableFor(level)) {
+			
+			StringBuffer buffer = new StringBuffer();
+			
+			if (this.name!=null) {
+				buffer.append("["); //$NON-NLS-1$
+				buffer.append(this.name);
+				buffer.append("] - "); //$NON-NLS-1$
+			}
+			buffer.append(getLocalizedString(level));
+			buffer.append(": "); //$NON-NLS-1$
+			buffer.append(msg);
+			
+			PrintStream ps = level.isAnomalyLevel() ? this.anomalyStream : this.noticeStream;
+
+			ps.println(buffer.toString());
+			
+			if (exception!=null) {
+				exception.printStackTrace(ps);
+			}
+
+			fireLoggerEvent(source, level, msg);
+		}
+	}
+
+}

Added: trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractStandAloneLogger.java
===================================================================
--- trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractStandAloneLogger.java	                        (rev 0)
+++ trunk/arakhneLogger/src/main/java/org/arakhne/logging/AbstractStandAloneLogger.java	2009-05-20 19:30:40 UTC (rev 66)
@@ -0,0 +1,124 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2009 St&eacute;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 java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * This class provides the base for a concrete implementation of the <code>Logger</code>
+ * interface. This logger impl is not wrapped to a third-party logger (Sun nor Apache
+ * for example). It contains the minimal knowledge required to implement
+ * not-wrapped loggers.
+ * 
+ * @author St&eacute;phane GALLAND &lt;galland@xxxxxxxxxxx&gt;
+ * @version $Name$ $Revision$ $Date$
+ * @see Logger
+ */
+public abstract class AbstractStandAloneLogger extends AbstractLogger {
+
+	private static String errorLabel = null;
+	private static String warningLabel = null;
+	private static String infoLabel = null;
+	private static String debugLabel = null;
+	
+	/** Replies the label which is corresponding to the given log level.
+	 * 
+	 * @param level
+	 * @return the localized label which is corresponding to the given log level.
+	 */
+	protected static String getLocalizedString(LogLevel level) {
+		switch (level) {
+		case NONE:
+			return null;
+		case DEBUG:
+			if (debugLabel!=null) return debugLabel;
+			break;
+		case WARNING:
+			if (warningLabel!=null) return warningLabel;
+			break;
+		case ERROR:
+			if (errorLabel!=null) return errorLabel;
+			break;
+		case INFO:
+			if (infoLabel!=null) return infoLabel;
+			break;
+		}
+
+		String name = level.name().toUpperCase();
+		
+        try {
+        	ResourceBundle resource = ResourceBundle.getBundle(AbstractStandAloneLogger.class.getCanonicalName());
+        	String str = resource.getString(name);
+        	if ((str!=null)&&(!"".equals(str))) //$NON-NLS-1$
+        		name = str;
+        }
+        catch (MissingResourceException exep) {
+            //
+        }
+		
+		switch (level) {
+		case NONE:
+			return null;
+		case DEBUG:
+			debugLabel = name;
+			break;
+		case WARNING:
+			warningLabel = name;
+			break;
+		case ERROR:
+			errorLabel = name;
+			break;
+		case INFO:
+			infoLabel = name;
+			break;
+		}
+		
+		return name;
+	}
+
+	/** Name of this logger.
+	 */
+	protected final String name;
+	
+	/**
+	 * Unamed Logger on system console.
+	 */
+	public AbstractStandAloneLogger() {
+		this.name = null;
+	}
+
+	/**
+	 * Named Logger on system console.
+	 * 
+	 * @param name is the name of the logger.
+	 */
+	public AbstractStandAloneLogger(String name) {
+		this.name = name;
+	}
+
+	/** {@InheritDoc}
+	 */
+	public String getName() {
+		return this.name;
+	}
+
+}

Modified: trunk/arakhneLogger/src/main/java/org/arakhne/logging/ConsoleLogger.java
===================================================================
--- trunk/arakhneLogger/src/main/java/org/arakhne/logging/ConsoleLogger.java	2009-05-20 19:30:27 UTC (rev 65)
+++ trunk/arakhneLogger/src/main/java/org/arakhne/logging/ConsoleLogger.java	2009-05-20 19:30:40 UTC (rev 66)
@@ -1,7 +1,7 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2004-2008 St&eacute;phane GALLAND and Nicolas GAUD
+ * Copyright (C) 2004-2009 St&eacute;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
@@ -20,9 +20,6 @@
  */
 package org.arakhne.logging;
 
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
 /**
  * This class provides the concrete implementation of the <code>Logger</code>
  * interface. This impl is displaying on the standard output.
@@ -31,70 +28,13 @@
  * @version $Name$ $Revision$ $Date$
  * @see Logger
  */
-public class ConsoleLogger extends AbstractLogger {
+public class ConsoleLogger extends AbstractPrintStreamLogger {
 
-	private final String name;
-	
-	private static String errorLabel = null;
-	private static String warningLabel = null;
-	private static String infoLabel = null;
-	private static String debugLabel = null;
-	
-	private static String getString(LogLevel level) {
-		switch (level) {
-		case NONE:
-			return null;
-		case DEBUG:
-			if (debugLabel!=null) return debugLabel;
-			break;
-		case WARNING:
-			if (warningLabel!=null) return warningLabel;
-			break;
-		case ERROR:
-			if (errorLabel!=null) return errorLabel;
-			break;
-		case INFO:
-			if (infoLabel!=null) return infoLabel;
-			break;
-		}
-
-		String name = level.name().toUpperCase();
-		
-        try {
-        	ResourceBundle resource = ResourceBundle.getBundle(ConsoleLogger.class.getCanonicalName());
-        	String str = resource.getString(name);
-        	if ((str!=null)&&(!"".equals(str))) //$NON-NLS-1$
-        		name = str;
-        }
-        catch (MissingResourceException exep) {
-            //
-        }
-		
-		switch (level) {
-		case NONE:
-			return null;
-		case DEBUG:
-			debugLabel = name;
-			break;
-		case WARNING:
-			warningLabel = name;
-			break;
-		case ERROR:
-			errorLabel = name;
-			break;
-		case INFO:
-			infoLabel = name;
-			break;
-		}
-		
-		return name;
-	}
-
 	/**
 	 * Unamed Logger on system console.
 	 */
 	public ConsoleLogger() {
-		this.name = null;
+		super(System.err, System.out);
 	}
 
 	/**
@@ -103,49 +43,7 @@
 	 * @param name is the name of the logger.
 	 */
 	public ConsoleLogger(String name) {
-		this.name = name;
+		super(System.err, System.out, name);
 	}
 
-//	**************************************************************************************//
-	
-	/** {@InheritDoc}
-	 * 
-	 * @param level {@InheritDoc}
-	 * @param msg {@InheritDoc}
-	 * @param exception {@InheritDoc}
-	 */
-	public void log(LogLevel level, String msg, Throwable exception) {
-		if (isLoggableFor(level)) {
-			
-			StringBuffer buffer = new StringBuffer();
-			
-			if (this.name!=null) {
-				buffer.append("["); //$NON-NLS-1$
-				buffer.append(this.name);
-				buffer.append("] - "); //$NON-NLS-1$
-			}
-			buffer.append(getString(level));
-			buffer.append(": "); //$NON-NLS-1$
-			buffer.append(msg);
-			
-			System.out.println(buffer.toString());
-			
-			if (exception!=null)
-				exception.printStackTrace();
-
-			fireLoggerEvent(level, msg);
-		}
-	}
-
-	
-//	**************************************************************************************//	
-
-	/** {@InheritDoc}
-	 * 
-	 * @return {@InheritDoc}
-	 */
-	public String getName() {
-		return this.name;
-	}
-
 }

Added: trunk/arakhneLogger/src/main/java/org/arakhne/logging/FileLogger.java
===================================================================
--- trunk/arakhneLogger/src/main/java/org/arakhne/logging/FileLogger.java	                        (rev 0)
+++ trunk/arakhneLogger/src/main/java/org/arakhne/logging/FileLogger.java	2009-05-20 19:30:40 UTC (rev 66)
@@ -0,0 +1,75 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2009 St&eacute;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 java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+/**
+ * This class provides the concrete implementation of the <code>Logger</code>
+ * interface. This impl is writting inside a file.
+ * 
+ * @author St&eacute;phane GALLAND &lt;galland@xxxxxxxxxxx&gt;
+ * @version $Name$ $Revision$ $Date$
+ * @see Logger
+ */
+public class FileLogger extends AbstractPrintStreamLogger {
+
+	private final File logFile;
+	
+	/**
+	 * Unamed Logger on system console.
+	 * 
+	 * @param logFile is the log file to write inside.
+	 */
+	public FileLogger(File logFile) throws IOException {
+		this(logFile, new PrintStream(new FileOutputStream(logFile)));
+	}
+
+	/**
+	 * Named Logger on system console.
+	 * 
+	 * @param logFile is the log file to write inside.
+	 * @param name is the name of the logger.
+	 */
+	public FileLogger(File logFile, String name) throws IOException {
+		this(logFile, new PrintStream(new FileOutputStream(logFile)), name);
+	}
+
+	private FileLogger(File logFile, PrintStream logStream) {
+		super(logStream, logStream);
+		this.logFile = logFile;
+	}
+
+	private FileLogger(File logFile, PrintStream logStream, String name) {
+		super(logStream, logStream, name);
+		this.logFile = logFile;
+	}
+
+	/** Replies the log file which is written by this logger.
+	 */
+	public File getLogFile() {
+		return this.logFile;
+	}
+
+}

Added: trunk/arakhneLogger/src/main/java/org/arakhne/logging/LogLevel.java
===================================================================
--- trunk/arakhneLogger/src/main/java/org/arakhne/logging/LogLevel.java	                        (rev 0)
+++ trunk/arakhneLogger/src/main/java/org/arakhne/logging/LogLevel.java	2009-05-20 19:30:40 UTC (rev 66)
@@ -0,0 +1,72 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2004-2009 St&eacute;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;
+
+/**
+ * The enum describing the various available log levels.
+ * 
+ * @author Nicolas GAUD &lt;gaud@xxxxxxxxxxx&gt;
+ * @author St&eacute;phane GALLAND &lt;galland@xxxxxxxxxxx&gt;
+ * @version $Name$ $Revision$ $Date$
+ */	
+public enum LogLevel {
+	/**
+	 * No logging.
+	 */
+	NONE,
+	/**
+	 * Error message Level.
+	 */
+	ERROR,
+	/**
+	 * Warning message Level.
+	 */
+	WARNING,
+	/**
+	 * Information message Level.
+	 */
+	INFO,
+	/**
+	 * Debug message Level.
+	 */
+	DEBUG;
+
+	/** Check if logging is allowed.
+	 * This function check if the current log level has a priority
+	 * greater or equals to the given log level.
+	 * 
+	 * @param referenceLogLevel is the level to check.
+	 * @return <code>true</code> if logging is allowed, <code>false</code> otherwise
+	 */
+	public boolean hasHigherPriority(LogLevel referenceLogLevel) {
+		return ordinal()>0 && ordinal()<=referenceLogLevel.ordinal();
+	}	
+	
+	/** Replies if this log level is for anomalies.
+	 * 
+	 * @return <code>true</code> if this log level is an error or a warning,
+	 * otherwise <code>false</code>.
+	 */
+	public boolean isAnomalyLevel() {
+		return this==ERROR || this==WARNING;
+	}
+
+}

Modified: trunk/arakhneLogger/src/main/java/org/arakhne/logging/Logger.java
===================================================================
--- trunk/arakhneLogger/src/main/java/org/arakhne/logging/Logger.java	2009-05-20 19:30:27 UTC (rev 65)
+++ trunk/arakhneLogger/src/main/java/org/arakhne/logging/Logger.java	2009-05-20 19:30:40 UTC (rev 66)
@@ -1,7 +1,7 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2004-2008 St&eacute;phane GALLAND and Nicolas GAUD
+ * Copyright (C) 2004-2009 St&eacute;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
@@ -34,47 +34,6 @@
 public interface Logger {
 
 	/**
-	 * The enum describing the various available log levels.
-	 * 
-	 * @author Nicolas GAUD &lt;nicolas.gaud@xxxxxxx&gt;
-	 * @version $Name$ $Revision$ $Date$
-	 */	
-	public static enum LogLevel {
-		/**
-		 * No logging.
-		 */
-		NONE,
-		/**
-		 * Error message Level.
-		 */
-		ERROR,
-		/**
-		 * Warning message Level.
-		 */
-		WARNING,
-		/**
-		 * Information message Level.
-		 */
-		INFO,
-		/**
-		 * Debug message Level.
-		 */
-		DEBUG;
-
-		/** Check if logging is allowed.
-		 * This function check if the current log level has a priority
-		 * greater or equals to the given log level.
-		 * 
-		 * @param referenceLogLevel is the level to check.
-		 * @return <code>true</code> if logging is allowed, <code>false</code> otherwise
-		 */
-		public boolean hasHigherPriority(LogLevel referenceLogLevel) {
-			return ordinal()>0 && ordinal()<=referenceLogLevel.ordinal();
-		}	
-
-	}
-
-	/**
 	 * Return the name of this <code>Logger</code> instance.
 	 * 
 	 * @return the name of this <code>Logger</code> instance.
@@ -94,35 +53,84 @@
 	 * 
 	 * @param level - the log level
 	 * @param msg - the message to log
+	 * @deprecated see {@link #log(Object, LogLevel, String)}
 	 */
+	@Deprecated
 	public void log(LogLevel level, String msg);
 
 	/**
 	 * Log the specified message at the specified level
 	 * 
+	 * @param source - the object which send this log
 	 * @param level - the log level
 	 * @param msg - the message to log
+	 * @since 1.2
+	 */
+	public void log(Object source, LogLevel level, String msg);
+
+	/**
+	 * Log the specified message at the specified level
+	 * 
+	 * @param level - the log level
+	 * @param msg - the message to log
 	 * @param exception - the exception cause of the log message
+	 * @deprecated see {@link #log(Object, LogLevel, String, Throwable)}
 	 */
+	@Deprecated
 	public void log(LogLevel level, String msg, Throwable exception);
 
 	/**
+	 * Log the specified message at the specified level
+	 * 
+	 * @param source - the object which send this log
+	 * @param level - the log level
+	 * @param msg - the message to log
+	 * @param exception - the exception cause of the log message
+	 * @since 1.2
+	 */
+	public void log(Object source, LogLevel level, String msg, Throwable exception);
+
+	/**
 	 * Log a message at the DEBUG level.
 	 *
 	 * @param msg the message string to be logged
+	 * @deprecated see {@link #debug(Object, String)}
 	 */
+	@Deprecated
 	public void debug(String msg);
 
 	/**
+	 * Log a message at the DEBUG level.
+	 *
+	 * @param source - the object which send this log
+	 * @param msg the message string to be logged
+	 * @since 1.2
+	 */
+	public void debug(Object source, String msg);
+
+	/**
 	 * Log an exception (throwable) at the DEBUG level with an
 	 * accompanying message. 
 	 * 
 	 * @param msg the message accompanying the exception
 	 * @param t the exception (throwable) to log
+	 * @deprecated see {@link #debug(Object, String, Throwable)}
 	 */ 
+	@Deprecated
 	public void debug(String msg, Throwable t);
 
 	/**
+	 * Log an exception (throwable) at the DEBUG level with an
+	 * accompanying message. 
+	 * 
+	 * @param source - the object which send this log
+	 * @param msg the message accompanying the exception
+	 * @param t the exception (throwable) to log
+	 * @since 1.2
+	 */ 
+	public void debug(Object source, String msg, Throwable t);
+
+	/**
 	 * Is the logger instance enabled for the INFO level?
 	 * 
 	 * @return <code>true</code> if this Logger is enabled for the INFO level,
@@ -135,19 +143,43 @@
 	 * Log a message at the INFO level.
 	 *
 	 * @param msg the message string to be logged
+	 * @deprecated see {@link #info(Object, String)}
 	 */
+	@Deprecated
 	public void info(String msg);
 
 	/**
+	 * Log a message at the INFO level.
+	 *
+	 * @param source - the object which send this log
+	 * @param msg the message string to be logged
+	 * @since 1.2
+	 */
+	public void info(Object source, String msg);
+
+	/**
 	 * Log an exception (throwable) at the INFO level with an
 	 * accompanying message. 
 	 * 
 	 * @param msg the message accompanying the exception
 	 * @param t the exception (throwable) to log 
+	 * @deprecated see {@link #info(Object, String, Throwable)}
 	 */
+	@Deprecated
 	public void info(String msg, Throwable t);
 
 	/**
+	 * Log an exception (throwable) at the INFO level with an
+	 * accompanying message. 
+	 * 
+	 * @param source - the object which send this log
+	 * @param msg the message accompanying the exception
+	 * @param t the exception (throwable) to log
+	 * @since 1.2 
+	 */
+	public void info(Object source, String msg, Throwable t);
+
+	/**
 	 * Is the logger instance enabled for the WARN level?
 	 * 
 	 * @return <code>true</code> if this Logger is enabled for the WARN level,
@@ -159,19 +191,43 @@
 	 * Log a message at the WARN level.
 	 *
 	 * @param msg the message string to be logged
+	 * @deprecated see {@link #warn(Object, String)}
 	 */
+	@Deprecated
 	public void warn(String msg);
 
 	/**
+	 * Log a message at the WARN level.
+	 *
+	 * @param source - the object which send this log
+	 * @param msg the message string to be logged
+	 * @since 1.2
+	 */
+	public void warn(Object source, String msg);
+
+	/**
 	 * Log an exception (throwable) at the WARN level with an
 	 * accompanying message. 
 	 * 
 	 * @param msg the message accompanying the exception
 	 * @param t the exception (throwable) to log 
+	 * @deprecated see {@link #warn(Object, String, Throwable)}
 	 */
+	@Deprecated
 	public void warn(String msg, Throwable t);
 
 	/**
+	 * Log an exception (throwable) at the WARN level with an
+	 * accompanying message. 
+	 * 
+	 * @param source - the object which send this log
+	 * @param msg the message accompanying the exception
+	 * @param t the exception (throwable) to log
+	 * @since 1.2 
+	 */
+	public void warn(Object source, String msg, Throwable t);
+
+	/**
 	 * Is the logger instance enabled for the ERROR level?
 	 * 
 	 * @return <code>true</code> if this Logger is enabled for the ERROR level,
@@ -183,18 +239,42 @@
 	 * Log a message at the ERROR level.
 	 *
 	 * @param msg the message string to be logged
+	 * @deprecated see {@link #error(Object, String)}
 	 */
+	@Deprecated
 	public void error(String msg);
 
 	/**
+	 * Log a message at the ERROR level.
+	 *
+	 * @param source - the object which send this log
+	 * @param msg the message string to be logged
+	 * @since 1.2
+	 */
+	public void error(Object source, String msg);
+
+	/**
 	 * Log an exception (throwable) at the ERROR level with an
 	 * accompanying message. 
 	 * 
 	 * @param msg the message accompanying the exception
 	 * @param t the exception (throwable) to log
+	 * @deprecated see {@link #error(Object, String, Throwable)}
 	 */
+	@Deprecated
 	public void error(String msg, Throwable t);
 	
+	/**
+	 * Log an exception (throwable) at the ERROR level with an
+	 * accompanying message. 
+	 * 
+	 * @param source - the object which send this log
+	 * @param msg the message accompanying the exception
+	 * @param t the exception (throwable) to log
+	 * @since 1.2
+	 */
+	public void error(Object source, String msg, Throwable t);
+
 	/** Set the minimum log level.
 	 * 
 	 * @param level

Modified: trunk/arakhneLogger/src/main/java/org/arakhne/logging/LoggerEvent.java
===================================================================
--- trunk/arakhneLogger/src/main/java/org/arakhne/logging/LoggerEvent.java	2009-05-20 19:30:27 UTC (rev 65)
+++ trunk/arakhneLogger/src/main/java/org/arakhne/logging/LoggerEvent.java	2009-05-20 19:30:40 UTC (rev 66)
@@ -1,7 +1,7 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2004-2008 St&eacute;phane GALLAND and Nicolas GAUD
+ * Copyright (C) 2004-2009 St&eacute;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
@@ -22,8 +22,6 @@
 
 import java.util.EventObject;
 
-import org.arakhne.logging.Logger.LogLevel;
-
 /**
  * This class provides a description of a logging event.
  * 
@@ -33,37 +31,51 @@
  */
 public class LoggerEvent extends EventObject {
 
-	private static final long serialVersionUID = 6781328201390477344L;
+	private static final long serialVersionUID = -272287628530037390L;
 	
+	private final Logger logger;
 	private final LogLevel level;
 	private final String message;
 	private final Throwable exception;
 	
 	/**
-	 * @param logger is the object which had fired the event.
-	 * @param level is the level of the message
+	 * @param source is the source of the event.
+	 * @param logger is the logger which has received the message.
+	 * @param level is the level of the message.
 	 * @param message is the text of the message.
 	 */
-	public LoggerEvent(Logger logger, LogLevel level, String message) {
-		super(logger);
+	public LoggerEvent(Object source, Logger logger, LogLevel level, String message) {
+		super(source);
+		this.logger = logger;
 		this.level = level;
 		this.message = message;
 		this.exception = null;
 	}
 	
 	/**
-	 * @param logger is the object which had fired the event.
+	 * @param source is the source of the event.
+	 * @param logger is the logger which has received the message.
 	 * @param level is the level of the message
 	 * @param message is the text of the message.
 	 * @param exception is the exception associated to the message.
 	 */
-	public LoggerEvent(Logger logger, LogLevel level, String message, Throwable exception) {
-		super(logger);
+	public LoggerEvent(Object source, Logger logger, LogLevel level, String message, Throwable exception) {
+		super(source);
+		this.logger = logger;
 		this.level = level;
 		this.message = message;
 		this.exception = exception;
 	}
 	
+	/** Replies the logger which has received the event.
+	 * 
+	 * @return the logger which as receivd the log.
+	 * @since 1.2
+	 */
+	public Logger getLogger() {
+		return this.logger;
+	}
+
 	/** Replies the log level of the event.
 	 * 
 	 * @return the log level of the event.

Modified: trunk/arakhneLogger/src/main/java/org/arakhne/logging/LoggingSystem.java
===================================================================
--- trunk/arakhneLogger/src/main/java/org/arakhne/logging/LoggingSystem.java	2009-05-20 19:30:27 UTC (rev 65)
+++ trunk/arakhneLogger/src/main/java/org/arakhne/logging/LoggingSystem.java	2009-05-20 19:30:40 UTC (rev 66)
@@ -26,10 +26,6 @@
 import java.util.Map;
 import java.util.TreeMap;
 
-import org.arakhne.logging.Logger.LogLevel;
-
-
-
 /** This interface describes the body of an situated agent.
  * The body is the only available interaction mean between
  * an agent and the environment.

Modified: trunk/arakhneLogger/src/main/java/org/arakhne/logging/SunLogger.java
===================================================================
--- trunk/arakhneLogger/src/main/java/org/arakhne/logging/SunLogger.java	2009-05-20 19:30:27 UTC (rev 65)
+++ trunk/arakhneLogger/src/main/java/org/arakhne/logging/SunLogger.java	2009-05-20 19:30:40 UTC (rev 66)
@@ -1,7 +1,7 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2004-2008 St&eacute;phane GALLAND and Nicolas GAUD
+ * Copyright (C) 2004-2009 St&eacute;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
@@ -76,25 +76,18 @@
 	}
 	
 	/** {@InheritDoc}
-	 * 
-	 * @param level {@InheritDoc}
-	 * @param msg {@InheritDoc}
 	 */
 	@Override
-	public void log(LogLevel level, String msg) {
+	public void log(Object source, LogLevel level, String msg) {
 		this.bindedLogger.log(toSunLevel(level),msg);
-		fireLoggerEvent(level, msg);
+		fireLoggerEvent(source, level, msg);
 	}
 
 	/** {@InheritDoc}
-	 * 
-	 * @param level {@InheritDoc}
-	 * @param msg {@InheritDoc}
-	 * @param exception {@InheritDoc}
 	 */
-	public void log(LogLevel level, String msg, Throwable exception) {
+	public void log(Object source, LogLevel level, String msg, Throwable exception) {
 		this.bindedLogger.log(toSunLevel(level),msg,exception);
-		fireLoggerEvent(level, msg);
+		fireLoggerEvent(source, level, msg);
 	}
 
 	


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