Exemplo n.º 1
0
  /**
   * Obtains a Logger from the Context.
   *
   * @param name The name of the Logger to return.
   * @param messageFactory The message factory is used only when creating a logger, subsequent use
   *     does not change the logger but will log a warning if mismatched.
   * @return The Logger.
   */
  @Override
  public Logger getLogger(final String name, final MessageFactory messageFactory) {
    // Note: This is the only method where we add entries to the 'loggers' ivar.
    // The loggers map key is the logger name plus the messageFactory FQCN.
    String key = LoggerContextKey.create(name, messageFactory);
    Logger logger = loggers.get(key);
    if (logger != null) {
      AbstractLogger.checkMessageFactory(logger, messageFactory);
      return logger;
    }

    logger = newInstance(this, name, messageFactory);
    // If messageFactory was null then we need to pull it out of the logger now
    key = LoggerContextKey.create(name, logger.getMessageFactory());
    final Logger prev = loggers.putIfAbsent(key, logger);
    return prev == null ? logger : prev;
  }
Exemplo n.º 2
0
 /**
  * Causes all Logger to be updated against the specified Configuration.
  *
  * @param config The Configuration.
  */
 public void updateLoggers(final Configuration config) {
   for (final Logger logger : loggers.values()) {
     logger.updateConfiguration(config);
   }
 }