jrunx.logger
Class FileLogEventHandler

jrunx.kernel.ServiceAdapter
  |
  +--jrunx.kernel.ServicePartition
        |
        +--jrunx.kernel.ConfigurableServicePartition
              |
              +--jrunx.logger.LogEventHandler
                    |
                    +--jrunx.logger.FileLogEventHandler
All Implemented Interfaces:
ConfigurableServicePartitionMBean, FileLogEventHandlerMBean, LogEventHandlerMBean, javax.naming.Referenceable, java.lang.Runnable, java.io.Serializable, Service, ServiceMBean, ServicePartitionMBean

public class FileLogEventHandler
extends LogEventHandler
implements FileLogEventHandlerMBean, java.lang.Runnable

Sends log events to a file.

Author:
Karl Moss
See Also:
Serialized Form

Field Summary
protected  long closeDelay
           
protected  java.lang.String currentFilename
           
static long DEFAULT_CLOSE_DELAY
           
static java.lang.String DEFAULT_FILENAME
           
static int DEFAULT_ROTATION_FILES
           
static java.lang.String DEFAULT_ROTATION_SIZE
           
protected  long lastWriteTime
           
protected static java.lang.String newline
           
protected static int newlineLen
           
protected  java.io.PrintWriter out
           
protected  boolean scheduled
           
 
Fields inherited from class jrunx.kernel.ServicePartition
sortedServices
 
Fields inherited from class jrunx.kernel.ServiceAdapter
DEFAULT_DEACTIVATED, DEFAULT_DOMAIN, DOMAIN_NAME_SEPARATOR, DOMAIN_NAME_SUFFIX, domainName, jndiBindable, LOGGER_CACHE_TIME, SCHEDULER_SERVICE, SECURITY_MANAGER, server, status, TRANSACTION_MANAGER
 
Fields inherited from interface jrunx.kernel.Service
INITIALIZED, STARTED, STARTING, STOPPED, STOPPING, UNINITIALIZED
 
Constructor Summary
FileLogEventHandler()
           
 
Method Summary
protected  void calculateRotationSize()
           
protected  void checkForRotation(LogEvent event, java.lang.String msg)
          Check to see if a file rotation is necessary
protected  void closeFile()
           
static java.lang.String computeLocalizedLogFileHeading(java.lang.String format)
           
static java.lang.String expandServerDate(java.lang.String formatString)
           
 long getCloseDelay()
          Gets the number of milliseconds to wait before closing the physical file.
 boolean getDeleteOnExit()
          Gets the value of the delete on exit flag.
 java.lang.String getFilename()
          Gets the name of the file to be used for logging
 long getFileSize()
          Gets the size of the file to be used for logging
 java.lang.String getHeading()
          Gets the heading that will be written into each new file that is created.
 int getRotationFiles()
          Gets the number of rotated files to maintain.
protected  java.lang.String getRotationName(java.lang.String filename, int n)
          Format a rotation filename given the original name and the rotation number
 java.lang.String getRotationSize()
          Gets the rotation size of the file
 int getRotationSizeValue()
           
 boolean logEvent(LogEvent event)
           
protected  java.io.PrintWriter openFile(java.lang.String fname)
          Open the given file.
protected  boolean removeFile(java.lang.String name)
          Attempt to delete the given file
protected  boolean renameFile(java.lang.String name, java.lang.String newName)
          Attempt to rename the given file
 void run()
           
 void setCloseDelay(long delay)
          Sets the number of milliseconds to wait before closing the physical file.
 void setDeleteOnExit(boolean deleteOnExit)
          Sets the flag for deleting log files from previous server runs.
 void setFilename(java.lang.String filename)
          Sets the name of the file to be used for logging
 void setHeading(java.lang.String heading)
          Sets the heading that will be written into each new file that is created.
 void setRotationFiles(int files)
          Specify the number of rotated files to maintain.
 void setRotationSize(java.lang.String size)
          Sets the rotation size of the file.
 void start()
          Every service other than mere data collections should start
 void stop()
          Every service other than mere data collections should stop
 
Methods inherited from class jrunx.logger.LogEventHandler
clearBuffer, flush, getFormat, log, setFormat
 
Methods inherited from class jrunx.kernel.ConfigurableServicePartition
destroy, destroyServices, init, initServices, loadAndInit, loadChildren, setChildElements, startServices, stopServices
 
Methods inherited from class jrunx.kernel.ServicePartition
addService, addService, getServices, invokeChain, iterator, removeService, removeService
 
