1 20 21 package org.snmp4j.log; 22 23 import java.util.Iterator ; 24 import java.util.Collections ; 25 26 35 public class LogFactory { 36 37 public static final String SNMP4J_LOG_FACTORY_SYSTEM_PROPERTY = 38 "snmp4j.LogFactory"; 39 40 private static LogFactory snmp4jLogFactory = null; 41 private static boolean configChecked = false; 42 43 51 public static LogAdapter getLogger(Class c) { 52 checkConfig(); 53 if (snmp4jLogFactory == null) { 54 return NoLogger.instance; 55 } 56 else { 57 return snmp4jLogFactory.createLogger(c.getName()); 58 } 59 } 60 61 private static void checkConfig() { 62 if (!configChecked) { 63 configChecked = true; 64 getFactoryFromSystemProperty(); 65 } 66 } 67 68 private synchronized static void getFactoryFromSystemProperty() { 69 try { 70 String factory = 71 System.getProperty(SNMP4J_LOG_FACTORY_SYSTEM_PROPERTY, null); 72 if (factory != null) { 73 try { 74 Class c = Class.forName(factory); 75 snmp4jLogFactory = (LogFactory) c.newInstance(); 76 } 77 catch (ClassNotFoundException ex) { 78 } 79 catch (IllegalAccessException ex) { 80 } 81 catch (InstantiationException ex) { 82 } 83 } 84 } 85 catch (SecurityException sec) { 86 } 87 } 88 89 95 public LogAdapter getRootLogger() { 96 return NoLogger.instance; 97 } 98 99 108 public static LogAdapter getLogger(String className) { 109 checkConfig(); 110 if (snmp4jLogFactory == null) { 111 return NoLogger.instance; 112 } 113 else { 114 return snmp4jLogFactory.createLogger(className); 115 } 116 } 117 118 129 protected LogAdapter createLogger(Class c) { 130 return NoLogger.instance; 131 } 132 133 145 protected LogAdapter createLogger(String className) { 146 return NoLogger.instance; 147 } 148 149 157 public static void setLogFactory(LogFactory factory) { 158 configChecked = true; 159 snmp4jLogFactory = factory; 160 } 161 162 168 public static LogFactory getLogFactory() { 169 return snmp4jLogFactory; 170 } 171 172 178 public Iterator loggers() { 179 return Collections.singletonList(NoLogger.instance).iterator(); 180 } 181 182 } 183 | Popular Tags |