package common;

import common.log.LoggerName;
import common.log.SimpleLogger;
import java.security.AccessControlException;

public abstract class Logger {
  private static Logger logger = null;
  
  public static final Logger getLogger(Class cl) {
    if (logger == null)
      initializeLogger(); 
    return logger.getLoggerImpl(cl);
  }
  
  private static synchronized void initializeLogger() {
    if (logger != null)
      return; 
    String loggerName = LoggerName.NAME;
    try {
      loggerName = System.getProperty("logger");
      if (loggerName == null)
        loggerName = LoggerName.NAME; 
      logger = (Logger)Class.forName(loggerName).newInstance();
    } catch (IllegalAccessException e) {
      logger = (Logger)new SimpleLogger();
      logger.warn("Could not instantiate logger " + loggerName + " using default");
    } catch (InstantiationException e) {
      logger = (Logger)new SimpleLogger();
      logger.warn("Could not instantiate logger " + loggerName + " using default");
    } catch (AccessControlException e) {
      logger = (Logger)new SimpleLogger();
      logger.warn("Could not instantiate logger " + loggerName + " using default");
    } catch (ClassNotFoundException e) {
      logger = (Logger)new SimpleLogger();
      logger.warn("Could not instantiate logger " + loggerName + " using default");
    } 
  }
  
  public abstract void debug(Object paramObject);
  
  public abstract void debug(Object paramObject, Throwable paramThrowable);
  
  public abstract void error(Object paramObject);
  
  public abstract void error(Object paramObject, Throwable paramThrowable);
  
  public abstract void fatal(Object paramObject);
  
  public abstract void fatal(Object paramObject, Throwable paramThrowable);
  
  public abstract void info(Object paramObject);
  
  public abstract void info(Object paramObject, Throwable paramThrowable);
  
  public abstract void warn(Object paramObject);
  
  public abstract void warn(Object paramObject, Throwable paramThrowable);
  
  protected abstract Logger getLoggerImpl(Class paramClass);
  
  public void setSuppressWarnings(boolean w) {}
}
