1 package com.protomatter.syslog; 2 3 52 53 import java.util.Map ; 54 import java.util.HashMap ; 55 import java.text.MessageFormat ; 56 import com.protomatter.util.*; 57 58 97 public final class Channel 98 { 99 102 public static final Channel ALL = Channel.getAllChannel(); 103 104 107 public static final Channel DEFAULT = Channel.getDefaultChannel(); 108 109 private String channels[] = null; 111 private SyslogChannelAware channelAware = null; 112 113 private Channel(String channels[]) 114 { 115 this.channels = channels; 116 } 117 118 private Channel(SyslogChannelAware channelAware) 119 { 120 this.channelAware = channelAware; 121 } 122 123 private final Object getChannelForLogging() 124 { 125 return (channels != null) ? channels : channelAware.getSyslogChannel(); 126 } 127 128 136 public String [] getChannelNames() 137 { 138 return Syslog.convertChannelObject(getChannelForLogging()); 139 } 140 141 144 public static Channel getChannel(String channelName) 145 { 146 return getChannel(new String [] { channelName }); 147 } 148 149 152 public static Channel getChannel(Class channelClass) 153 { 154 return getChannel(new String [] { channelClass.getName() }); 155 } 156 157 163 public static Channel forPackage(Class someClass) 164 { 165 String packageName = someClass.getName(); 166 int pos = packageName.lastIndexOf('.'); 167 return getChannel(new String [] { packageName.substring(0, pos) }); 168 } 169 170 174 public static Channel getChannel(String channels[]) 175 { 176 return new Channel(channels); 177 } 178 179 188 public static Channel getChannel(SyslogChannelAware channelAware) 189 { 190 return new Channel(channelAware); 191 } 192 193 196 public static Channel getAllChannel() 197 { 198 return getChannel(Syslog.ALL_CHANNEL); 199 } 200 201 204 public static Channel getDefaultChannel() 205 { 206 return getChannel(Syslog.DEFAULT_CHANNEL); 207 } 208 209 212 public void debug(Object caller, Object message) 213 { 214 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), message, null, Syslog.DEBUG, 215 Thread.currentThread(), Thread.currentThread().getName(), 216 System.currentTimeMillis(), 1); 217 } 218 219 222 public void debug(Object caller, Object message, Object detail) 223 { 224 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), message, detail, Syslog.DEBUG, 225 Thread.currentThread(), Thread.currentThread().getName(), 226 System.currentTimeMillis(), 1); 227 } 228 229 232 public void info(Object caller, Object message) 233 { 234 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), message, null, Syslog.INFO, 235 Thread.currentThread(), Thread.currentThread().getName(), 236 System.currentTimeMillis(), 1); 237 } 238 239 242 public void info(Object caller, Object message, Object detail) 243 { 244 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), message, detail, Syslog.INFO, 245 Thread.currentThread(), Thread.currentThread().getName(), 246 System.currentTimeMillis(), 1); 247 } 248 249 252 public void warning(Object caller, Object message) 253 { 254 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), message, null, Syslog.WARNING, 255 Thread.currentThread(), Thread.currentThread().getName(), 256 System.currentTimeMillis(), 1); 257 } 258 259 262 public void warning(Object caller, Object message, Object detail) 263 { 264 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), message, detail, Syslog.WARNING, 265 Thread.currentThread(), Thread.currentThread().getName(), 266 System.currentTimeMillis(), 1); 267 } 268 269 272 public void error(Object caller, Object message) 273 { 274 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), message, null, Syslog.ERROR, 275 Thread.currentThread(), Thread.currentThread().getName(), 276 System.currentTimeMillis(), 1); 277 } 278 279 282 public void error(Object caller, Object message, Object detail) 283 { 284 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), message, detail, Syslog.ERROR, 285 Thread.currentThread(), Thread.currentThread().getName(), 286 System.currentTimeMillis(), 1); 287 } 288 289 292 public void fatal(Object caller, Object message) 293 { 294 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), message, null, Syslog.FATAL, 295 Thread.currentThread(), Thread.currentThread().getName(), 296 System.currentTimeMillis(), 1); 297 } 298 299 302 public void fatal(Object caller, Object message, Object detail) 303 { 304 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), message, detail, Syslog.FATAL, 305 Thread.currentThread(), Thread.currentThread().getName(), 306 System.currentTimeMillis(), 1); 307 } 308 309 316 public void log(Object caller, Throwable exception) 317 { 318 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), exception.toString(), exception, Syslog.ERROR, 319 Thread.currentThread(), Thread.currentThread().getName(), 320 System.currentTimeMillis(), 1); 321 } 322 323 326 public void log(Object caller, Object message, Object detail, int level) 327 { 328 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), message, detail, level, 329 Thread.currentThread(), Thread.currentThread().getName(), 330 System.currentTimeMillis(), 1); 331 } 332 333 338 public void crumb(Object caller) 339 { 340 Syslog.log(Syslog.getLocalHostName(), caller, getChannelForLogging(), 341 MessageFormat.format(Syslog.getResourceString(MessageConstants.CRUMB_MESSAGE), 342 new Object [] { Syslog.whereAmI(1) }), 343 null, Syslog.DEBUG, Thread.currentThread(), Thread.currentThread().getName(), 344 System.currentTimeMillis(), 1); 345 } 346 347 352 public void crumb() 353 { 354 StackTraceInfo trace = StackTraceUtil.whereAmI(1); 355 Syslog.log(Syslog.getLocalHostName(), trace.className, getChannelForLogging(), 356 MessageFormat.format(Syslog.getResourceString(MessageConstants.CRUMB_MESSAGE), 357 new Object [] { trace }), 358 null, Syslog.DEBUG, Thread.currentThread(), Thread.currentThread().getName(), 359 System.currentTimeMillis(), 1); 360 } 361 362 } 363 | Popular Tags |