Class LogFile

  • All Implemented Interfaces:
    IExtendedPluginInfo, com.netscape.certsrv.logging.ILogEventListener, java.util.EventListener
    Direct Known Subclasses:
    RollingLogFile

    public class LogFile
    extends java.lang.Object
    implements com.netscape.certsrv.logging.ILogEventListener, IExtendedPluginInfo
    A log event listener which write logs to log files
    Version:
    $Revision$, $Date$
    • Constructor Summary

      Constructors 
      Constructor Description
      LogFile()
      Constructor for a LogFile.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String base64Encode​(byte[] bytes)  
      protected void close()
      Close the log file
      void deselectEvent​(java.lang.String event)
      remove the event from the selected events list
      protected void doLog​(com.netscape.certsrv.logging.ILogEvent event)
      Synchronized method to write an event to the log file.
      boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event, netscape.ldap.client.JDAPFilter filter)  
      boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event, netscape.ldap.client.JDAPFilterAnd filter)  
      boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event, netscape.ldap.client.JDAPFilterEqualityMatch filter)  
      boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event, netscape.ldap.client.JDAPFilterNot filter)  
      boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event, netscape.ldap.client.JDAPFilterOr filter)  
      boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event, netscape.ldap.client.JDAPFilterPresent filter)  
      boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event, netscape.ldap.client.JDAPFilterSubString filter)  
      void filter​(com.netscape.certsrv.logging.SignedAuditEvent ev)  
      void flush()
      Flush the log file.
      IConfigStore getConfigStore()
      Retrieves the configuration store of this subsystem.
      java.util.Vector<java.lang.String> getDefaultParams()
      Return list of default config parameters for this log event listener.
      java.lang.String getDescription()
      Returns the description of this log event listener.
      java.lang.String[] getExtendedPluginInfo​(java.util.Locale locale)
      This method returns an array of strings.
      java.lang.String getImplName()
      Returns implementation name.
      java.util.Vector<java.lang.String> getInstanceParams()
      Return list of instance config parameters for this log event listener.
      long getLevel()
      Retrieves the log level threshold.
      java.lang.String getName()
      Retrieves the base log file name.
      java.lang.String getOn()
      Retrieves the log on/off.
      java.lang.String getType()
      Retrieves the eventType this log is triggered.
      void init​(IConfigStore config)
      Initialize and open the log using the parameters from a config store
      void init​(ISubsystem owner, IConfigStore config)
      Initialize this log listener
      void init​(java.lang.String fileName, int bufferSize, int flushInterval)
      Initialize and open the log
      void log​(com.netscape.certsrv.logging.ILogEvent ev)
      Write an event to the log file
      java.lang.String logEvt2String​(com.netscape.certsrv.logging.ILogEvent ev)  
      protected void open()
      Open the log file.
      java.util.Vector<LogEntry> readEntry​(int maxLine, int lowLevel, com.netscape.certsrv.logging.LogSource source, java.lang.String fName)
      Read all entries whose logLevel>=lowLevel && log source = source to at most maxLine entries(from end) If the parameter is -1, it's ignored and return all entries
      void replaceEvents​(java.lang.String events)
      replace the selected events list
      com.netscape.certsrv.common.NameValuePairs retrieveLogContent​(java.util.Hashtable<java.lang.String,​java.lang.String> req)
      Retrieve last "maxLine" number of system log with log lever >"level" and from source "source".
      com.netscape.certsrv.common.NameValuePairs retrieveLogList​(java.util.Hashtable<java.lang.String,​java.lang.String> req)
      Retrieve log file list.
      void selectEvent​(java.lang.String event)
      add the event to the selected events list
      void setFlushInterval​(int flushInterval)
      Set the flush interval
      void shutdown()
      Shutdown this log file.
      void startup()
      Startup the instance
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        public static org.slf4j.Logger logger
      • PROP_SIGNED_AUDIT_LOG_SIGNING

        public static final java.lang.String PROP_SIGNED_AUDIT_LOG_SIGNING
        See Also:
        Constant Field Values
      • PROP_SIGNED_AUDIT_CERT_NICKNAME

        public static final java.lang.String PROP_SIGNED_AUDIT_CERT_NICKNAME
        See Also:
        Constant Field Values
      • PROP_SIGNED_AUDIT_SELECTED_EVENTS

        public static final java.lang.String PROP_SIGNED_AUDIT_SELECTED_EVENTS
        See Also:
        Constant Field Values
      • PROP_SIGNED_AUDIT_MANDATORY_EVENTS

        public static final java.lang.String PROP_SIGNED_AUDIT_MANDATORY_EVENTS
        See Also:
        Constant Field Values
      • PROP_SIGNED_AUDIT_FILTERS

        public static final java.lang.String PROP_SIGNED_AUDIT_FILTERS
        See Also:
        Constant Field Values
      • mLogFileDateFormat

        protected java.text.SimpleDateFormat mLogFileDateFormat
      • mFile

        protected java.io.File mFile
        The log file
      • mFileName

        protected java.lang.String mFileName
        The log file name
      • mLogWriter

        protected java.io.BufferedWriter mLogWriter
        The log file output stream
      • mDatePattern

        protected java.lang.String mDatePattern
        The log date entry format pattern
      • mLogDateFormat

        protected java.text.SimpleDateFormat mLogDateFormat
        The log date entry format
      • mDate

        protected java.util.Date mDate
        The date object used for log entries
      • mBytesWritten

        protected int mBytesWritten
        The number of bytes written to the current log file
      • mBufferSize

        protected int mBufferSize
        The output buffer size in bytes
      • mFlushInterval

        protected int mFlushInterval
        The output buffer flush interval
      • mBytesUnflushed

        protected int mBytesUnflushed
        The number of unflushed bytes
      • mandatoryEvents

        protected java.util.Set<java.lang.String> mandatoryEvents
        The mandatory log event types
      • selectedEvents

        protected java.util.Set<java.lang.String> selectedEvents
        The selected log event types
      • filters

        protected java.util.Map<java.lang.String,​netscape.ldap.client.JDAPFilter> filters
        The event filters
      • mType

        protected java.lang.String mType
        The eventType that this log is triggered
      • mOn

        protected boolean mOn
        The log is turned on/off
      • mRegister

        protected boolean mRegister
        Should this log listener self-register or not
      • mTrace

        protected boolean mTrace
      • mLogSigning

        protected boolean mLogSigning
        Log signing is on/off
      • mLevel

        protected long mLevel
        The log level threshold Only logs with level greater or equal than this value will be written
    • Constructor Detail

      • LogFile

        public LogFile()
        Constructor for a LogFile.
    • Method Detail

      • init

        public void init​(ISubsystem owner,
                         IConfigStore config)
                  throws EBaseException
        Description copied from interface: com.netscape.certsrv.logging.ILogEventListener
        Initialize this log listener
        Specified by:
        init in interface com.netscape.certsrv.logging.ILogEventListener
        Parameters:
        owner - The subsystem.
        config - Configuration store for this log listener.
        Throws:
        EBaseException
      • selectEvent

        public void selectEvent​(java.lang.String event)
        add the event to the selected events list
        Parameters:
        event - to be selected
      • deselectEvent

        public void deselectEvent​(java.lang.String event)
        remove the event from the selected events list
        Parameters:
        event - to be de-selected
      • replaceEvents

        public void replaceEvents​(java.lang.String events)
        replace the selected events list
        Parameters:
        events - comma-separated event list
      • base64Encode

        public static java.lang.String base64Encode​(byte[] bytes)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • init

        public void init​(IConfigStore config)
                  throws java.io.IOException,
                         EBaseException
        Initialize and open the log using the parameters from a config store
        Parameters:
        config - The property config store to find values in
        Throws:
        java.io.IOException
        EBaseException
      • init

        public void init​(java.lang.String fileName,
                         int bufferSize,
                         int flushInterval)
                  throws java.io.IOException,
                         com.netscape.certsrv.logging.ELogException
        Initialize and open the log
        Parameters:
        bufferSize - The buffer size for the output stream in bytes
        flushInterval - The interval in seconds to flush the log
        Throws:
        java.io.IOException
        com.netscape.certsrv.logging.ELogException
      • startup

        public void startup()
                     throws EBaseException
        Startup the instance

        • signed.audit LOGGING_SIGNED_AUDIT_AUDIT_LOG_STARTUP used at audit function startup
        Specified by:
        startup in interface com.netscape.certsrv.logging.ILogEventListener
        Throws:
        EBaseException - if an internal error occurred
      • getType

        public java.lang.String getType()
        Retrieves the eventType this log is triggered.
      • getOn

        public java.lang.String getOn()
        Retrieves the log on/off.
      • getLevel

        public long getLevel()
        Retrieves the log level threshold.
      • getName

        public java.lang.String getName()
        Retrieves the base log file name.
      • open

        protected void open()
                     throws java.io.IOException
        Open the log file. This creates the buffered FileWriter
        Throws:
        java.io.IOException
      • flush

        public void flush()
        Flush the log file. Also update the MAC for hash protected logs
        Specified by:
        flush in interface com.netscape.certsrv.logging.ILogEventListener
      • close

        protected void close()
        Close the log file
      • shutdown

        public void shutdown()
        Shutdown this log file.

        • signed.audit AUDIT_LOG_SHUTDOWN used at audit function shutdown
        Specified by:
        shutdown in interface com.netscape.certsrv.logging.ILogEventListener
      • setFlushInterval

        public void setFlushInterval​(int flushInterval)
        Set the flush interval

        Parameters:
        flushInterval - The amount of time in seconds until the log is flush. A value of 0 will disable autoflush. This will also set the update period for hash protected logs.
      • doLog

        protected void doLog​(com.netscape.certsrv.logging.ILogEvent event)
                      throws com.netscape.certsrv.logging.ELogException
        Synchronized method to write an event to the log file.
        Parameters:
        event - The log event
        Throws:
        com.netscape.certsrv.logging.ELogException
      • log

        public void log​(com.netscape.certsrv.logging.ILogEvent ev)
                 throws com.netscape.certsrv.logging.ELogException
        Write an event to the log file
        Specified by:
        log in interface com.netscape.certsrv.logging.ILogEventListener
        Parameters:
        ev - The event to be logged.
        Throws:
        com.netscape.certsrv.logging.ELogException
      • filter

        public void filter​(com.netscape.certsrv.logging.SignedAuditEvent ev)
                    throws com.netscape.certsrv.logging.ELogException
        Throws:
        com.netscape.certsrv.logging.ELogException
      • eval

        public boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event,
                            netscape.ldap.client.JDAPFilter filter)
      • eval

        public boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event,
                            netscape.ldap.client.JDAPFilterPresent filter)
      • eval

        public boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event,
                            netscape.ldap.client.JDAPFilterEqualityMatch filter)
      • eval

        public boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event,
                            netscape.ldap.client.JDAPFilterSubString filter)
      • eval

        public boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event,
                            netscape.ldap.client.JDAPFilterAnd filter)
      • eval

        public boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event,
                            netscape.ldap.client.JDAPFilterOr filter)
      • eval

        public boolean eval​(com.netscape.certsrv.logging.SignedAuditEvent event,
                            netscape.ldap.client.JDAPFilterNot filter)
      • logEvt2String

        public java.lang.String logEvt2String​(com.netscape.certsrv.logging.ILogEvent ev)
      • readEntry

        public java.util.Vector<LogEntry> readEntry​(int maxLine,
                                                    int lowLevel,
                                                    com.netscape.certsrv.logging.LogSource source,
                                                    java.lang.String fName)
        Read all entries whose logLevel>=lowLevel && log source = source to at most maxLine entries(from end) If the parameter is -1, it's ignored and return all entries
        Parameters:
        maxLine - The maximum lines to be returned
        lowLevel - The lowest log level to be returned
        source - The particular log source to be returned
        fName - The log file name to be read. If it's null, read the current log file
      • getConfigStore

        public IConfigStore getConfigStore()
        Retrieves the configuration store of this subsystem.

        Specified by:
        getConfigStore in interface com.netscape.certsrv.logging.ILogEventListener
        Returns:
        configuration store
      • retrieveLogContent

        public com.netscape.certsrv.common.NameValuePairs retrieveLogContent​(java.util.Hashtable<java.lang.String,​java.lang.String> req)
                                                                      throws javax.servlet.ServletException,
                                                                             java.io.IOException,
                                                                             EBaseException
        Retrieve last "maxLine" number of system log with log lever >"level" and from source "source". If the parameter is omitted. All entries are sent back.
        Specified by:
        retrieveLogContent in interface com.netscape.certsrv.logging.ILogEventListener
        Parameters:
        req - a Hashtable containing the required information such as log entry, log level, log source, and log name.
        Returns:
        NameValue pair list of log messages.
        Throws:
        javax.servlet.ServletException - For Servelet errros.
        java.io.IOException - For input/output problems.
        EBaseException - For other problems.
      • retrieveLogList

        public com.netscape.certsrv.common.NameValuePairs retrieveLogList​(java.util.Hashtable<java.lang.String,​java.lang.String> req)
                                                                   throws javax.servlet.ServletException,
                                                                          java.io.IOException,
                                                                          EBaseException
        Retrieve log file list.
        Specified by:
        retrieveLogList in interface com.netscape.certsrv.logging.ILogEventListener
        Throws:
        javax.servlet.ServletException
        java.io.IOException
        EBaseException
      • getImplName

        public java.lang.String getImplName()
        Description copied from interface: com.netscape.certsrv.logging.ILogEventListener
        Returns implementation name.
        Specified by:
        getImplName in interface com.netscape.certsrv.logging.ILogEventListener
        Returns:
        String name of event listener implementation.
      • getDescription

        public java.lang.String getDescription()
        Description copied from interface: com.netscape.certsrv.logging.ILogEventListener
        Returns the description of this log event listener.
        Specified by:
        getDescription in interface com.netscape.certsrv.logging.ILogEventListener
        Returns:
        String with listener description.
      • getDefaultParams

        public java.util.Vector<java.lang.String> getDefaultParams()
        Description copied from interface: com.netscape.certsrv.logging.ILogEventListener
        Return list of default config parameters for this log event listener.
        Specified by:
        getDefaultParams in interface com.netscape.certsrv.logging.ILogEventListener
        Returns:
        Vector of default parameters.
      • getInstanceParams

        public java.util.Vector<java.lang.String> getInstanceParams()
        Description copied from interface: com.netscape.certsrv.logging.ILogEventListener
        Return list of instance config parameters for this log event listener.
        Specified by:
        getInstanceParams in interface com.netscape.certsrv.logging.ILogEventListener
        Returns:
        Vector of instance parameters.
      • getExtendedPluginInfo

        public java.lang.String[] getExtendedPluginInfo​(java.util.Locale locale)
        Description copied from interface: IExtendedPluginInfo
        This method returns an array of strings. Each element of the array represents a configurable parameter, or some other meta-info (such as help-token) there is an entry indexed on that parameter name ;[,required];;... Where: type_info is either 'string', 'number', 'boolean', 'password' or 'choice(ch1,ch2,ch3,...)' If the marker 'required' is included after the type_info, the parameter will has some visually distinctive marking in the UI. 'description' is a short sentence describing the parameter 'choice' is rendered as a drop-down list. The first parameter in the list will be activated by default 'boolean' is rendered as a checkbox. The resulting parameter will be either 'true' or 'false' 'string' allows any characters 'number' allows only numbers 'password' is rendered as a password field (the characters are replaced with *'s when being types. This parameter is not passed through to the plugin. It is instead inserted directly into the password cache keyed on the instance name. The value of the parameter 'bindPWPrompt' (see example below) is set to the key. In addition to the configurable parameters, the following magic parameters may be defined: HELP_TOKEN;helptoken - a pointer to the online manual section for this plugin HELP_TEXT;helptext - a general help string describing the plugin For example: "username;string;The username you wish to login as" "bindPWPrompt;password;Enter password to bind as above user with" "algorithm;choice(RSA,DSA);Which algorithm do you want to use" "enable;boolean;Do you want to run this plugin" "port;number;Which port number do you want to use"
        Specified by:
        getExtendedPluginInfo in interface IExtendedPluginInfo