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>filtersThe event filtersstatic org.slf4j.Loggerloggerprotected java.util.Set<java.lang.String>mandatoryEventsThe mandatory log event typesprotected intmBufferSizeThe output buffer size in bytesprotected intmBytesUnflushedThe number of unflushed bytesprotected intmBytesWrittenThe number of bytes written to the current log fileprotected IConfigStoremConfigprotected java.util.DatemDateThe date object used for log entriesprotected java.lang.StringmDatePatternThe log date entry format patternprotected java.io.FilemFileThe log fileprotected java.lang.StringmFileNameThe log file nameprotected intmFlushIntervalThe output buffer flush intervalprotected longmLevelThe log level threshold Only logs with level greater or equal than this value will be writtenprotected java.text.SimpleDateFormatmLogDateFormatThe log date entry formatprotected java.text.SimpleDateFormatmLogFileDateFormatprotected booleanmLogSigningLog signing is on/offprotected java.io.BufferedWritermLogWriterThe log file output streamprotected booleanmOnThe log is turned on/offprotected booleanmRegisterShould this log listener self-register or notprotected booleanmTraceprotected java.lang.StringmTypeThe eventType that this log is triggeredstatic java.lang.StringPROP_LEVELstatic java.lang.StringPROP_ONstatic java.lang.StringPROP_REGISTERstatic java.lang.StringPROP_SIGNED_AUDIT_CERT_NICKNAMEstatic java.lang.StringPROP_SIGNED_AUDIT_FILTERSstatic java.lang.StringPROP_SIGNED_AUDIT_LOG_SIGNINGstatic java.lang.StringPROP_SIGNED_AUDIT_MANDATORY_EVENTSstatic java.lang.StringPROP_SIGNED_AUDIT_SELECTED_EVENTSstatic java.lang.StringPROP_TRACEstatic java.lang.StringPROP_TYPEprotected java.util.Set<java.lang.String>selectedEventsThe 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.Stringbase64Encode(byte[] bytes)protected voidclose()Close the log filevoiddeselectEvent(java.lang.String event)remove the event from the selected events listprotected voiddoLog(ILogEvent event)Synchronized method to write an event to the log file.booleaneval(SignedAuditEvent event, netscape.ldap.client.JDAPFilter filter)booleaneval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterAnd filter)booleaneval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterEqualityMatch filter)booleaneval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterNot filter)booleaneval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterOr filter)booleaneval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterPresent filter)booleaneval(SignedAuditEvent event, netscape.ldap.client.JDAPFilterSubString filter)voidfilter(SignedAuditEvent ev)voidflush()Flush the log file.IConfigStoregetConfigStore()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.StringgetDescription()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.StringgetImplName()Returns implementation name.java.util.Vector<java.lang.String>getInstanceParams()Return list of instance config parameters for this log event listener.longgetLevel()Retrieves the log level threshold.java.lang.StringgetName()Retrieves the base log file name.java.lang.StringgetOn()Retrieves the log on/off.java.lang.StringgetType()Retrieves the eventType this log is triggered.voidinit(IConfigStore config)Initialize and open the log using the parameters from a config storevoidinit(ISubsystem owner, IConfigStore config)Initialize this log listenervoidinit(java.lang.String fileName, int bufferSize, int flushInterval)Initialize and open the logvoidlog(ILogEvent ev)Write an event to the log filejava.lang.StringlogEvt2String(ILogEvent ev)protected voidopen()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 entriesvoidreplaceEvents(java.lang.String events)replace the selected events listNameValuePairsretrieveLogContent(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".NameValuePairsretrieveLogList(java.util.Hashtable<java.lang.String,java.lang.String> req)Retrieve log file list.voidselectEvent(java.lang.String event)add the event to the selected events listvoidsetFlushInterval(int flushInterval)Set the flush intervalvoidshutdown()Shutdown this log file.voidstartup()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:ILogEventListenerInitialize this log listener- Specified by:
initin 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.IOExceptionEBaseException
-
init
public void init(java.lang.String fileName, int bufferSize, int flushInterval) throws java.io.IOException, ELogExceptionInitialize 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.IOExceptionELogException
-
startup
public void startup() throws EBaseExceptionStartup the instance- signed.audit LOGGING_SIGNED_AUDIT_AUDIT_LOG_STARTUP used at audit function startup
- Specified by:
startupin 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.IOExceptionOpen 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:
flushin 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:
shutdownin 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:
login 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:
getConfigStorein 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:
retrieveLogContentin 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:
retrieveLogListin interfaceILogEventListener- Throws:
javax.servlet.ServletExceptionjava.io.IOExceptionEBaseException
-
getImplName
public java.lang.String getImplName()
Description copied from interface:ILogEventListenerReturns implementation name.- Specified by:
getImplNamein interfaceILogEventListener- Returns:
- String name of event listener implementation.
-
getDescription
public java.lang.String getDescription()
Description copied from interface:ILogEventListenerReturns the description of this log event listener.- Specified by:
getDescriptionin interfaceILogEventListener- Returns:
- String with listener description.
-
getDefaultParams
public java.util.Vector<java.lang.String> getDefaultParams()
Description copied from interface:ILogEventListenerReturn list of default config parameters for this log event listener.- Specified by:
getDefaultParamsin interfaceILogEventListener- Returns:
- Vector of default parameters.
-
getInstanceParams
public java.util.Vector<java.lang.String> getInstanceParams()
Description copied from interface:ILogEventListenerReturn list of instance config parameters for this log event listener.- Specified by:
getInstanceParamsin interfaceILogEventListener- Returns:
- Vector of instance parameters.
-
getExtendedPluginInfo
public java.lang.String[] getExtendedPluginInfo(java.util.Locale locale)
Description copied from interface:IExtendedPluginInfoThis 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:
getExtendedPluginInfoin interfaceIExtendedPluginInfo
-
-