KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > util > log4j > WebmanCategory


1 package de.webman.util.log4j;
2
3
4 import org.apache.log4j.Category;
5 import org.apache.log4j.Priority;
6 import org.apache.log4j.spi.OptionHandler;
7 import org.apache.log4j.spi.LoggingEvent;
8 import org.apache.log4j.spi.CategoryFactory;
9 import org.apache.log4j.helpers.LogLog;
10
11 import java.util.Enumeration JavaDoc;
12
13 /**
14     Subclassing Category from Log4j
15  * @see org.apache.log4j.Category
16  * @author $Author: alex $
17  * @version $Revision: 1.2 $
18  */

19 public class WebmanCategory extends Category implements OptionHandler
20 {
21     public static final int ALL = 0;
22     
23     public static final int EDITOR = 1;
24     
25     public static final int ADMINISTRATOR = 2;
26     
27     public static final int PRODUCER = 3;
28     
29     private static int filter = Integer.MAX_VALUE;
30
31     final private static String JavaDoc FQCN = WebmanCategory.class.getName();
32
33     // It's enough to instantiate a factory once and for all.
34
public static WebmanFactory factory = new WebmanFactory();
35       
36     /**
37         Just calls the parent constructor.
38     */

39     protected WebmanCategory(String JavaDoc name) {
40         super(name);
41     }
42
43     /**
44         Nothing to activate.
45     */

46     public void activateOptions() {
47     }
48
49     public static void setFilter(int _filter)
50     {
51         filter = _filter;
52     }
53     /**
54      Set specific options.
55
56      <p>The <b>Suffix</b> option is the only recognized option. It
57      takes a string value.
58      @deprecated
59     */

60     public void setOption(String JavaDoc option, String JavaDoc value)
61     {
62         if(option == null) {
63         return;
64         }
65     }
66     
67     /**
68         Retuns the option names for this component
69         @deprecated
70     */

71     public String JavaDoc[] getOptionStrings()
72     {
73         return null;
74     }
75   
76     public String JavaDoc getOption(String JavaDoc option)
77     {
78         return null;
79     }
80   
81     /**
82         This method overrides {@link Category#getInstance} by supplying
83         its own factory type as a parameter.
84     */

85     public static Category getInstance(String JavaDoc name)
86     {
87         return Category.getInstance(name, factory);
88     }
89
90     /**
91         This method overrides {@link Category#getInstance(Class)} by supplying
92         its own factory type as a parameter.
93     */

94     public static Category getInstance(Class JavaDoc clazz)
95     {
96         return getInstance(clazz.getName(), factory);
97     }
98
99     private static boolean isUserEnabled(int user)
100     {
101         return user <= filter;
102     }
103     
104     public void debug(Object JavaDoc message)
105     {
106         if (isUserEnabled(Integer.MAX_VALUE))
107             super.debug(message);
108     }
109     
110     public void debug(Object JavaDoc message, int user)
111     {
112         if (isUserEnabled(user))
113             super.debug(message);
114     }
115     
116     public void debug(Object JavaDoc message, Throwable JavaDoc t, int user)
117     {
118         if (isUserEnabled(user))
119             super.debug(message, t);
120     }
121     
122     public void debug(Object JavaDoc message, Throwable JavaDoc t)
123     {
124         if (isUserEnabled(Integer.MAX_VALUE))
125             super.debug(message, t);
126     }
127     
128     public void info(Object JavaDoc message)
129     {
130         if (isUserEnabled(Integer.MAX_VALUE))
131             super.info(message);
132     }
133     
134     public void info(Object JavaDoc message, int user)
135     {
136         if (isUserEnabled(user))
137             super.info(message);
138     }
139     
140     public void info(Object JavaDoc message, Throwable JavaDoc t, int user)
141     {
142         if (isUserEnabled(user))
143             super.info(message, t);
144     }
145     
146     public void info(Object JavaDoc message, Throwable JavaDoc t)
147     {
148         if (isUserEnabled(Integer.MAX_VALUE))
149             super.info(message, t);
150     }
151     
152     public void warn(Object JavaDoc message)
153     {
154         if (isUserEnabled(Integer.MAX_VALUE))
155             super.warn(message);
156     }
157     
158     public void warn(Object JavaDoc message, int user)
159     {
160         if (isUserEnabled(user))
161             super.warn(message);
162     }
163     
164     public void warn(Object JavaDoc message, Throwable JavaDoc t, int user)
165     {
166         if (isUserEnabled(user))
167             super.warn(message, t);
168     }
169     
170     public void warn(Object JavaDoc message, Throwable JavaDoc t)
171     {
172         if (isUserEnabled(Integer.MAX_VALUE))
173             super.warn(message, t);
174     }
175     
176     public void error(Object JavaDoc message)
177     {
178         if (isUserEnabled(Integer.MAX_VALUE))
179             super.error(message);
180     }
181     
182     public void error(Object JavaDoc message, int user)
183     {
184         if (isUserEnabled(user))
185             super.error(message);
186     }
187     
188     public void error(Object JavaDoc message, Throwable JavaDoc t, int user)
189     {
190         if (isUserEnabled(user))
191             super.error(message, t);
192     }
193     
194     public void error(Object JavaDoc message, Throwable JavaDoc t)
195     {
196         if (isUserEnabled(Integer.MAX_VALUE))
197             super.error(message, t);
198     }
199     
200     public void fatal(Object JavaDoc message)
201     {
202         if (isUserEnabled(Integer.MAX_VALUE))
203             super.fatal(message);
204     }
205     
206     public void fatal(Object JavaDoc message, int user)
207     {
208         if (isUserEnabled(user))
209             super.fatal(message);
210     }
211     
212     public void fatal(Object JavaDoc message, Throwable JavaDoc t, int user)
213     {
214         if (isUserEnabled(user))
215             super.fatal(message, t);
216     }
217     
218     public void fatal(Object JavaDoc message, Throwable JavaDoc t)
219     {
220         if (isUserEnabled(Integer.MAX_VALUE))
221             super.fatal(message, t);
222     }
223     
224     /**
225         We introduce a new printing method that takes the ACCESS priority.
226     */

227     public void access(Object JavaDoc message, Throwable JavaDoc t)
228     {
229         // disable is defined in Category
230
if(hierarchy.isDisabled(AccessPriority.ACCESS_INT))
231             return;
232         if(AccessPriority.ACCESS.isGreaterOrEqual(this.getChainedPriority()))
233             forcedLog(FQCN, AccessPriority.ACCESS, message, t);
234     }
235
236     /**
237         We introduce a new printing method that takes the ACCESS priority.
238     */

239     public void access(Object JavaDoc message)
240     {
241         if(hierarchy.isDisabled(AccessPriority.ACCESS_INT))
242             return;
243         if(AccessPriority.ACCESS.isGreaterOrEqual(this.getChainedPriority()))
244         {
245             forcedLog(FQCN, AccessPriority.ACCESS, message, null);
246             // callAppenders(new LoggingEvent(FQCN, this, AccessPriority.ACCESS,
247
// message, null));
248
}
249     }
250
251
252
253     // Any sub-class of Category must also have its own implementation of
254
// CategoryFactory.
255
public static class WebmanFactory implements CategoryFactory {
256         
257         public WebmanFactory() {
258         }
259
260         public Category makeNewCategoryInstance(String JavaDoc name) {
261             return new WebmanCategory(name);
262         }
263     }
264 }
265
266
267
Popular Tags