com.netscape.cms.logging
Class LogFile

java.lang.Object
  extended by com.netscape.cms.logging.LogFile
All Implemented Interfaces:
IExtendedPluginInfo, ILogEventListener, java.util.EventListener
Direct Known Subclasses:
RollingLogFile

public class LogFile
extends java.lang.Object
implements ILogEventListener, IExtendedPluginInfo

A log event listener which write logs to log files

Version:
$Revision: 1599 $, $Date: 2010-12-02 12:22:49 -0800 (Thu, 02 Dec 2010) $

Field Summary
protected  int mBufferSize
          The output buffer size in bytes
protected  int mBytesUnflushed
          The number of unflushed bytes
protected  int mBytesWritten
          The number of bytes written to the current log file
protected  IConfigStore mConfig
           
protected  java.util.Date mDate
          The date object used for log entries
protected  java.lang.String mDatePattern
          The log date entry format pattern
protected  java.io.File mFile
          The log file
protected  java.lang.String mFileName
          The log file name
protected  int mFlushInterval
          The output buffer flush interval
protected  long mLevel
          The log level threshold Only logs with level greater or equal than this value will be written
protected  java.text.SimpleDateFormat mLogDateFormat
          The log date entry format
protected  java.text.SimpleDateFormat mLogFileDateFormat
           
protected  boolean mLogSigning
          Log signing is on/off
protected  java.io.BufferedWriter mLogWriter
          The log file output stream
protected  boolean mOn
          The log is turned on/off
protected  int mPid
          The current pid for the log entries
protected  boolean mRegister
          Should this log listener self-register or not
protected  java.util.Vector mSelectedEvents
           
protected  java.lang.String mSelectedEventsList
          The selected log event types
protected  ILogger mSignedAuditLogger
           
protected  boolean mTrace
           
protected  java.lang.String mType
          The eventType that this log is triggered
static java.lang.String PROP_LEVEL
           
static java.lang.String PROP_ON
           
static java.lang.String PROP_REGISTER
           
static java.lang.String PROP_SIGNED_AUDIT_CERT_NICKNAME
           
static java.lang.String PROP_SIGNED_AUDIT_EVENTS
           
static java.lang.String PROP_SIGNED_AUDIT_LOG_SIGNING
           
static java.lang.String PROP_TRACE
           
static java.lang.String PROP_TYPE
           
 
Fields inherited from interface com.netscape.certsrv.base.IExtendedPluginInfo
HELP_TEXT, HELP_TOKEN
 
Constructor Summary
LogFile()
          Constructor for a LogFile.
 
Method Summary
protected  void audit(java.lang.String msg)
          Signed Audit Log This method is inherited by all classes that extend this "LogFile" class, and is called to store messages to the signed audit log.
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
 void flush()
          Flush the log file.
 IConfigStore getConfigStore()
          Retrieves the configuration store of this subsystem.
 java.util.Vector 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 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(ILogEvent ev)
          Write an event to the log file
protected  void log(java.lang.String entry)
          Synchronized method to write a string to the log file.
 java.lang.String logEvt2String(ILogEvent ev)
           
protected  void open()
          Open the log file.
 java.util.Vector readEntry(int maxLine, int lowLevel, int 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
 NameValuePairs retrieveLogContent(java.util.Hashtable req)
          Retrieve last "maxLine" number of system log with log lever >"level" and from source "source".
 NameValuePairs retrieveLogList(java.util.Hashtable 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
protected  java.util.Vector string2Vector(java.lang.String theString)
          turns a comma-separated String into a Vector
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_TYPE

public static final java.lang.String PROP_TYPE
See Also:
Constant Field Values

PROP_REGISTER

public static final java.lang.String PROP_REGISTER
See Also:
Constant Field Values

PROP_ON

public static final java.lang.String PROP_ON
See Also:
Constant Field Values

PROP_TRACE

public static final java.lang.String PROP_TRACE
See Also:
Constant Field Values

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_EVENTS

public static final java.lang.String PROP_SIGNED_AUDIT_EVENTS
See Also:
Constant Field Values

PROP_LEVEL

public static final java.lang.String PROP_LEVEL
See Also:
Constant Field Values

mSignedAuditLogger

protected ILogger mSignedAuditLogger

mConfig

protected IConfigStore mConfig

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


mPid

protected int mPid
The current pid for the log entries


mSelectedEventsList

protected java.lang.String mSelectedEventsList
The selected log event types


mSelectedEvents

protected java.util.Vector mSelectedEvents

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: ILogEventListener
Initialize this log listener

Specified by:
init in interface ILogEventListener
Parameters:
owner - The subsystem.
config - Configuration store for this log listener.
Throws:
EBaseException

string2Vector

protected java.util.Vector string2Vector(java.lang.String theString)
turns a comma-separated String into a Vector


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,
                 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
ELogException

startup

public void startup()
             throws EBaseException
Startup the instance

Specified by:
startup in interface 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 ILogEventListener

close

protected void close()
Close the log file


shutdown

public void shutdown()
Shutdown this log file.

Specified by:
shutdown in interface 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.

log

protected void log(java.lang.String entry)
            throws ELogException
Synchronized method to write a string to the log file. All I18N should take place before this call.

Parameters:
entry - The log entry string
Throws:
ELogException

log

public void log(ILogEvent ev)
         throws ELogException
Write an event to the log file

Specified by:
log in interface ILogEventListener
Parameters:
ev - The event to be logged.
Throws:
ELogException

logEvt2String

public java.lang.String logEvt2String(ILogEvent ev)

readEntry

public java.util.Vector readEntry(int maxLine,
                                  int lowLevel,
                                  int 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 ILogEventListener
Returns:
configuration store

retrieveLogContent

public NameValuePairs retrieveLogContent(java.util.Hashtable 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 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 NameValuePairs retrieveLogList(java.util.Hashtable req)
                               throws javax.servlet.ServletException,
                                      java.io.IOException,
                                      EBaseException
Retrieve log file list.

Specified by:
retrieveLogList in interface ILogEventListener
Throws:
javax.servlet.ServletException
java.io.IOException
EBaseException

getImplName

public java.lang.String getImplName()
Description copied from interface: ILogEventListener
Returns implementation name.

Specified by:
getImplName in interface ILogEventListener
Returns:
String name of event listener implementation.

getDescription

public java.lang.String getDescription()
Description copied from interface: ILogEventListener
Returns the description of this log event listener.

Specified by:
getDescription in interface ILogEventListener
Returns:
String with listener description.

getDefaultParams

public java.util.Vector getDefaultParams()
Description copied from interface: ILogEventListener
Return list of default config parameters for this log event listener.

Specified by:
getDefaultParams in interface ILogEventListener
Returns:
Vector of default parameters.

getInstanceParams

public java.util.Vector getInstanceParams()
Description copied from interface: ILogEventListener
Return list of instance config parameters for this log event listener.

Specified by:
getInstanceParams in interface 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

audit

protected void audit(java.lang.String msg)
Signed Audit Log This method is inherited by all classes that extend this "LogFile" class, and is called to store messages to the signed audit log.

Parameters:
msg - signed audit log message