From 91079a946317f5c96c2778efaca814da67e0c3bf Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Thu, 22 Jun 2017 01:02:18 +0200 Subject: Reorganized Logger classes. Some Logger classes have been moved into com.netscape.cms.logging due to dependency requirements in subsequent changes. https://pagure.io/dogtagpki/issue/2689 Change-Id: I1e8ec247764d344647a519618a7523c51799f3de --- .../netscape/cms/logging/AuditEventFactory.java | 67 ++++ .../src/com/netscape/cms/logging/LogFactory.java | 65 ++++ .../cms/src/com/netscape/cms/logging/LogQueue.java | 117 ++++++ .../cms/src/com/netscape/cms/logging/Logger.java | 407 +++++++++++++++++++++ .../cms/logging/SignedAuditEventFactory.java | 94 +++++ .../netscape/cms/logging/SignedAuditLogger.java | 39 ++ .../netscape/cms/logging/SystemEventFactory.java | 67 ++++ .../src/com/netscape/cmscore/apps/CMSEngine.java | 4 +- .../cmscore/logging/AuditEventFactory.java | 67 ---- .../com/netscape/cmscore/logging/LogFactory.java | 65 ---- .../src/com/netscape/cmscore/logging/LogQueue.java | 117 ------ .../com/netscape/cmscore/logging/LogSubsystem.java | 1 + .../src/com/netscape/cmscore/logging/Logger.java | 407 --------------------- .../cmscore/logging/SignedAuditEventFactory.java | 94 ----- .../cmscore/logging/SignedAuditLogger.java | 39 -- .../cmscore/logging/SystemEventFactory.java | 67 ---- 16 files changed, 859 insertions(+), 858 deletions(-) create mode 100644 base/server/cms/src/com/netscape/cms/logging/AuditEventFactory.java create mode 100644 base/server/cms/src/com/netscape/cms/logging/LogFactory.java create mode 100644 base/server/cms/src/com/netscape/cms/logging/LogQueue.java create mode 100644 base/server/cms/src/com/netscape/cms/logging/Logger.java create mode 100644 base/server/cms/src/com/netscape/cms/logging/SignedAuditEventFactory.java create mode 100644 base/server/cms/src/com/netscape/cms/logging/SignedAuditLogger.java create mode 100644 base/server/cms/src/com/netscape/cms/logging/SystemEventFactory.java delete mode 100644 base/server/cmscore/src/com/netscape/cmscore/logging/AuditEventFactory.java delete mode 100644 base/server/cmscore/src/com/netscape/cmscore/logging/LogFactory.java delete mode 100644 base/server/cmscore/src/com/netscape/cmscore/logging/LogQueue.java delete mode 100644 base/server/cmscore/src/com/netscape/cmscore/logging/Logger.java delete mode 100644 base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditEventFactory.java delete mode 100644 base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditLogger.java delete mode 100644 base/server/cmscore/src/com/netscape/cmscore/logging/SystemEventFactory.java (limited to 'base') diff --git a/base/server/cms/src/com/netscape/cms/logging/AuditEventFactory.java b/base/server/cms/src/com/netscape/cms/logging/AuditEventFactory.java new file mode 100644 index 000000000..fad45780b --- /dev/null +++ b/base/server/cms/src/com/netscape/cms/logging/AuditEventFactory.java @@ -0,0 +1,67 @@ +// --- 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.cms.logging; + +import java.util.Properties; + +import com.netscape.certsrv.logging.AuditEvent; +import com.netscape.certsrv.logging.ILogEvent; +import com.netscape.certsrv.logging.ILogger; +import com.netscape.certsrv.logging.LogCategory; +import com.netscape.certsrv.logging.LogSource; + +/** + * A log event object for handling audit messages + *

