summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/logging/Logger.java
blob: 79895e263c1df4617277d5a0c4aa0b5706fc62ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.logging;

import java.util.Hashtable;
import java.util.Properties;

import com.netscape.certsrv.logging.ILogEvent;
import com.netscape.certsrv.logging.ILogEventFactory;
import com.netscape.certsrv.logging.ILogQueue;
import com.netscape.certsrv.logging.ILogger;

/**
 * A class represents certificate server logger
 * implementation.
 * <P>
 * 
 * @author thomask
 * @author mzhao
 * @version $Revision$, $Date$
 */
public class Logger implements ILogger {

    protected static Logger mLogger = new Logger();
    protected ILogQueue mLogQueue = null;
    protected Hashtable<Integer, ILogEventFactory> mFactories = new Hashtable<Integer, ILogEventFactory>();

    /**
     * Constructs a generic logger, and registers a list
     * of resident event factories.
     */
    public Logger() {
        mLogQueue = LogSubsystem.getLogQueue();

        // register standard event factories
        register(EV_AUDIT, new AuditEventFactory());
        register(EV_SYSTEM, new SystemEventFactory());
        register(EV_SIGNED_AUDIT, new SignedAuditEventFactory());
    }

    /**
     * get default single global logger
     */
    static public Logger getLogger() {
        return mLogger;
    }

    /**
     * Retrieves the associated log queue.
     */
    public ILogQueue getLogQueue() {
        return mLogQueue;
    }

    /**
     * Registers log factory.
     * 
     * @param evtClass the event class name: ILogger.EV_SYSTEM or ILogger.EV_AUDIT
     * @param f the event factory name
     */
    public void register(int evtClass, ILogEventFactory f) {
        mFactories.put(evtClass, f);
    }

    //************** default level ****************
    /**
     * Logs an event using default log level: ILogger.LL_INFO
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param source the source of the log event
     * @param msg the one line detail message to be logged
     */
    public void log(int evtClass, int source, String msg) {
        log(evtClass, null, source, ILogger.LL_INFO, msg, null);
    }

    /**
     * Logs an event using default log level: ILogger.LL_INFO
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param msg the one line detail message to be logged
     */
    public void log(int evtClass, Properties props, int source, String msg) {
        log(evtClass, props, source, ILogger.LL_INFO, msg, null);
    }

    //************** no param ****************

    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param source the source of the log event
     * @param level the level of the log event
     * @param msg the one line detail message to be logged
     */
    public void log(int evtClass, int source, int level, String msg) {
        log(evtClass, null, source, level, msg, null);
    }

    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param level the level of the log event
     * @param msg the one line detail message to be logged
     */
    public void log(int evtClass, Properties props, int source, int level, String msg) {
        log(evtClass, props, source, level, msg, null);
    }

    //********************* one param **********************

    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param msg the one line detail message to be logged
     * @param param the parameter in the detail message
     */
    public void log(int evtClass, int source, int level, String msg, Object param) {
        log(evtClass, null, source, level, msg, param);
    }

    /**
     * Logs an event using default log level: ILogger.LL_INFO
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param msg the one line detail message to be logged
     * @param param the parameter in the detail message
     */
    public void log(int evtClass, Properties props, int source, String msg, Object param) {
        log(evtClass, props, source, ILogger.LL_INFO, msg, param);
    }

    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param level the level of the log event
     * @param msg the one line detail message to be logged
     * @param param the parameter in the detail message
     */
    public void log(int evtClass, Properties props, int source, int level, String msg,
            Object param) {
        Object o[] = new Object[1];

        o[0] = param;
        log(evtClass, props, source, level, msg, o);
    }

    //******************* multiple param **************************

    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param source the source of the log event
     * @param level the level of the log event
     * @param msg the one line detail message to be logged
     * @param params the parameters in the detail message
     */
    public void log(int evtClass, int source, int level, String msg,
            Object params[]) {
        log(evtClass, null, source, level, msg, params);
    }

    //*************** the real implementation *****************
    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param level the level of the log event
     * @param msg the one line detail message to be logged
     * @param params the parameters in the detail message
     */
    public void log(int evtClass, Properties prop, int source, int level, String msg,
            Object params[]) {
        mLogQueue.log(create(evtClass, prop, source, level, msg, params, ILogger.L_SINGLELINE));
    }

