Servertec
Foundation Classes
1.3.3 09/04/2005

stec.sfc.Win32
Class EventLog

java.lang.Object
  extended by stec.sfc.Win32.EventLog

public final class EventLog
extends java.lang.Object

Used to add and remove event log sources and to add, read, backup and clear messages in the Windows NT/2000/XP event log.

Local Mode is used to resolve EventLogRecord external refernces such as Category, Expanded Parameters, Message and User Name using resources relative to the computer the EventLog is on. Defaults to true.

Raw Mode is used to retrieve EventLogRecords without resolving external references such as User Name. Defaults to false.

Since:
1.0.0 01/07/2001

Field Summary
static java.lang.String APPLICATION
          Used when adding sources to the Application log.
static int BACKWARDS_READ_DIRECTION
          Read backwards.
static int FORWARDS_READ_DIRECTION
          Read forwards.
static java.lang.String SECURITY
          Used when adding sources to the Security log.
static java.lang.String SYSTEM
          Used when adding sources to the System log.
 
Constructor Summary
EventLog(java.lang.String eventlog)
          Creates a new EventLog object.
EventLog(java.lang.String hostname, java.lang.String eventlog)
          Creates a new EventLog object.
EventLog(java.lang.String hostname, java.lang.String eventlog, boolean register_event_source)
          Creates a new EventLog object.
 
Method Summary
static void addSource(java.lang.String eventlog, java.lang.String name, java.lang.String path, int events, int categories)
          Adds the named event source to the specified event log.
 void backup(java.lang.String filename)
          Used to backup the event log to the specified file.
 void clear()
          Clears the event log.
 void clear(java.lang.String filename)
          Used to backup and clear the event log.
 void close()
          Close the event log.
 EventLogRecord get(int record_number)
          Returns the specified EventLogRecord.
 EventLogRecord get(int record_number, int read_direction)
          Returns the specified EventLogRecord.
 java.lang.String getEventLog()
          Returns the name of the event log being used.
 java.lang.String getHostname()
          Returns the name of the computer whose event log is being used.
 boolean isFull()
          Returns whether the event log is full.
 boolean localMode()
          Returns whether the EventLogRecords will use resources relative to the computer the EventLog is on to resolve Category, Expanded Parameters, Message and User Name.
 void localMode(boolean local_mode)
          Sets whether the EventLogRecords will use local resources relative to the computer the EventLog is on to resolve Category, Expanded Parameters, Message and User Name.
 void log(int event_type, int categoryid, int eventid, java.lang.String[] parameters, byte[] data)
          Adds the specified message to the event log.
 void log(int event_type, int categoryid, int eventid, java.lang.String[] parameters, byte[] data, int bytes)
          Adds the specified message to the event log.
 void log(int event_type, java.lang.String parameter)
          Adds the specified message to the event log.
 void log(int event_type, java.lang.String[] parameters)
          Adds the specified message to the event log.
 EventLogRecord next()
          Returns the next EventLogRecord.
 EventLogRecord previous()
          Returns the previous EventLogRecord.
 boolean rawMode()
          Returns whether the EventLogRecords are retrieved in raw mode.
 void rawMode(boolean raw_mode)
          Sets whether the EventLogRecords are to be retrieved in raw mode.
static void removeSource(java.lang.String eventlog, java.lang.String name)
          Removes the named event source from the specified event log.
 int size()
          Returns the number of events in the current event log.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BACKWARDS_READ_DIRECTION

public static final int BACKWARDS_READ_DIRECTION
Read backwards.

Set to EVENTLOG_BACKWARDS_READ.


FORWARDS_READ_DIRECTION

public static final int FORWARDS_READ_DIRECTION
Read forwards.

Set to EVENTLOG_FORWARDS_READ.


APPLICATION

public static final java.lang.String APPLICATION
Used when adding sources to the Application log.

See Also:
Constant Field Values

SECURITY

public static final java.lang.String SECURITY
Used when adding sources to the Security log.

See Also:
Constant Field Values

SYSTEM

public static final java.lang.String SYSTEM
Used when adding sources to the System log.

See Also:
Constant Field Values
Constructor Detail

EventLog

public EventLog(java.lang.String eventlog)
         throws Win32Exception
Creates a new EventLog object.

Parameters:
eventlog - the name of the event log.

If Servertec Win32 event source is being used set this value to sfc.

Throws:
Win32Exception - if any error occurs.

EventLog

public EventLog(java.lang.String hostname,
                java.lang.String eventlog)
         throws Win32Exception
Creates a new EventLog object.

Parameters:
hostname - the name of the computer whose log will be used.
eventlog - the name of the event log.

If Servertec Win32 event source is being used set this value to sfc.

Throws:
Win32Exception - if any error occurs.

