Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH . All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: s IT Solutions AT Spardat GmbH - initial API and implementation /
 
 
 /*
  * Created on : 25.06.2003
  * Created by : s3595
  */
 package at.spardat.xma.boot.logger;
 
 
LogManager

Author(s):
s3595 (CGS)
Version:
$Id: LogManager.java 2084 2007-11-27 14:53:31Z s3460 $
 
 public class LogManager {
 
     /* The global LogManager object */
     private static LogManager manager;
 
     /* default and fallback loglevel */
     private final static LogLevel defaultLevel = .;
 
     /* current active log level */
     private LogLevel currentLogLevel;
 
     /* Table of known loggers.  Maps names to Loggers. */
     private Hashtable loggers = new Hashtable();
 
     /* configuration properties */
     private Properties props;
 
     /* default log handler */
     private ILogHandler defaultHandler = new LogHandlerDefault();
 
 
     /* log handlers */
     private ArrayList handlers = new ArrayList(3);
 
     static {
         if ( == null) {
              = new LogManager();
         }
     }

    
It is intended that there only be one LogManager object, whose value is retrieved by calling Logmanager.getLogManager.
 
     protected LogManager() {
          = ;
         .add();
     }

    
Return the global LogManager object.
 
     public static LogManager getLogManager() {
         return ;
     }

    
Reinitialize the logging properties and reread the logging configuration.
 
     public void setConfigurationProperties in ) {
          = in;
 
         String strDebug = (String).get. ); //$NON-NLS-1$
         LogLevel newlevel = LogLevel.getLogLevelNamed(strDebug);
         if(newlevel != null){
              = newlevel;
         }
 
         String strHandlers = (String).get. ); //$NON-NLS-1$
         if(strHandlers!=null) {
              = new ArrayList();
             loadHandlersstrHandlers );
             if.size()== 0 ) {
                 .add();
             }
         }
 
         notifyLoggers(true );
    }
    public void notifyLoggersLogLevel newlevelboolean notifyHandlers ) {
        for (Iterator iter = .keySet().iterator(); iter.hasNext();) {
            Logger element = (Logger).get((String)iter.next());
            element.setLevel(newlevel);
            element.setHandlers();
        }
    }
    public synchronized boolean addLogger(Logger logger) {
        String name = logger.getName();
        if (name == null) {
            throw new NullPointerException();
        }
        Logger old = (Logger.get(name);
        if (old != null) {
            // We already have a registered logger with the given name.
            return false;
        }
        .put(namelogger);
        logger.setLevel );
        logger.setHandlers );
      return true;
    }

    
Method to find a named logger.

Parameters:
name name of the logger
Returns:
matching logger or null if none is found
    public synchronized Logger getLogger(String name) {
    return (Logger.get(name);
    }
    private synchronized void loadHandlers(String strHandlers) {
        if(strHandlers==null)
            return;
        String names[] = parseClassNames(strHandlers);
        for (int i = 0; i < names.lengthi++) {
                String word = names[i];
                try {
                    Class clz = ClassLoader.getSystemClassLoader().loadClass(word);
                    ILogHandler h = (ILogHandlerclz.newInstance();
                    h.setProperties();
                    .add(h);
               } catch (Exception ex) {
                    ..println("Can't load log handler \"" + word + "\"");
                    ..println("" + ex);
               }
        }
        return;
    }
    // get a list of whitespace separated classnames from a property.
    private String[] parseClassNames(String handlers) {
        if (handlers == null) {
            return new String[0];
        }
        handlers = handlers.trim();
        int ix = 0;
        Vector result = new Vector();
        while (ix < handlers.length()) {
            int end = ix;
            while (end < handlers.length()) {
            if (Character.isWhitespace(handlers.charAt(end))) {
                break;
            }
            if (handlers.charAt(end) == ',') {
                break;
            }
            end++;
            }
            String word = handlers.substring(ixend);
            ix = end+1;
            word = word.trim();
            if (word.length() == 0) {
            continue;
            }
            result.add(word);
        }
      return (String[]) result.toArray(new String[result.size()]);
    }

    
Get the fully quallified name of the used logfile. If no logfile is used, this method returns null.

Since:
1.6.0
    public String getLogFileName() {
        for(Iterator it=.iterator();it.hasNext();) {
            Object handler = it.next();
            if(handler instanceof LogHandlerFile) {
                return ((LogHandlerFile)handler).getLogFileName();
            }
        }
        return null;
    }
New to GrepCode? Check out our FAQ X