1 20 21 package org.snmp4j.log; 22 23 import java.util.Iterator ; 24 import java.util.Collections ; 25 26 33 public class ConsoleLogAdapter implements LogAdapter { 34 35 private static boolean debugEnabled = false; 36 private static boolean infoEnabled = true; 37 private static boolean warnEnabled = true; 38 39 public ConsoleLogAdapter() { 40 } 41 42 47 public void debug(Object message) { 48 if (debugEnabled) { 49 System.out.println(message.toString()); 50 } 51 } 52 53 58 public void error(Object message) { 59 System.err.println(message.toString()); 60 } 61 62 68 public void error(Object message, Throwable throwable) { 69 System.err.println(message.toString()); 70 } 71 72 77 public void fatal(Object message) { 78 System.err.println(message.toString()); 79 } 80 81 87 public void fatal(Object message, Throwable throwable) { 88 System.err.println(message.toString()); 89 } 90 91 96 public void info(Object message) { 97 if (infoEnabled) { 98 System.out.println(message.toString()); 99 } 100 } 101 102 108 public boolean isDebugEnabled() { 109 return debugEnabled; 110 } 111 112 118 public boolean isInfoEnabled() { 119 return infoEnabled; 120 } 121 122 128 public boolean isWarnEnabled() { 129 return warnEnabled; 130 } 131 132 137 public void warn(Object message) { 138 if (warnEnabled) { 139 System.out.println(message.toString()); 140 } 141 } 142 143 public static void setDebugEnabled(boolean isDebugEnabled) { 144 debugEnabled = isDebugEnabled; 145 } 146 147 public static void setWarnEnabled(boolean isWarnEnabled) { 148 warnEnabled = isWarnEnabled; 149 } 150 151 public static void setInfoEnabled(boolean isInfoEnabled) { 152 infoEnabled = isInfoEnabled; 153 } 154 155 public void setLogLevel(LogLevel level) { 156 debugEnabled = false; 157 warnEnabled = false; 158 infoEnabled = false; 159 switch (level.getLevel()) { 160 case LogLevel.LEVEL_ALL: 161 debugEnabled = true; 162 warnEnabled = true; 163 infoEnabled = true; 164 break; 165 case LogLevel.LEVEL_TRACE: 166 case LogLevel.LEVEL_DEBUG: 167 debugEnabled = true; 168 break; 169 case LogLevel.LEVEL_INFO: 170 infoEnabled = true; 171 break; 172 case LogLevel.LEVEL_WARN: 173 warnEnabled = true; 174 break; 175 default: 176 } 177 } 178 179 public String getName() { 180 return ""; 181 } 182 183 public LogLevel getLogLevel() { 184 if (debugEnabled) { 185 return LogLevel.DEBUG; 186 } 187 else if (infoEnabled) { 188 return LogLevel.INFO; 189 } 190 else if (warnEnabled) { 191 return LogLevel.WARN; 192 } 193 return LogLevel.OFF; 194 } 195 196 public LogLevel getEffectiveLogLevel() { 197 return getLogLevel(); 198 } 199 200 public Iterator getLogHandler() { 201 return Collections.EMPTY_LIST.iterator(); 202 } 203 } 204 | Popular Tags |