Methods inherited from class jrunx.kernel.ServiceAdapter
bind, findObjectInstance, findObjectInstance, findObjectInstance, getBindToJNDI, getDeactivated, getDomainName, getDomainSearchPath, getJRunService, getLogger, getName, getParentService, getReference, getResourceManager, getServerName, getServerProperties, getStatus, invokeMethod, isInPartition, isPartition, lookup, postDeregister, postRegister, preDeregister, preRegister, requestServer, scheduleRunnable, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, toString, unbind, unscheduleRunnable, updateStatus
 
Methods inherited from interface jrunx.logger.LogEventHandlerMBean
flush, getFormat, log, setFormat
 
Methods inherited from interface jrunx.kernel.ServiceMBean
bind, getBindToJNDI, getDeactivated, getDomainName, getJRunService, getLogger, getName, getParentService, getServerName, requestServer, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, unbind
 
Methods inherited from interface jrunx.kernel.Service
destroy, getStatus, init, updateStatus
 
Methods inherited from interface jrunx.kernel.ServicePartitionMBean
addService, addService, iterator, removeService, removeService
 

Field Detail

DEFAULT_FILENAME

public static final java.lang.String DEFAULT_FILENAME

DEFAULT_ROTATION_SIZE

public static final java.lang.String DEFAULT_ROTATION_SIZE

DEFAULT_ROTATION_FILES

public static final int DEFAULT_ROTATION_FILES

DEFAULT_CLOSE_DELAY

public static final long DEFAULT_CLOSE_DELAY

newline

protected static java.lang.String newline

newlineLen

protected static int newlineLen

closeDelay

protected long closeDelay

lastWriteTime

protected long lastWriteTime

currentFilename

protected java.lang.String currentFilename

out

protected java.io.PrintWriter out

scheduled

protected boolean scheduled
Constructor Detail

FileLogEventHandler

public FileLogEventHandler()
Method Detail

setDeleteOnExit

public void setDeleteOnExit(boolean deleteOnExit)
Sets the flag for deleting log files from previous server runs.
Specified by:
setDeleteOnExit in interface FileLogEventHandlerMBean
Parameters:
deleteOnExit - The delete on exit flag.

getDeleteOnExit

public boolean getDeleteOnExit()
Gets the value of the delete on exit flag.
Specified by:
getDeleteOnExit in interface FileLogEventHandlerMBean
Returns:
The delete on exit flag.

setFilename

public void setFilename(java.lang.String filename)
Description copied from interface: FileLogEventHandlerMBean
Sets the name of the file to be used for logging
Specified by:
setFilename in interface FileLogEventHandlerMBean
Following copied from interface: jrunx.logger.FileLogEventHandlerMBean
Parameters:
filename - The filename

getFilename

public java.lang.String getFilename()
Description copied from interface: FileLogEventHandlerMBean
Gets the name of the file to be used for logging
Specified by:
getFilename in interface FileLogEventHandlerMBean
Following copied from interface: jrunx.logger.FileLogEventHandlerMBean
Returns:
The filename

getFileSize

public long getFileSize()
Description copied from interface: FileLogEventHandlerMBean
Gets the size of the file to be used for logging
Specified by:
getFileSize in interface FileLogEventHandlerMBean
Following copied from interface: jrunx.logger.FileLogEventHandlerMBean
Returns:
The size of the file

setRotationSize

public void setRotationSize(java.lang.String size)
Description copied from interface: FileLogEventHandlerMBean
Sets the rotation size of the file. The rotation size is the maximum size of the log file before rotating. If the size of the log file will exceed the rotationsize after the log event is written, the log file will be rotated. The number of rotation files is given in rotationFiles. For example if rotationFiles = 3, rotationsize = 1000, and filename = event.log, and the size of the file will exceed the rotationsize with a new event, the following will take place: event_3.log will be deleted event_2.log is renamed to event_3.log event_1.log is renamed to event_2.log event.log is renamed to event_1.log a new event.log is created

The file number will be inserted before an extension if one exists (such as event.log -> event_1.log); otherwise the file number will be appended to the file (such as event -> event_1).

The default rotation size is 100000.

Rotation sizes can include a suffix of 'm' or 'k', for megabytes or kilobytes. For example, 100k or 1m. The suffix is case insensitive.

Specified by:
setRotationSize in interface FileLogEventHandlerMBean
Following copied from interface: jrunx.logger.FileLogEventHandlerMBean
Parameters:
size - The rotation size

