All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.heavenark.infrastructure.log.LogFactoryForSlf4j Maven / Gradle / Ivy

The newest version!
package com.heavenark.infrastructure.log;

import java.util.concurrent.ConcurrentHashMap;

/**
 * Ark-Log factory for create logger instance
 *
 * @author 冰糕Luminous BGLuminous Luminous
 * @since 2.2.1
 */
public class LogFactoryForSlf4j {
  /** logger instance save map */
  private static final ConcurrentHashMap loggerMap = new ConcurrentHashMap<>();

  /** Constructor Private */
  private LogFactoryForSlf4j() {}

  /**
   * Get current factory instance
   *
   * @return ArkLogFactory instance
   */
  private static LogFactoryForSlf4j getInstance() {
    return Holder.INSTANCE;
  }

  /**
   * Get logger instance
   *
   * @param classname logger target class name
   * @return logger
   */
  public static Logger getLogger(String classname) {
    return getInstance().getOrCreateLogger(classname);
  }

  /**
   * Get or create logger instance, if logger already exist return it, if not found at map create a
   * new logger and return it.
   *
   * @param className logger target class name
   * @return logger
   */
  private Logger getOrCreateLogger(String className) {
    Logger logger = loggerMap.get(className);
    if (logger != null) {
      return logger;
    }
    logger = new Logger(ArkLogLoader.PROJECT_NAME_SLF, className);
    loggerMap.putIfAbsent(className, logger);
    return logger;
  }

  /** Initialization on Demand Holder */
  private static class Holder {
    private static final LogFactoryForSlf4j INSTANCE = new LogFactoryForSlf4j();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy