KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > monolog > wrapper > config > BasicLogger


1 /**
2  * Copyright (C) 2001-2003 France Telecom R&D
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package org.objectweb.util.monolog.wrapper.config;
20
21 import org.objectweb.util.monolog.api.Handler;
22 import org.objectweb.util.monolog.api.Level;
23 import org.objectweb.util.monolog.api.LevelFactory;
24 import org.objectweb.util.monolog.api.TopicalLogger;
25
26 import java.io.Serializable JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Enumeration JavaDoc;
29 import java.util.HashMap JavaDoc;
30
31 /**
32  * This class is a basic implementatio of the TopicalLogger interface. It is not
33  * linked to any underlying log system. The log methods do nothing. Only the
34  * configuration aspect is treated. Therefore all the logger structure is
35  * stored into internal struture.
36  *
37  * @author Sebastien Chassande-Barrioz
38  */

39 public class BasicLogger implements TopicalLogger, Serializable JavaDoc {
40
41     /**
42      * This fields references by their name the handlers associated to the
43      * logger.
44      * key = a handler name
45      * value = a Handler instance
46      */

47     protected HashMap JavaDoc handlers = null;
48
49     /**
50      * The fields lists all topics the logger.
51      */

52     protected ArrayList JavaDoc topics = null;
53
54     /**
55      * This field references the level factory.
56      */

57     protected LevelFactory levelFactory = null;
58
59     boolean additivity = true;
60
61     /**
62      * The current level of the logger.
63      */

64     protected Level level = null;
65
66     BasicLogger(String JavaDoc topic, LevelFactory lf) {
67         topics = new ArrayList JavaDoc();
68         handlers = new HashMap JavaDoc();
69         topics.add(topic);
70         levelFactory = lf;
71     }
72
73     // IMPLEMENTATION OF THE TopicalLogger INTERFACE //
74
//--------------------------------------------//
75

76     public void addHandler(Handler h) throws Exception JavaDoc {
77         handlers.put(h.getName(), h);
78     }
79
80     public void removeHandler(Handler h) throws Exception JavaDoc {
81         handlers.remove(h.getName());
82     }
83
84     public Handler[] getHandler() {
85         return (Handler[]) handlers.values().toArray(new Handler[0]);
86     }
87
88     public Handler getHandler(String JavaDoc hn) {
89         return (Handler) handlers.get(hn);
90     }
91
92     public void removeAllHandlers() throws Exception JavaDoc {
93         handlers.clear();
94     }
95
96     public void setAdditivity(boolean a) {
97         additivity = a;
98     }
99
100     public boolean getAdditivity() {
101         return additivity;
102     }
103
104     public void addTopic(String JavaDoc topic) throws Exception JavaDoc {
105         if (!topics.contains(topic)) {
106             topics.add(topic);
107         }
108     }
109
110     /**
111      * TODO
112      */

113     public Enumeration JavaDoc getTopics() {
114 //TODO
115
return null;
116     }
117
118     public String JavaDoc[] getTopic() {
119         return (String JavaDoc[]) topics.toArray(new String JavaDoc[0]);
120     }
121
122     public void removeTopic(String JavaDoc topic) throws Exception JavaDoc {
123         topics.remove(topic);
124     }
125
126     // IMPLEMENTATION OF THE Handler INTERFACE //
127
//----------------------------------------//
128
public String JavaDoc getName() {
129         return (String JavaDoc) topics.get(0);
130     }
131
132     public void setName(String JavaDoc name) {
133         topics.set(0, name);
134     }
135
136     public String JavaDoc getType() {
137         return "logger";
138     }
139
140     public String JavaDoc[] getAttributeNames() {
141         return new String JavaDoc[0];
142     }
143
144     public Object JavaDoc getAttribute(String JavaDoc name) {
145         return null;
146     }
147
148     public Object JavaDoc setAttribute(String JavaDoc name, Object JavaDoc value) {
149         return null;
150     }
151
152     // IMPLEMENTATION OF THE Logger INTERFACE //
153
//----------------------------------------//
154

155     public void setIntLevel(int l) {
156         level = levelFactory.getLevel(l);
157     }
158
159     public void setLevel(Level l) {
160         level = l;
161     }
162
163     public int getCurrentIntLevel() {
164         return (level != null ? level.getIntValue() : 0);
165     }
166
167     public Level getCurrentLevel() {
168         return level;
169     }
170
171     public boolean isLoggable(int level) {
172         return false;
173     }
174
175     public boolean isLoggable(Level l) {
176         return false;
177     }
178
179     public boolean isOn() {
180         return false;
181     }
182
183     public void log(int level, Object JavaDoc message) {
184     }
185
186     public void log(Level level, Object JavaDoc message) {
187     }
188
189     public void log(int level, Object JavaDoc message, Throwable JavaDoc throwable) {
190     }
191
192     public void log(Level level, Object JavaDoc message, Throwable JavaDoc throwable) {
193     }
194
195     public void log(int level, Object JavaDoc message, Object JavaDoc location, Object JavaDoc method) {
196     }
197
198     public void log(Level l, Object JavaDoc message, Object JavaDoc location, Object JavaDoc method) {
199     }
200
201     public void log(int level, Object JavaDoc message, Throwable JavaDoc throwable,
202                     Object JavaDoc location, Object JavaDoc method) {
203     }
204
205     public void log(Level level, Object JavaDoc message, Throwable JavaDoc throwable,
206                     Object JavaDoc location, Object JavaDoc method) {
207     }
208
209     public void turnOn() {
210     }
211
212     public void turnOff() {
213     }
214 }
215
Popular Tags