X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=source%2Fmir%2Flog%2Flog4j%2FLoggerImpl.java;h=6f3b5add2ffe6e0303997786be03f60cceba63db;hb=HEAD;hp=298a6d92e546d7c5d8fb19bd0f2fce41bb21f72e;hpb=31c1bb88255dbb42eba30f0e016e07161eb6f2a2;p=mir.git diff --git a/source/mir/log/log4j/LoggerImpl.java b/source/mir/log/log4j/LoggerImpl.java index 298a6d92..6f3b5add 100755 --- a/source/mir/log/log4j/LoggerImpl.java +++ b/source/mir/log/log4j/LoggerImpl.java @@ -1,57 +1,130 @@ +/* + * Copyright (C) 2005 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License. + * You must obey the GNU General Public License in all respects for all of the code used + * other than the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. + */ package mir.log.log4j; -import org.apache.log4j.PropertyConfigurator; -import org.apache.log4j.Logger; - -import java.util.Map; import java.util.HashMap; +import java.util.Map; + +import mir.config.MirPropertiesConfiguration; +import mir.log.LoggerExc; +import mir.log.LoggerFailure; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; public class LoggerImpl implements mir.log.Logger { + private static final Map loggers = new HashMap(); - private static Map loggers = new HashMap(); + public LoggerImpl() throws LoggerExc { + reload(); + } - public LoggerImpl() { - PropertyConfigurator.configure("log4j.properties"); - } + /** {@inheritDoc} */ + public void debug(Object o, String s) { + this.getLogger(o).debug(s); + } + /** {@inheritDoc} */ + public void info(Object o, String s) { + this.getLogger(o).info(s); + } - public void debug( Object o, String s ) { - this.getLogger(o).debug(s); - } + /** {@inheritDoc} */ + public void warn(Object o, String s) { + this.getLogger(o).warn(s); + } - public void info( Object o, String s ) { - this.getLogger(o).info(s); - } + /** {@inheritDoc} */ + public void warn(Object o, String s, Throwable anException) { + this.getLogger(o).warn(s, anException); + } - public void warn( Object o, String s ) { - this.getLogger(o).warn(s); - } + /** {@inheritDoc} */ + public void error(Object o, String s) { + this.getLogger(o).error(s); + } - public void error( Object o, String s ) { - this.getLogger(o).error(s); - } + /** {@inheritDoc} */ + public void error(Object o, String s, Throwable anException) { + this.getLogger(o).error(s, anException); + } + + /** {@inheritDoc} */ + public void fatal(Object o, String s) { + this.getLogger(o).fatal(s); + } - public void fatal( Object o, String s ) { - this.getLogger(o).fatal(s); + /** {@inheritDoc} */ + public void reload() throws LoggerExc, LoggerFailure { + try { + synchronized (loggers) { + System.setProperty("log.home", + MirPropertiesConfiguration.instance().getFile("Log.Home").getAbsolutePath()); + + PropertyConfigurator.configure( + MirPropertiesConfiguration.instance().getFile("Log.log4j.ConfigurationFile").getAbsolutePath()); + + loggers.clear(); + } + } + catch (Throwable t) { + throw new LoggerFailure(t); } + } + private Logger getLogger(Object o) { + String name; + Logger l; - private Logger getLogger( Object o ) { - String name; - if (o instanceof Class) { - name = ((Class)o).getName(); - } else if (o!=null) { - name = o.getClass().getName(); - } else { - name = "generic"; - } + if (o instanceof String) { + name = (String) o; + } + else if (o instanceof Class) { + name = ( (Class) o).getName(); + } + else if (o != null) { + name = o.getClass().getName(); + } + else { + name = "generic"; + } - Logger l = (Logger)loggers.get(name); - if (l==null) { - l = Logger.getLogger(name); - loggers.put(name, l); + synchronized (loggers) { + l = (Logger) loggers.get(name); + if (l == null) { + if (!loggers.containsKey(name)) { + l = Logger.getLogger(name); + loggers.put(name, l); } - return l; + l = (Logger) loggers.get(name); + } } + + return l; + } } \ No newline at end of file