From d0f2e4efbd3eb0f1d7f5a28e7f97c1fb4ec027bb Mon Sep 17 00:00:00 2001 From: PKI Team Date: Tue, 18 Mar 2008 22:36:57 +0000 Subject: Initial open source version based upon proprietary Red Hat Certificate System (RHCS) 7.3. git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@2 c9f7a03b-bd48-0410-a16d-cbbf54688b0b --- .../src/com/netscape/cmscore/logging/Logger.java | 374 +++++++++++++++++++++ 1 file changed, 374 insertions(+) create mode 100644 pki/base/common/src/com/netscape/cmscore/logging/Logger.java (limited to 'pki/base/common/src/com/netscape/cmscore/logging/Logger.java') diff --git a/pki/base/common/src/com/netscape/cmscore/logging/Logger.java b/pki/base/common/src/com/netscape/cmscore/logging/Logger.java new file mode 100644 index 000000000..f90488eb8 --- /dev/null +++ b/pki/base/common/src/com/netscape/cmscore/logging/Logger.java @@ -0,0 +1,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.io.*; +import java.util.*; +import com.netscape.certsrv.logging.*; + +import com.netscape.cmscore.util.*; + + +/** + * A class represents certificate server logger + * implementation. + *

+ * + * @author thomask + * @author mzhao + * @version $Revision: 14561 $, $Date: 2007-05-01 10:28:56 -0700 (Tue, 01 May 2007) $ + */ +public class Logger implements ILogger { + + protected static Logger mLogger = new Logger(); + protected ILogQueue mLogQueue = null; + protected Hashtable mFactories = new Hashtable(); + + /** + * 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(Integer.toString(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 = (ILogEventFactory) mFactories.get( + Integer.toString(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. + } + +} -- cgit