001: package de.webman.util.log4j;
002:
003: import org.apache.log4j.Category;
004: import org.apache.log4j.Priority;
005: import org.apache.log4j.spi.OptionHandler;
006: import org.apache.log4j.spi.LoggingEvent;
007: import org.apache.log4j.spi.CategoryFactory;
008: import org.apache.log4j.helpers.LogLog;
009:
010: import java.util.Enumeration;
011:
012: /**
013: Subclassing Category from Log4j
014: * @see org.apache.log4j.Category
015: * @author $Author: alex $
016: * @version $Revision: 1.2 $
017: */
018: public class WebmanCategory extends Category implements OptionHandler {
019: public static final int ALL = 0;
020:
021: public static final int EDITOR = 1;
022:
023: public static final int ADMINISTRATOR = 2;
024:
025: public static final int PRODUCER = 3;
026:
027: private static int filter = Integer.MAX_VALUE;
028:
029: final private static String FQCN = WebmanCategory.class.getName();
030:
031: // It's enough to instantiate a factory once and for all.
032: public static WebmanFactory factory = new WebmanFactory();
033:
034: /**
035: Just calls the parent constructor.
036: */
037: protected WebmanCategory(String name) {
038: super (name);
039: }
040:
041: /**
042: Nothing to activate.
043: */
044: public void activateOptions() {
045: }
046:
047: public static void setFilter(int _filter) {
048: filter = _filter;
049: }
050:
051: /**
052: Set specific options.
053:
054: <p>The <b>Suffix</b> option is the only recognized option. It
055: takes a string value.
056: @deprecated
057: */
058: public void setOption(String option, String value) {
059: if (option == null) {
060: return;
061: }
062: }
063:
064: /**
065: Retuns the option names for this component
066: @deprecated
067: */
068: public String[] getOptionStrings() {
069: return null;
070: }
071:
072: public String getOption(String option) {
073: return null;
074: }
075:
076: /**
077: This method overrides {@link Category#getInstance} by supplying
078: its own factory type as a parameter.
079: */
080: public static Category getInstance(String name) {
081: return Category.getInstance(name, factory);
082: }
083:
084: /**
085: This method overrides {@link Category#getInstance(Class)} by supplying
086: its own factory type as a parameter.
087: */
088: public static Category getInstance(Class clazz) {
089: return getInstance(clazz.getName(), factory);
090: }
091:
092: private static boolean isUserEnabled(int user) {
093: return user <= filter;
094: }
095:
096: public void debug(Object message) {
097: if (isUserEnabled(Integer.MAX_VALUE))
098: super .debug(message);
099: }
100:
101: public void debug(Object message, int user) {
102: if (isUserEnabled(user))
103: super .debug(message);
104: }
105:
106: public void debug(Object message, Throwable t, int user) {
107: if (isUserEnabled(user))
108: super .debug(message, t);
109: }
110:
111: public void debug(Object message, Throwable t) {
112: if (isUserEnabled(Integer.MAX_VALUE))
113: super .debug(message, t);
114: }
115:
116: public void info(Object message) {
117: if (isUserEnabled(Integer.MAX_VALUE))
118: super .info(message);
119: }
120:
121: public void info(Object message, int user) {
122: if (isUserEnabled(user))
123: super .info(message);
124: }
125:
126: public void info(Object message, Throwable t, int user) {
127: if (isUserEnabled(user))
128: super .info(message, t);
129: }
130:
131: public void info(Object message, Throwable t) {
132: if (isUserEnabled(Integer.MAX_VALUE))
133: super .info(message, t);
134: }
135:
136: public void warn(Object message) {
137: if (isUserEnabled(Integer.MAX_VALUE))
138: super .warn(message);
139: }
140:
141: public void warn(Object message, int user) {
142: if (isUserEnabled(user))
143: super .warn(message);
144: }
145:
146: public void warn(Object message, Throwable t, int user) {
147: if (isUserEnabled(user))
148: super .warn(message, t);
149: }
150:
151: public void warn(Object message, Throwable t) {
152: if (isUserEnabled(Integer.MAX_VALUE))
153: super .warn(message, t);
154: }
155:
156: public void error(Object message) {
157: if (isUserEnabled(Integer.MAX_VALUE))
158: super .error(message);
159: }
160:
161: public void error(Object message, int user) {
162: if (isUserEnabled(user))
163: super .error(message);
164: }
165:
166: public void error(Object message, Throwable t, int user) {
167: if (isUserEnabled(user))
168: super .error(message, t);
169: }
170:
171: public void error(Object message, Throwable t) {
172: if (isUserEnabled(Integer.MAX_VALUE))
173: super .error(message, t);
174: }
175:
176: public void fatal(Object message) {
177: if (isUserEnabled(Integer.MAX_VALUE))
178: super .fatal(message);
179: }
180:
181: public void fatal(Object message, int user) {
182: if (isUserEnabled(user))
183: super .fatal(message);
184: }
185:
186: public void fatal(Object message, Throwable t, int user) {
187: if (isUserEnabled(user))
188: super .fatal(message, t);
189: }
190:
191: public void fatal(Object message, Throwable t) {
192: if (isUserEnabled(Integer.MAX_VALUE))
193: super .fatal(message, t);
194: }
195:
196: /**
197: We introduce a new printing method that takes the ACCESS priority.
198: */
199: public void access(Object message, Throwable t) {
200: // disable is defined in Category
201: if (hierarchy.isDisabled(AccessPriority.ACCESS_INT))
202: return;
203: if (AccessPriority.ACCESS.isGreaterOrEqual(this
204: .getChainedPriority()))
205: forcedLog(FQCN, AccessPriority.ACCESS, message, t);
206: }
207:
208: /**
209: We introduce a new printing method that takes the ACCESS priority.
210: */
211: public void access(Object message) {
212: if (hierarchy.isDisabled(AccessPriority.ACCESS_INT))
213: return;
214: if (AccessPriority.ACCESS.isGreaterOrEqual(this
215: .getChainedPriority())) {
216: forcedLog(FQCN, AccessPriority.ACCESS, message, null);
217: // callAppenders(new LoggingEvent(FQCN, this, AccessPriority.ACCESS,
218: // message, null));
219: }
220: }
221:
222: // Any sub-class of Category must also have its own implementation of
223: // CategoryFactory.
224: public static class WebmanFactory implements CategoryFactory {
225:
226: public WebmanFactory() {
227: }
228:
229: public Category makeNewCategoryInstance(String name) {
230: return new WebmanCategory(name);
231: }
232: }
233: }
|