1 33 34 package org.slf4j.impl; 35 36 import java.util.HashMap ; 37 import java.util.Map ; 38 39 import org.apache.log4j.LogManager; 40 import org.slf4j.ILoggerFactory; 41 import org.slf4j.Logger; 42 43 49 public class Log4jLoggerFactory implements ILoggerFactory { 50 51 Map loggerMap; 53 54 public Log4jLoggerFactory() { 55 loggerMap = new HashMap (); 56 } 57 58 63 public Logger getLogger(String name) { 64 Logger slf4jLogger = null; 65 synchronized (this) { 67 slf4jLogger = (Logger) loggerMap.get(name); 68 if (slf4jLogger == null) { 69 org.apache.log4j.Logger log4jLogger; 70 if(name.equalsIgnoreCase(Logger.ROOT_LOGGER_NAME)) { 71 log4jLogger = LogManager.getRootLogger(); 72 } else { 73 log4jLogger = LogManager.getLogger(name); 74 } 75 slf4jLogger = new Log4jLoggerAdapter(log4jLogger); 76 loggerMap.put(name, slf4jLogger); 77 } 78 } 79 return slf4jLogger; 80 } 81 } 82 | Popular Tags |