1 package com.protomatter.syslog; 2 3 52 53 import java.net.*; 54 import java.util.*; 55 import java.text.*; 56 57 71 public abstract class BasicLogger 72 implements Syslogger 73 { 74 protected LogPolicy policy = new SimpleLogPolicy(); 75 protected LogPolicy realPolicy = null; 76 protected SyslogTextFormatter formatter = null; 77 private String name = null; 78 79 82 public BasicLogger() 83 { 84 super(); 85 86 formatter = new SimpleSyslogTextFormatter(); 87 } 88 89 95 public void suspend() 96 { 97 this.realPolicy = this.policy; 98 this.policy = new FalseLogPolicy(); 99 } 100 101 105 public void resume() 106 { 107 this.policy = this.realPolicy; 108 this.realPolicy = null; 109 } 110 111 114 public boolean isSuspended() 115 { 116 return (this.realPolicy != null); 117 } 118 119 122 public void setPolicy(LogPolicy policy) 123 { 124 this.policy = policy; 125 } 126 127 130 public LogPolicy getPolicy() 131 { 132 return this.policy; 133 } 134 135 146 public boolean mightLog(Object logger, int level, String channel) 147 { 148 SyslogMessage m = new SyslogMessage(); 149 m.level = level; 150 m.channel = channel; 151 m.thread = Thread.currentThread(); 152 153 m.logger = logger; 154 if (logger != null) 155 { 156 if (logger instanceof Class ) 158 m.loggerClassname = ((Class )logger).getName(); 159 else 160 m.loggerClassname = logger.getClass().getName(); 161 } 162 else 163 { 164 m.loggerClassname = "?"; 165 } 166 167 m.time = System.currentTimeMillis(); 169 170 return policy.shouldLog(m); 172 } 173 174 177 public void setTextFormatter(SyslogTextFormatter formatter) 178 { 179 this.formatter = formatter; 180 } 181 182 185 public SyslogTextFormatter getTextFormatter() 186 { 187 return this.formatter; 188 } 189 190 194 protected boolean shouldLog(SyslogMessage message) 195 { 196 return policy.shouldLog(message); 197 } 198 199 204 protected void formatLogEntry(StringBuffer b, SyslogMessage message) 205 { 206 formatter.formatLogEntry(b, message); 207 } 208 209 216 protected void resetDateFormat() 217 { 218 formatter.resetDateFormat(); 219 } 220 221 224 public void setName(String name) 225 { 226 this.name = name; 227 } 228 229 232 public String getName() 233 { 234 return this.name; 235 } 236 } 237 | Popular Tags |