    //******************** multiline log *************************
    //************** default level ****************
    /**
     * Logs an event using default log level: ILogger.LL_INFO
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param source the source of the log event
     * @param msg the one line detail message to be logged
     * @param multiline true if the message has more than one line, otherwise false
     */
    public void log(int evtClass, int source, String msg, boolean multiline) {
        log(evtClass, null, source, ILogger.LL_INFO, msg, null, multiline);
    }

    /**
     * Logs an event using default log level: ILogger.LL_INFO
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param msg the one line detail message to be logged
     * @param multiline true if the message has more than one line, otherwise false
     */
    public void log(int evtClass, Properties props, int source, String msg, boolean multiline) {
        log(evtClass, props, source, ILogger.LL_INFO, msg, null, multiline);
    }

    //************** no param ****************

    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param source the source of the log event
     * @param level the level of the log event
     * @param msg the one line detail message to be logged
     * @param multiline true if the message has more than one line, otherwise false
     */
    public void log(int evtClass, int source, int level, String msg, boolean multiline) {
        log(evtClass, null, source, level, msg, null, multiline);
    }

    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param level the level of the log event
     * @param msg the one line detail message to be logged
     * @param multiline true if the message has more than one line, otherwise false
     */
    public void log(int evtClass, Properties props, int source, int level, String msg, boolean multiline) {
        log(evtClass, props, source, level, msg, null, multiline);
    }

    //********************* one param **********************

    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param msg the one line detail message to be logged
     * @param param the parameter in the detail message
     * @param multiline true if the message has more than one line, otherwise false
     */
    public void log(int evtClass, int source, int level, String msg, Object param, boolean multiline) {
        log(evtClass, null, source, level, msg, param, multiline);
    }

    /**
     * Logs an event using default log level: ILogger.LL_INFO
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param msg the one line detail message to be logged
     * @param param the parameter in the detail message
     * @param multiline true if the message has more than one line, otherwise false
     */
    public void log(int evtClass, Properties props, int source, String msg, Object param, boolean multiline) {
        log(evtClass, props, source, ILogger.LL_INFO, msg, param, multiline);
    }

    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param level the level of the log event
     * @param msg the one line detail message to be logged
     * @param param the parameter in the detail message
     * @param multiline true if the message has more than one line, otherwise false
     */
    public void log(int evtClass, Properties props, int source, int level, String msg,
            Object param, boolean multiline) {
        Object o[] = new Object[1];

        o[0] = param;
        log(evtClass, props, source, level, msg, o, multiline);
    }

    //******************* multiple param **************************

    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param source the source of the log event
     * @param level the level of the log event
     * @param msg the one line detail message to be logged
     * @param params the parameters in the detail message
     * @param multiline true if the message has more than one line, otherwise false
     */
    public void log(int evtClass, int source, int level, String msg,
            Object params[], boolean multiline) {
        log(evtClass, null, source, level, msg, params, multiline);
    }

    //*************** the real implementation *****************
    /**
     * Logs an event to the log queue.
     * 
     * @param evtClass What kind of event it is: EV_AUDIT or EV_SYSTEM.
     * @param props the resource bundle used for the detailed message
     * @param source the source of the log event
     * @param level the level of the log event
     * @param msg the one line detail message to be logged
     * @param params the parameters in the detail message
     * @param multiline true if the message has more than one line, otherwise false
     */
    public void log(int evtClass, Properties prop, int source, int level, String msg,
            Object params[], boolean multiline) {
        mLogQueue.log(create(evtClass, prop, source, level, msg, params, multiline));
    }

    //******************** end  multiline log *************************

    /**
     * Creates generic log event. If required, we can recycle
     * events here.
     */
    //XXXXXXXXXXX prop is out dated!!!! XXXXXXXXXXXXXXX
    public ILogEvent create(int evtClass, Properties prop, int source, int level,
            String msg, Object params[], boolean multiline) {
        ILogEventFactory f = mFactories.get(evtClass);

        if (f == null)
            return null;
        return f.create(evtClass, prop, source, level, multiline, msg, params);
    }

    /**
     * Notifies logger to reuse the event. This framework
     * opens up possibility to reuse event.
     * 
     * @param event a log event
     */
    public void release(ILogEvent event) {
        // do nothing for now.
    }

}