EventLog

public EventLog(java.lang.String hostname,
                java.lang.String eventlog,
                boolean register_event_source)
         throws Win32Exception
Creates a new EventLog object.

Parameters:
hostname - the name of the computer whose log will be used.
eventlog - the name of the event log.
register_event_source - whether to just open the event log or whether to also register the event source. Must be true when using log() otherwise can be false.

If Servertec Win32 event source is being used set this value to sfc.

Throws:
Win32Exception - if any error occurs.
Since:
1.2.3 10/01/2003
Method Detail

close

public final void close()
                 throws Win32Exception
Close the event log.

Throws:
Win32Exception - if any error occurs.

addSource

public static final void addSource(java.lang.String eventlog,
                                   java.lang.String name,
                                   java.lang.String path,
                                   int events,
                                   int categories)
                            throws Win32Exception
Adds the named event source to the specified event log.

Parameters:
eventlog - the name of the event log.

Normally Application is used. Other predefined event logs are Security and System.

If Servertec Win32 event source is being used set this value to Application.

name - the name of the new event source.

If Servertec Win32 event source is being used set this value to sfc.

path - the path to the .exe or .dll containing event source messages.

If Servertec Win32 event source is being used set this value to sfc_dirbin\sfc_wnt.dll in Windows NT or sfc_dirbin\sfc_w2k.dll in Windows 2000/XP.

events - the EventLogType.
categories - the number of event categories.

If Servertec Win32 event source is being used set this value to 1.

Throws:
Win32Exception - if any error occurs.

removeSource

public static final void removeSource(java.lang.String eventlog,
                                      java.lang.String name)
                               throws Win32Exception
Removes the named event source from the specified event log.

Once an event source is removed, messages for that event source will not be available for viewing.

Parameters:
eventlog - the name of the event log.

If Servertec Win32 event source is being used set this value to Application.

name - the name of the event source to remove.

If Servertec Win32 event source is being used set this value to sfc.

Throws:
Win32Exception - if any error occurs.

size

public final int size()
               throws Win32Exception,
                      java.io.IOException
Returns the number of events in the current event log.

Returns:
the number of events in the current event log.
Throws:
java.io.IOException - the EventLog has been closed.
Win32Exception - if any error occurs.

log

public final void log(int event_type,
                      int categoryid,
                      int eventid,
                      java.lang.String[] parameters,
                      byte[] data,
                      int bytes)
               throws Win32Exception,
                      java.io.IOException,
                      java.lang.ArrayIndexOutOfBoundsException
Adds the specified message to the event log.

Parameters:
event_type - the EventLogType.
categoryid - the category identifier.

If Servertec Win32 event source is being used set this value to 1.

eventid - the event identifier.

If Servertec Win32 event source is being used set this value to 0.

parameters - the array of Strings containing any progameter to the message to add to the event log.

If Servertec Win32 event source is being used use a single dimension String array containing a single String.

data - the byte array of binary data to log.
bytes - the number of bytes of binary data to log.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the length of the specified parameters string array is zero (0) or if the specified number of bytes to log is larger than the specified byte array.
java.io.IOException - the EventLog has been closed.
Win32Exception - if any error occurs.

clear

public final void clear(java.lang.String filename)
                 throws Win32Exception,
                        java.io.IOException
Used to backup and clear the event log.

Parameters:
filename - the name of the file to backup the event log to.
Throws:
java.io.IOException - the EventLog has been closed.
Win32Exception - if the file already exists or if any error occurs.

backup

public final void backup(java.lang.String filename)
                  throws Win32Exception,
                         java.io.IOException
Used to backup the event log to the specified file.

Parameters:
filename - the name of the file to backup the event log to.
Throws:
java.io.IOException - the EventLog has been closed.
Win32Exception - if the file already exists or if any error occurs.

log

public final void log(int event_type,
                      java.lang.String parameter)
               throws Win32Exception,
                      java.io.IOException
Adds the specified message to the event log.

Parameters:
event_type - the EventLogType.
parameters - the array of Strings containing any progameter to the message to add to the event log.
Throws:
java.io.IOException - the EventLog has been closed.
Win32Exception - if any error occurs.

log

public final void log(int event_type,
                      java.lang.String[] parameters)
               throws Win32Exception,
                      java.io.IOException
Adds the specified message to the event log.

Parameters:
event_type - the EventLogType.
parameters - the array of Strings containing any progameter to the message to add to the event log.

If Servertec Win32 event source is being used use a single dimension String array containing a single String.

Throws:
java.io.IOException - the EventLog has been closed.
Win32Exception - if any error occurs.

log

public final void log(int event_type,
                      int categoryid,
                      int eventid,
                      java.lang.String[] parameters,
                      byte[] data)
               throws Win32Exception,
                      java.io.IOException,
                      java.lang.ArrayIndexOutOfBoundsException