+ * + * @author mikep + * @author mzhao + * @version $Revision$, $Date$ + */ +public class AuditEventFactory extends LogFactory { + + /** + * Constructs a audit event factory. + */ + public AuditEventFactory() { + } + + /** + * Creates an log event. + * + * @param evtClass the event type + * @param prop the resource bundle + * @param source the subsystem ID who creates the log event + * @param level the severity of the log event + * @param multiline the log message has more than one line or not + * @param msg the detail message of the log + * @param params the parameters in the detail log message + */ + public ILogEvent create(LogCategory evtClass, Properties prop, LogSource source, + int level, boolean multiline, String msg, Object params[]) { + if (evtClass != ILogger.EV_AUDIT) + return null; + AuditEvent event = new AuditEvent(msg, params); + + event.setLevel(level); + event.setSource(source); + event.setMultiline(multiline); + setProperties(prop, event); + return event; + } +} diff --git a/base/server/cms/src/com/netscape/cms/logging/LogFactory.java b/base/server/cms/src/com/netscape/cms/logging/LogFactory.java new file mode 100644 index 000000000..d624a56ff --- /dev/null +++ b/base/server/cms/src/com/netscape/cms/logging/LogFactory.java @@ -0,0 +1,65 @@ +// --- 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.cms.logging; + +import java.util.Properties; + +import com.netscape.certsrv.logging.IBundleLogEvent; +import com.netscape.certsrv.logging.ILogEvent; +import com.netscape.certsrv.logging.ILogEventFactory; +import com.netscape.certsrv.logging.LogCategory; +import com.netscape.certsrv.logging.LogSource; + +public abstract class LogFactory implements ILogEventFactory { + + public static final String PROP_BUNDLE = "bundleName"; + + public LogFactory() { + } + + public Logger createLogger(LogCategory category, LogSource source) { + return new Logger(this, category, source); + } + + /** + * Set the resource bundle of the log event. + * + * @param prop the properties + * @param event the log event + */ + protected void setProperties(Properties prop, IBundleLogEvent event) { + if (prop == null) { + event.setBundleName(null); + } else { + String bundleName = (String) prop.get(PROP_BUNDLE); + + if (bundleName != null) { + event.setBundleName(bundleName); + } + } + } + + /** + * Releases an log event. + * + * @param e the log event + */ + public void release(ILogEvent e) { + // do nothing + } +} diff --git a/base/server/cms/src/com/netscape/cms/logging/LogQueue.java b/base/server/cms/src/com/netscape/cms/logging/LogQueue.java new file mode 100644 index 000000000..1b4067690 --- /dev/null +++ b/base/server/cms/src/com/netscape/cms/logging/LogQueue.java @@ -0,0 +1,117 @@ +// --- 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.cms.logging; + +import java.util.Vector; + +import com.netscape.certsrv.logging.ELogException; +import com.netscape.certsrv.logging.ILogEvent; +import com.netscape.certsrv.logging.ILogEventListener; +import com.netscape.certsrv.logging.ILogQueue; + +/** + * A class represents a log queue. + *

