1 42 43 package org.jfree.util; 44 45 50 public class LogContext { 51 52 53 private String contextPrefix; 54 55 60 public LogContext(final String contextPrefix) { 61 this.contextPrefix = contextPrefix; 62 } 63 64 70 public boolean isDebugEnabled() { 71 return Log.isDebugEnabled(); 72 } 73 74 80 public boolean isInfoEnabled() { 81 return Log.isInfoEnabled(); 82 } 83 84 90 public boolean isWarningEnabled() { 91 return Log.isWarningEnabled(); 92 } 93 94 100 public boolean isErrorEnabled() { 101 return Log.isErrorEnabled(); 102 } 103 104 105 110 public void debug(final Object message) { 111 log(LogTarget.DEBUG, message); 112 } 113 114 120 public void debug(final Object message, final Exception e) { 121 log(LogTarget.DEBUG, message, e); 122 } 123 124 129 public void info(final Object message) { 130 log(LogTarget.INFO, message); 131 } 132 133 139 public void info(final Object message, final Exception e) { 140 log(LogTarget.INFO, message, e); 141 } 142 143 148 public void warn(final Object message) { 149 log(LogTarget.WARN, message); 150 } 151 152 158 public void warn(final Object message, final Exception e) { 159 log(LogTarget.WARN, message, e); 160 } 161 162 167 public void error(final Object message) { 168 log(LogTarget.ERROR, message); 169 } 170 171 177 public void error(final Object message, final Exception e) { 178 log(LogTarget.ERROR, message, e); 179 } 180 181 189 public void log(final int level, final Object message) { 190 if (this.contextPrefix != null) { 191 Log.getInstance().doLog(level, new Log.SimpleMessage(this.contextPrefix, ":", message)); 192 } 193 else { 194 Log.getInstance().doLog(level, message); 195 } 196 } 197 198 209 public void log(final int level, final Object message, final Exception e) { 210 if (this.contextPrefix != null) { 211 Log.getInstance().doLog( 212 level, new Log.SimpleMessage(this.contextPrefix, ":", message), e 213 ); 214 } 215 else { 216 Log.getInstance().doLog(level, message, e); 217 } 218 } 219 220 227 public boolean equals(final Object o) { 228 if (this == o) { 229 return true; 230 } 231 if (!(o instanceof LogContext)) { 232 return false; 233 } 234 235 final LogContext logContext = (LogContext) o; 236 237 if (this.contextPrefix != null) 238 { 239 if (!this.contextPrefix.equals(logContext.contextPrefix)) { 240 return false; 241 } 242 } 243 else { 244 if (logContext.contextPrefix != null) { 245 return false; 246 } 247 } 248 249 return true; 250 } 251 252 257 public int hashCode() { 258 return (this.contextPrefix != null ? this.contextPrefix.hashCode() : 0); 259 } 260 } 261 | Popular Tags |