Adds the specified message to the event log.

Parameters:
event_type - the EventLogType.
categoryid - the category identifier.

If Servertec Win32 event source is being used set this value to 1.

eventid - the event identifier.

If Servertec Win32 event source is being used set this value to 0.

parameters - the array of Strings containing any progameter to the message to add to the event log.

If Servertec Win32 event source is being used use a single dimension String array containing a single String.

data - the byte array of binary data to log.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the length of the specified parameters string array is zero (0) or if the specified number of bytes to log is larger than the specified byte array.
java.io.IOException - the EventLog has been closed.
Win32Exception - if any error occurs.

clear

public final void clear()
                 throws Win32Exception,
                        java.io.IOException
Clears the event log.

Throws:
java.io.IOException - the EventLog has been closed.
Win32Exception - if any error occurs.

get

public final EventLogRecord get(int record_number,
                                int read_direction)
                         throws java.lang.IllegalArgumentException,
                                Win32Exception,
                                java.io.IOException
Returns the specified EventLogRecord.

Parameters:
record_number - the record number starting at 0 to size() - 1.
read_direction - the read direction.
Returns:
the EventLogRecord.
Throws:
java.io.IOException - the EventLog has been closed.
Win32Exception - if any error occurs.
java.lang.IllegalArgumentException
Since:
1.3.0 10/19/2003

get

public final EventLogRecord get(int record_number)
                         throws Win32Exception,
                                java.io.IOException
Returns the specified EventLogRecord.

Parameters:
record_number - the record number starting at 0 to size() - 1.
Returns:
the EventLogRecord.
Throws:
java.io.IOException - the EventLog has been closed.
Win32Exception - if any error occurs.
Since:
1.1.0 11/18/2001

previous

public final EventLogRecord previous()
                              throws Win32Exception,
                                     java.io.IOException
Returns the previous EventLogRecord.

Returns:
the previous EventLogRecord. null if none.
Throws:
java.io.IOException - the EventLog has been closed.
Win32Exception - if any error occurs.
Since:
1.1.3 09/08/2002

next

public final EventLogRecord next()
                          throws Win32Exception,
                                 java.io.IOException
Returns the next EventLogRecord.

Returns:
the next EventLogRecord. null if none.
Throws:
java.io.IOException - the EventLog has been closed.
Win32Exception - if any error occurs.
Since:
1.1.3 09/08/2002

isFull

public final boolean isFull()
                     throws Win32Exception,
                            java.io.IOException
Returns whether the event log is full.

Requires Windows 2000/XP.

Returns:
whether the event log is full.
Throws:
java.io.IOException - the EventLog has been closed.
Win32Exception - if any error occurs.
Since:
1.1.0 11/18/2001

rawMode

public final boolean rawMode()
Returns whether the EventLogRecords are retrieved in raw mode.

EventLogRecord.getUserNames() returns the username when Raw Mode is false and returns the SID when Raw Mode is true or when Raw Mode is false and the username cannot be found.

Returns:
whether the EventLogRecords are retrieved in raw mode.
Since:
1.3.1 09/07/2004

rawMode

public final void rawMode(boolean raw_mode)
Sets whether the EventLogRecords are to be retrieved in raw mode.

EventLogRecord.getUserNames() returns the username when Raw Mode is false and returns the SID when Raw Mode is true or when Raw Mode is false and the username cannot be found.

Parameters:
raw_mode - whether the EventLogRecords are to be retrieved in raw mode.
Since:
1.3.1 09/07/2004

localMode

public final boolean localMode()
Returns whether the EventLogRecords will use resources relative to the computer the EventLog is on to resolve Category, Expanded Parameters, Message and User Name.

Returns:
whether the EventLogRecords will use resources relative to the computer the EventLog is on.
Since:
1.3.2 06/29/2005

localMode

public final void localMode(boolean local_mode)
Sets whether the EventLogRecords will use local resources relative to the computer the EventLog is on to resolve Category, Expanded Parameters, Message and User Name.

Parameters:
local_mode - whether the EventLogRecords will use resources relative to the computer the EventLog is on.
Since:
1.3.2 06/29/2005

getHostname

public final java.lang.String getHostname()
Returns the name of the computer whose event log is being used.

Returns:
the name of the computer whose event log is being used. null is the default for the local computer.
Since:
1.3.2 06/29/2005

getEventLog

public final java.lang.String getEventLog()
Returns the name of the event log being used.

Returns:
the name of the event log being used.
Since:
1.3.2 06/29/2005

Servertec
Foundation Classes
1.3.3 09/04/2005

Copyright © 2001-2005 Servertec. All rights reserved.