+ * + * @author mzhao + * @version $Revision$, $Date$ + */ +public class LogQueue implements ILogQueue { + + private static LogQueue mLogQueue = new LogQueue(); + protected Vector mListeners = new Vector(); + + /** + * Constructs a log queue. + */ + public LogQueue() { + } + + public static ILogQueue getLogQueue() { + return mLogQueue; + } + + /** + * Initializes the log queue. + *

+ * + */ + public void init() { + mListeners.clear(); + + } + + /** + * Stops this log queue: shuts down all registered listeners + *

+ */ + public void shutdown() { + for (int i = 0; i < mListeners.size(); i++) { + ILogEventListener listener = mListeners.elementAt(i); + listener.shutdown(); + } + } + + /** + * Adds an event listener. + * + * @param listener the log event listener + */ + public void addLogEventListener(ILogEventListener listener) { + //Make sure we don't have duplicated listener + if (!mListeners.contains(listener)) { + mListeners.addElement(listener); + } + } + + /** + * Removes an event listener. + * + * @param listener the log event listener + */ + public void removeLogEventListener(ILogEventListener listener) { + mListeners.removeElement(listener); + } + + /** + * Logs an event, and notifies logger to reuse the event. + * + * @param event the log event + */ + public void log(ILogEvent event) { + for (int i = 0; i < mListeners.size(); i++) { + try { + mListeners.elementAt(i).log(event); + } catch (ELogException e) { + // Raidzilla Bug #57592: Don't display potentially + // incorrect log message. + // ConsoleError.send(new SystemEvent(CMS.getUserMessage("CMS_LOG_EVENT_FAILED", + // event.getEventType(), e.toString()))); + } + } + } + + /** + * Flushes the log buffers (if any) + */ + public void flush() { + for (int i = 0; i < mListeners.size(); i++) { + mListeners.elementAt(i).flush(); + } + } +} diff --git a/base/server/cms/src/com/netscape/cms/logging/Logger.java b/base/server/cms/src/com/netscape/cms/logging/Logger.java new file mode 100644 index 000000000..ccba6e2a9 --- /dev/null +++ b/base/server/cms/src/com/netscape/cms/logging/Logger.java @@ -0,0 +1,407 @@ +// --- 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.cms.logging; + +import java.util.Hashtable; +import java.util.Properties; + +import com.netscape.certsrv.logging.ILogEvent; +import com.netscape.certsrv.logging.ILogQueue; +import com.netscape.certsrv.logging.ILogger; +import com.netscape.certsrv.logging.LogCategory; +import com.netscape.certsrv.logging.LogSource; + +/** + * A class represents certificate server logger + * implementation. + *

+ * + * @author thomask + * @author mzhao + * @version $Revision$, $Date$ + */ +public class Logger implements ILogger { + + protected static Logger mLogger = new Logger(); + protected ILogQueue mLogQueue = LogQueue.getLogQueue(); + protected static Hashtable mFactories = new Hashtable(); + + static { + register(EV_AUDIT, new AuditEventFactory()); + register(EV_SYSTEM, new SystemEventFactory()); + register(EV_SIGNED_AUDIT, new SignedAuditEventFactory()); + } + + LogFactory factory; + LogCategory category; + LogSource source; + + public Logger() { + } + + public Logger(LogFactory factory, LogCategory category, LogSource source) { + this.factory = factory; + this.category = category; + this.source = source; + } + + /** + * get default single global logger + */ + static public Logger getLogger() { + return mLogger; + } + + public static Logger getLogger(LogCategory category, LogSource source) { + + LogFactory factory = mFactories.get(category); + + if (factory == null) { + throw new RuntimeException("Unknown logger category: " + category); + } + + return factory.createLogger(category, source); + } + + /** + * 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 static void register(LogCategory evtClass, LogFactory 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource source, String msg) { + log(evtClass, props, source, ILogger.LL_INFO, msg, null); + } + + //************** no param **************** + + public void log(int level, String msg) { + log(category, null, source, level, msg); + } + + /** + * 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties prop, LogSource source, int level, String msg, + Object params[]) { + ILogEvent iLEvent = create(evtClass, prop, source, level, msg, params, ILogger.L_SINGLELINE); + if (iLEvent != null) + mLogQueue.log(iLEvent); + } + + //******************** 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties prop, LogSource source, int level, String msg, + Object params[], boolean multiline) { + ILogEvent iLEvent = create(evtClass, prop, source, level, msg, params, multiline); + if (iLEvent != null) + mLogQueue.log(iLEvent); + } + + //******************** end multiline log ************************* + + public ILogEvent create(int level, String msg, Object params[], boolean multiline) { + return create(category, null, source, level, msg, params, multiline); + } + + /** + * Creates generic log event. If required, we can recycle + * events here. + */ + //XXXXXXXXXXX prop is out dated!!!! XXXXXXXXXXXXXXX + public ILogEvent create(LogCategory evtClass, Properties prop, LogSource source, int level, + String msg, Object params[], boolean multiline) { + + LogFactory f = factory == null ? mFactories.get(evtClass) : factory; + + if (f == null) { + throw new RuntimeException("Unknown logger category: " + evtClass); + } + + 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. + } + +} diff --git a/base/server/cms/src/com/netscape/cms/logging/SignedAuditEventFactory.java b/base/server/cms/src/com/netscape/cms/logging/SignedAuditEventFactory.java new file mode 100644 index 000000000..472037d41 --- /dev/null +++ b/base/server/cms/src/com/netscape/cms/logging/SignedAuditEventFactory.java @@ -0,0 +1,94 @@ +// --- 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.cms.logging; + +import java.util.Properties; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.logging.ILogEvent; +import com.netscape.certsrv.logging.ILogger; +import com.netscape.certsrv.logging.LogCategory; +import com.netscape.certsrv.logging.LogSource; +import com.netscape.certsrv.logging.SignedAuditEvent; + +/** + * A log event object for handling system messages + *

+ * + * @author mikep + * @author mzhao + * @author cfu + * @version $Revision$, $Date$ + */ +public class SignedAuditEventFactory extends LogFactory { + + /** + * Constructs a system event factory. + */ + public SignedAuditEventFactory() { + } + + /** + * Creates an log event. + * + * @param evtClass the event type + * @param prop the resource bundle + * @param source the subsystem ID who creates the log event + * @param level the severity of the log event + * @param multiline the log message has more than one line or not + * @param msg the detail message of the log + * @param params the parameters in the detail log message + */ + public ILogEvent create(LogCategory evtClass, Properties prop, LogSource source, + int level, boolean multiline, String msg, Object params[]) { + if (evtClass != ILogger.EV_SIGNED_AUDIT) + return null; + + String message = null; + // assume msg format :message + String typeMessage = msg.trim(); + String eventType = null; + int typeBegin = typeMessage.indexOf(":"); + + eventType = typeMessage.substring(typeBegin + 6, colon); + message = typeMessage.substring(colon + 2); + //CMS.debug("SignedAuditEventFactory: create() message=" + message + "\n"); + CMS.debug("SignedAuditEventFactory: create() message created for eventType=" + eventType + "\n"); + + } else { + // no type specified + message = msg; + } + + SignedAuditEvent event = new SignedAuditEvent(message.trim(), params); + + if (eventType != null) + event.setEventType(eventType.trim()); + + event.setLevel(level); + event.setSource(source); + event.setMultiline(multiline); + setProperties(prop, event); + + return event; + } +} diff --git a/base/server/cms/src/com/netscape/cms/logging/SignedAuditLogger.java b/base/server/cms/src/com/netscape/cms/logging/SignedAuditLogger.java new file mode 100644 index 000000000..aaf96ae9f --- /dev/null +++ b/base/server/cms/src/com/netscape/cms/logging/SignedAuditLogger.java @@ -0,0 +1,39 @@ +// --- 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.cms.logging; + +/** + * A class represents certificate server logger + * implementation. + *

+ * + * @author thomask + * @author mzhao + * @version $Revision$, $Date$ + */ +public class SignedAuditLogger extends Logger { + + /** + * Constructs a generic logger, and registers a list + * of resident event factories. + */ + public SignedAuditLogger() { + super(); + register(EV_SIGNED_AUDIT, new SignedAuditEventFactory()); + } +} diff --git a/base/server/cms/src/com/netscape/cms/logging/SystemEventFactory.java b/base/server/cms/src/com/netscape/cms/logging/SystemEventFactory.java new file mode 100644 index 000000000..f5e31936a --- /dev/null +++ b/base/server/cms/src/com/netscape/cms/logging/SystemEventFactory.java @@ -0,0 +1,67 @@ +// --- 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.cms.logging; + +import java.util.Properties; + +import com.netscape.certsrv.logging.ILogEvent; +import com.netscape.certsrv.logging.ILogger; +import com.netscape.certsrv.logging.LogCategory; +import com.netscape.certsrv.logging.LogSource; +import com.netscape.certsrv.logging.SystemEvent; + +/** + * A log event object for handling system messages + *

+ * + * @author mikep + * @author mzhao + * @version $Revision$, $Date$ + */ +public class SystemEventFactory extends LogFactory { + + /** + * Constructs a system event factory. + */ + public SystemEventFactory() { + } + + /** + * Creates an log event. + * + * @param evtClass the event type + * @param prop the resource bundle + * @param source the subsystem ID who creates the log event + * @param level the severity of the log event + * @param multiline the log message has more than one line or not + * @param msg the detail message of the log + * @param params the parameters in the detail log message + */ + public ILogEvent create(LogCategory evtClass, Properties prop, LogSource source, + int level, boolean multiline, String msg, Object params[]) { + if (evtClass != ILogger.EV_SYSTEM) + return null; + SystemEvent event = new SystemEvent(msg, params); + + event.setLevel(level); + event.setSource(source); + event.setMultiline(multiline); + setProperties(prop, event); + return event; + } +} diff --git a/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java b/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java index b111f71d3..4d0384a2b 100644 --- a/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java +++ b/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java @@ -117,6 +117,8 @@ import com.netscape.certsrv.ra.IRegistrationAuthority; import com.netscape.certsrv.request.IRequest; import com.netscape.certsrv.request.IRequestQueue; import com.netscape.certsrv.request.RequestStatus; +import com.netscape.cms.logging.Logger; +import com.netscape.cms.logging.SignedAuditLogger; import com.netscape.cmscore.authentication.AuthSubsystem; import com.netscape.cmscore.authentication.VerifiedCert; import com.netscape.cmscore.authentication.VerifiedCerts; @@ -148,8 +150,6 @@ import com.netscape.cmscore.ldapconn.LdapConnInfo; import com.netscape.cmscore.ldapconn.PKISocketFactory; import com.netscape.cmscore.logging.Auditor; import com.netscape.cmscore.logging.LogSubsystem; -import com.netscape.cmscore.logging.Logger; -import com.netscape.cmscore.logging.SignedAuditLogger; import com.netscape.cmscore.notification.EmailFormProcessor; import com.netscape.cmscore.notification.EmailResolverKeys; import com.netscape.cmscore.notification.EmailTemplate; diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/AuditEventFactory.java b/base/server/cmscore/src/com/netscape/cmscore/logging/AuditEventFactory.java deleted file mode 100644 index 06230b14c..000000000 --- a/base/server/cmscore/src/com/netscape/cmscore/logging/AuditEventFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -// --- 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.Properties; - -import com.netscape.certsrv.logging.AuditEvent; -import com.netscape.certsrv.logging.ILogEvent; -import com.netscape.certsrv.logging.ILogger; -import com.netscape.certsrv.logging.LogCategory; -import com.netscape.certsrv.logging.LogSource; - -/** - * A log event object for handling audit messages - *

- * - * @author mikep - * @author mzhao - * @version $Revision$, $Date$ - */ -public class AuditEventFactory extends LogFactory { - - /** - * Constructs a audit event factory. - */ - public AuditEventFactory() { - } - - /** - * Creates an log event. - * - * @param evtClass the event type - * @param prop the resource bundle - * @param source the subsystem ID who creates the log event - * @param level the severity of the log event - * @param multiline the log message has more than one line or not - * @param msg the detail message of the log - * @param params the parameters in the detail log message - */ - public ILogEvent create(LogCategory evtClass, Properties prop, LogSource source, - int level, boolean multiline, String msg, Object params[]) { - if (evtClass != ILogger.EV_AUDIT) - return null; - AuditEvent event = new AuditEvent(msg, params); - - event.setLevel(level); - event.setSource(source); - event.setMultiline(multiline); - setProperties(prop, event); - return event; - } -} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/LogFactory.java b/base/server/cmscore/src/com/netscape/cmscore/logging/LogFactory.java deleted file mode 100644 index 855acf981..000000000 --- a/base/server/cmscore/src/com/netscape/cmscore/logging/LogFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -// --- 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.Properties; - -import com.netscape.certsrv.logging.IBundleLogEvent; -import com.netscape.certsrv.logging.ILogEvent; -import com.netscape.certsrv.logging.ILogEventFactory; -import com.netscape.certsrv.logging.LogCategory; -import com.netscape.certsrv.logging.LogSource; - -public abstract class LogFactory implements ILogEventFactory { - - public static final String PROP_BUNDLE = "bundleName"; - - public LogFactory() { - } - - public Logger createLogger(LogCategory category, LogSource source) { - return new Logger(this, category, source); - } - - /** - * Set the resource bundle of the log event. - * - * @param prop the properties - * @param event the log event - */ - protected void setProperties(Properties prop, IBundleLogEvent event) { - if (prop == null) { - event.setBundleName(null); - } else { - String bundleName = (String) prop.get(PROP_BUNDLE); - - if (bundleName != null) { - event.setBundleName(bundleName); - } - } - } - - /** - * Releases an log event. - * - * @param e the log event - */ - public void release(ILogEvent e) { - // do nothing - } -} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/LogQueue.java b/base/server/cmscore/src/com/netscape/cmscore/logging/LogQueue.java deleted file mode 100644 index 1c477f751..000000000 --- a/base/server/cmscore/src/com/netscape/cmscore/logging/LogQueue.java +++ /dev/null @@ -1,117 +0,0 @@ -// --- 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.Vector; - -import com.netscape.certsrv.logging.ELogException; -import com.netscape.certsrv.logging.ILogEvent; -import com.netscape.certsrv.logging.ILogEventListener; -import com.netscape.certsrv.logging.ILogQueue; - -/** - * A class represents a log queue. - *

- * - * @author mzhao - * @version $Revision$, $Date$ - */ -public class LogQueue implements ILogQueue { - - private static LogQueue mLogQueue = new LogQueue(); - protected Vector mListeners = new Vector(); - - /** - * Constructs a log queue. - */ - public LogQueue() { - } - - public static ILogQueue getLogQueue() { - return mLogQueue; - } - - /** - * Initializes the log queue. - *

- * - */ - public void init() { - mListeners.clear(); - - } - - /** - * Stops this log queue: shuts down all registered listeners - *

- */ - public void shutdown() { - for (int i = 0; i < mListeners.size(); i++) { - ILogEventListener listener = mListeners.elementAt(i); - listener.shutdown(); - } - } - - /** - * Adds an event listener. - * - * @param listener the log event listener - */ - public void addLogEventListener(ILogEventListener listener) { - //Make sure we don't have duplicated listener - if (!mListeners.contains(listener)) { - mListeners.addElement(listener); - } - } - - /** - * Removes an event listener. - * - * @param listener the log event listener - */ - public void removeLogEventListener(ILogEventListener listener) { - mListeners.removeElement(listener); - } - - /** - * Logs an event, and notifies logger to reuse the event. - * - * @param event the log event - */ - public void log(ILogEvent event) { - for (int i = 0; i < mListeners.size(); i++) { - try { - mListeners.elementAt(i).log(event); - } catch (ELogException e) { - // Raidzilla Bug #57592: Don't display potentially - // incorrect log message. - // ConsoleError.send(new SystemEvent(CMS.getUserMessage("CMS_LOG_EVENT_FAILED", - // event.getEventType(), e.toString()))); - } - } - } - - /** - * Flushes the log buffers (if any) - */ - public void flush() { - for (int i = 0; i < mListeners.size(); i++) { - mListeners.elementAt(i).flush(); - } - } -} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/LogSubsystem.java b/base/server/cmscore/src/com/netscape/cmscore/logging/LogSubsystem.java index 0fe3ac622..ba405c2cd 100644 --- a/base/server/cmscore/src/com/netscape/cmscore/logging/LogSubsystem.java +++ b/base/server/cmscore/src/com/netscape/cmscore/logging/LogSubsystem.java @@ -30,6 +30,7 @@ import com.netscape.certsrv.logging.ILogEventListener; import com.netscape.certsrv.logging.ILogQueue; import com.netscape.certsrv.logging.ILogSubsystem; import com.netscape.certsrv.logging.LogPlugin; +import com.netscape.cms.logging.LogQueue; import com.netscape.cmscore.util.Debug; /** diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/Logger.java b/base/server/cmscore/src/com/netscape/cmscore/logging/Logger.java deleted file mode 100644 index 4b47a8712..000000000 --- a/base/server/cmscore/src/com/netscape/cmscore/logging/Logger.java +++ /dev/null @@ -1,407 +0,0 @@ -// --- 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.ILogQueue; -import com.netscape.certsrv.logging.ILogger; -import com.netscape.certsrv.logging.LogCategory; -import com.netscape.certsrv.logging.LogSource; - -/** - * A class represents certificate server logger - * implementation. - *

- * - * @author thomask - * @author mzhao - * @version $Revision$, $Date$ - */ -public class Logger implements ILogger { - - protected static Logger mLogger = new Logger(); - protected ILogQueue mLogQueue = LogQueue.getLogQueue(); - protected static Hashtable mFactories = new Hashtable(); - - static { - register(EV_AUDIT, new AuditEventFactory()); - register(EV_SYSTEM, new SystemEventFactory()); - register(EV_SIGNED_AUDIT, new SignedAuditEventFactory()); - } - - LogFactory factory; - LogCategory category; - LogSource source; - - public Logger() { - } - - public Logger(LogFactory factory, LogCategory category, LogSource source) { - this.factory = factory; - this.category = category; - this.source = source; - } - - /** - * get default single global logger - */ - static public Logger getLogger() { - return mLogger; - } - - public static Logger getLogger(LogCategory category, LogSource source) { - - LogFactory factory = mFactories.get(category); - - if (factory == null) { - throw new RuntimeException("Unknown logger category: " + category); - } - - return factory.createLogger(category, source); - } - - /** - * 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 static void register(LogCategory evtClass, LogFactory 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource source, String msg) { - log(evtClass, props, source, ILogger.LL_INFO, msg, null); - } - - //************** no param **************** - - public void log(int level, String msg) { - log(category, null, source, level, msg); - } - - /** - * 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties prop, LogSource source, int level, String msg, - Object params[]) { - ILogEvent iLEvent = create(evtClass, prop, source, level, msg, params, ILogger.L_SINGLELINE); - if (iLEvent != null) - mLogQueue.log(iLEvent); - } - - //******************** 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, Properties props, LogSource 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(LogCategory evtClass, LogSource 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(LogCategory evtClass, Properties prop, LogSource source, int level, String msg, - Object params[], boolean multiline) { - ILogEvent iLEvent = create(evtClass, prop, source, level, msg, params, multiline); - if (iLEvent != null) - mLogQueue.log(iLEvent); - } - - //******************** end multiline log ************************* - - public ILogEvent create(int level, String msg, Object params[], boolean multiline) { - return create(category, null, source, level, msg, params, multiline); - } - - /** - * Creates generic log event. If required, we can recycle - * events here. - */ - //XXXXXXXXXXX prop is out dated!!!! XXXXXXXXXXXXXXX - public ILogEvent create(LogCategory evtClass, Properties prop, LogSource source, int level, - String msg, Object params[], boolean multiline) { - - LogFactory f = factory == null ? mFactories.get(evtClass) : factory; - - if (f == null) { - throw new RuntimeException("Unknown logger category: " + evtClass); - } - - 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. - } - -} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditEventFactory.java b/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditEventFactory.java deleted file mode 100644 index 22400f5ea..000000000 --- a/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditEventFactory.java +++ /dev/null @@ -1,94 +0,0 @@ -// --- 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.Properties; - -import com.netscape.certsrv.apps.CMS; -import com.netscape.certsrv.logging.ILogEvent; -import com.netscape.certsrv.logging.ILogger; -import com.netscape.certsrv.logging.LogCategory; -import com.netscape.certsrv.logging.LogSource; -import com.netscape.certsrv.logging.SignedAuditEvent; - -/** - * A log event object for handling system messages - *

- * - * @author mikep - * @author mzhao - * @author cfu - * @version $Revision$, $Date$ - */ -public class SignedAuditEventFactory extends LogFactory { - - /** - * Constructs a system event factory. - */ - public SignedAuditEventFactory() { - } - - /** - * Creates an log event. - * - * @param evtClass the event type - * @param prop the resource bundle - * @param source the subsystem ID who creates the log event - * @param level the severity of the log event - * @param multiline the log message has more than one line or not - * @param msg the detail message of the log - * @param params the parameters in the detail log message - */ - public ILogEvent create(LogCategory evtClass, Properties prop, LogSource source, - int level, boolean multiline, String msg, Object params[]) { - if (evtClass != ILogger.EV_SIGNED_AUDIT) - return null; - - String message = null; - // assume msg format :message - String typeMessage = msg.trim(); - String eventType = null; - int typeBegin = typeMessage.indexOf(":"); - - eventType = typeMessage.substring(typeBegin + 6, colon); - message = typeMessage.substring(colon + 2); - //CMS.debug("SignedAuditEventFactory: create() message=" + message + "\n"); - CMS.debug("SignedAuditEventFactory: create() message created for eventType=" + eventType + "\n"); - - } else { - // no type specified - message = msg; - } - - SignedAuditEvent event = new SignedAuditEvent(message.trim(), params); - - if (eventType != null) - event.setEventType(eventType.trim()); - - event.setLevel(level); - event.setSource(source); - event.setMultiline(multiline); - setProperties(prop, event); - - return event; - } -} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditLogger.java b/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditLogger.java deleted file mode 100644 index 4b6fd55a2..000000000 --- a/base/server/cmscore/src/com/netscape/cmscore/logging/SignedAuditLogger.java +++ /dev/null @@ -1,39 +0,0 @@ -// --- 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; - -/** - * A class represents certificate server logger - * implementation. - *

- * - * @author thomask - * @author mzhao - * @version $Revision$, $Date$ - */ -public class SignedAuditLogger extends Logger { - - /** - * Constructs a generic logger, and registers a list - * of resident event factories. - */ - public SignedAuditLogger() { - super(); - register(EV_SIGNED_AUDIT, new SignedAuditEventFactory()); - } -} diff --git a/base/server/cmscore/src/com/netscape/cmscore/logging/SystemEventFactory.java b/base/server/cmscore/src/com/netscape/cmscore/logging/SystemEventFactory.java deleted file mode 100644 index 3a8cd8d5c..000000000 --- a/base/server/cmscore/src/com/netscape/cmscore/logging/SystemEventFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -// --- 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.Properties; - -import com.netscape.certsrv.logging.ILogEvent; -import com.netscape.certsrv.logging.ILogger; -import com.netscape.certsrv.logging.LogCategory; -import com.netscape.certsrv.logging.LogSource; -import com.netscape.certsrv.logging.SystemEvent; - -/** - * A log event object for handling system messages - *

- * - * @author mikep - * @author mzhao - * @version $Revision$, $Date$ - */ -public class SystemEventFactory extends LogFactory { - - /** - * Constructs a system event factory. - */ - public SystemEventFactory() { - } - - /** - * Creates an log event. - * - * @param evtClass the event type - * @param prop the resource bundle - * @param source the subsystem ID who creates the log event - * @param level the severity of the log event - * @param multiline the log message has more than one line or not - * @param msg the detail message of the log - * @param params the parameters in the detail log message - */ - public ILogEvent create(LogCategory evtClass, Properties prop, LogSource source, - int level, boolean multiline, String msg, Object params[]) { - if (evtClass != ILogger.EV_SYSTEM) - return null; - SystemEvent event = new SystemEvent(msg, params); - - event.setLevel(level); - event.setSource(source); - event.setMultiline(multiline); - setProperties(prop, event); - return event; - } -} -- cgit