getRotationSize

public java.lang.String getRotationSize()
Description copied from interface: FileLogEventHandlerMBean
Gets the rotation size of the file
Specified by:
getRotationSize in interface FileLogEventHandlerMBean
Following copied from interface: jrunx.logger.FileLogEventHandlerMBean
Returns:
The rotation size

getRotationSizeValue

public int getRotationSizeValue()

calculateRotationSize

protected void calculateRotationSize()

setRotationFiles

public void setRotationFiles(int files)
Description copied from interface: FileLogEventHandlerMBean
Specify the number of rotated files to maintain. The default is 9.
Specified by:
setRotationFiles in interface FileLogEventHandlerMBean
Following copied from interface: jrunx.logger.FileLogEventHandlerMBean
Parameters:
files - The number of rotation files

getRotationFiles

public int getRotationFiles()
Description copied from interface: FileLogEventHandlerMBean
Gets the number of rotated files to maintain.
Specified by:
getRotationFiles in interface FileLogEventHandlerMBean
Following copied from interface: jrunx.logger.FileLogEventHandlerMBean
Returns:
The number of rotation files

setHeading

public void setHeading(java.lang.String heading)
Description copied from interface: FileLogEventHandlerMBean
Sets the heading that will be written into each new file that is created.
Specified by:
setHeading in interface FileLogEventHandlerMBean
Following copied from interface: jrunx.logger.FileLogEventHandlerMBean
Parameters:
heading - The heading

getHeading

public java.lang.String getHeading()
Description copied from interface: FileLogEventHandlerMBean
Gets the heading that will be written into each new file that is created.
Specified by:
getHeading in interface FileLogEventHandlerMBean
Following copied from interface: jrunx.logger.FileLogEventHandlerMBean
Returns:
The heading

setCloseDelay

public void setCloseDelay(long delay)
Description copied from interface: FileLogEventHandlerMBean
Sets the number of milliseconds to wait before closing the physical file. Once this number of milliseconds passes with no other messages being written to the file, the file will be closed. The default is 5000 (5 seconds). Setting to 0 causes the file to be closed after every write.
Specified by:
setCloseDelay in interface FileLogEventHandlerMBean
Following copied from interface: jrunx.logger.FileLogEventHandlerMBean
Parameters:
delay - The close delay in milliseconds

getCloseDelay

public long getCloseDelay()
Description copied from interface: FileLogEventHandlerMBean
Gets the number of milliseconds to wait before closing the physical file.
Specified by:
getCloseDelay in interface FileLogEventHandlerMBean
Following copied from interface: jrunx.logger.FileLogEventHandlerMBean
Returns:
The close delay in milliseconds

start

public void start()
Description copied from class: ServiceAdapter
Every service other than mere data collections should start
Specified by:
start in interface Service
Overrides:
start in class ConfigurableServicePartition

stop

public void stop()
          throws java.lang.Exception
Description copied from class: ServiceAdapter
Every service other than mere data collections should stop
Specified by:
stop in interface Service
Overrides:
stop in class ConfigurableServicePartition

logEvent

public boolean logEvent(LogEvent event)
Overrides:
logEvent in class LogEventHandler

checkForRotation

protected void checkForRotation(LogEvent event,
                                java.lang.String msg)
Check to see if a file rotation is necessary
Parameters:
event - The log event into the current log

closeFile

protected void closeFile()

openFile

protected java.io.PrintWriter openFile(java.lang.String fname)
Open the given file. The file is opened in append mode with auto-flush on.
Parameters:
filename - The filename
Returns:
A print writer to the file, or null if not opened.

getRotationName

protected java.lang.String getRotationName(java.lang.String filename,
                                           int n)
Format a rotation filename given the original name and the rotation number

removeFile

protected boolean removeFile(java.lang.String name)
Attempt to delete the given file
Parameters:
name - The name of the file
Returns:
true if the file was deleted

renameFile

protected boolean renameFile(java.lang.String name,
                             java.lang.String newName)
Attempt to rename the given file
Parameters:
name - The name of the file
newName - The new name of the file
Returns:
true if the file was renamed

expandServerDate

public static java.lang.String expandServerDate(java.lang.String formatString)

computeLocalizedLogFileHeading

public static java.lang.String computeLocalizedLogFileHeading(java.lang.String format)

run

public void run()
Specified by:
run in interface java.lang.Runnable


Copyright � 2002 Macromedia Corporation. All Rights Reserved.