Package com.netscape.cms.logging
Class LogFile
- java.lang.Object
-
- 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$, $Date$
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,netscape.ldap.client.JDAPFilter>
filters
The event filtersstatic org.slf4j.Logger
logger
protected java.util.Set<java.lang.String>
mandatoryEvents
The mandatory log event typesprotected int
mBufferSize
The output buffer size in bytesprotected int
mBytesUnflushed
The number of unflushed bytesprotected int
mBytesWritten
The number of bytes written to the current log fileprotected IConfigStore
mConfig
protected java.util.Date
mDate
The date object used for log entriesprotected java.lang.String
mDatePattern
The log date entry format patternprotected java.io.File
mFile
The log fileprotected java.lang.String
mFileName
The log file nameprotected int
mFlushInterval
The output buffer flush intervalprotected long
mLevel
The log level threshold Only logs with level greater or equal than this value will be writtenprotected java.text.SimpleDateFormat
mLogDateFormat
The log date entry formatprotected java.text.SimpleDateFormat
mLogFileDateFormat
protected boolean
mLogSigning
Log signing is on/offprotected java.io.BufferedWriter
mLogWriter
The log file output streamprotected boolean
mOn
The log is turned on/offprotected boolean
mRegister
Should this log listener self-register or notprotected boolean
mTrace
protected java.lang.String
mType
The eventType that this log is triggeredstatic 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_FILTERS
static java.lang.String
PROP_SIGNED_AUDIT_LOG_SIGNING
static java.lang.String
PROP_SIGNED_AUDIT_MANDATORY_EVENTS
static java.lang.String
PROP_SIGNED_AUDIT_SELECTED_EVENTS
static java.lang.String
PROP_TRACE
static java.lang.String
PROP_TYPE
protected java.util.Set<java.lang.String>
selectedEvents
The selected log event types-
Fields inherited from interface com.netscape.certsrv.base.IExtendedPluginInfo
HELP_TEXT, HELP_TOKEN
-
-
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 filevoid
deselectEvent(java.lang.String event)
remove the event from the selected events listprotected void
doLog(ILogEvent event)
Synchronized method to write an event to the log file.boolean
eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilter filter)
boolean
eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterAnd filter)
boolean
eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterEqualityMatch filter)
boolean
eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterNot filter)
boolean
eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterOr filter)
boolean
eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterPresent filter)
boolean
eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterSubString filter)
void
filter(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 storevoid
init(ISubsystem owner, IConfigStore config)
Initialize this log listenervoid
init(java.lang.String fileName, int bufferSize, int flushInterval)
Initialize and open the logvoid
log(ILogEvent ev)
Write an event to the log filejava.lang.String
logEvt2String(ILogEvent ev)
protected void
open()
Open the log file.java.util.Vector<LogEntry>
readEntry(int maxLine, int lowLevel, 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 entriesvoid
replaceEvents(java.lang.String events)
replace the selected events listNameValuePairs
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".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 listvoid
setFlushInterval(int flushInterval)
Set the flush intervalvoid
shutdown()
Shutdown this log file.void
startup()
Startup the instance
-
-
-
Field Detail
-
logger
public static org.slf4j.Logger logger
-
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_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
-
PROP_LEVEL
public static final java.lang.String PROP_LEVEL
- See Also:
- Constant Field Values
-
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
-
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
-
-
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 interfaceILogEventListener
- 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, ELogException
Initialize and open the log- Parameters:
bufferSize
- The buffer size for the output stream in bytesflushInterval
- The interval in seconds to flush the log- Throws:
java.io.IOException
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 interfaceILogEventListener
- 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 interfaceILogEventListener
-
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 interfaceILogEventListener
-
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(ILogEvent event) throws ELogException
Synchronized method to write an event to the log file.- Parameters:
event
- The log event- Throws:
ELogException
-
log
public void log(ILogEvent ev) throws ELogException
Write an event to the log file- Specified by:
log
in interfaceILogEventListener
- Parameters:
ev
- The event to be logged.- Throws:
ELogException
-
filter
public void filter(SignedAuditEvent ev) throws ELogException
- Throws:
ELogException
-
eval
public boolean eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilter filter)
-
eval
public boolean eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterPresent filter)
-
eval
public boolean eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterEqualityMatch filter)
-
eval
public boolean eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterSubString filter)
-
eval
public boolean eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterAnd filter)
-
eval
public boolean eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterOr filter)
-
eval
public boolean eval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterNot filter)
-
logEvt2String
public java.lang.String logEvt2String(ILogEvent ev)
-
readEntry
public java.util.Vector<LogEntry> readEntry(int maxLine, int lowLevel, 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 returnedlowLevel
- The lowest log level to be returnedsource
- The particular log source to be returnedfName
- 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 interfaceILogEventListener
- Returns:
- configuration store
-
retrieveLogContent
public 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 interfaceILogEventListener
- 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<java.lang.String,java.lang.String> req) throws javax.servlet.ServletException, java.io.IOException, EBaseException
Retrieve log file list.- Specified by:
retrieveLogList
in interfaceILogEventListener
- 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 interfaceILogEventListener
- 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 interfaceILogEventListener
- Returns:
- String with listener description.
-
getDefaultParams
public java.util.Vector<java.lang.String> getDefaultParams()
Description copied from interface:ILogEventListener
Return list of default config parameters for this log event listener.- Specified by:
getDefaultParams
in interfaceILogEventListener
- Returns:
- Vector of default parameters.
-
getInstanceParams
public java.util.Vector<java.lang.String> getInstanceParams()
Description copied from interface:ILogEventListener
Return list of instance config parameters for this log event listener.- Specified by:
getInstanceParams
in interfaceILogEventListener
- 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 interfaceIExtendedPluginInfo
-
-