org.openmdx.kernel.log.impl
Class AbstractFileLoggingMechanism

java.lang.Object
  extended by org.openmdx.kernel.log.impl.AbstractLoggingMechanism
      extended by org.openmdx.kernel.log.impl.AbstractFileLoggingMechanism
All Implemented Interfaces:
ManageableMechanism
Direct Known Subclasses:
SharedFileLoggingMechanism, UniqueFileLoggingMechanism

public abstract class AbstractFileLoggingMechanism
extends AbstractLoggingMechanism

AbstractFileLoggingMechanism is an abstract class which defines the format and location of log files, so they all work consistently for the same application. The default file name where logs are created is:

      [Path][App][LogClass][date].[extn]

      where:      [Path]      = "c:\temp\"
                  [App]       = "App"
                  [LogClass]  = The Java Class name of the Log Class
                                (only used for unique logs)
                  [date]      = today's date (only used for dated logs)
                  [extn]      = "log"

 
The [App] default can be overridden by the application, it is taken from the associated logger class. The [Path] and [extn] defaults can be overridden by settings in a properties file, see the LogProperties class for more information.


Field Summary
 
Fields inherited from class org.openmdx.kernel.log.impl.AbstractLoggingMechanism
OPEN_DATE_FORMAT
 
Constructor Summary
AbstractFileLoggingMechanism()
           
 
Method Summary
protected  void close()
          Closes a file log
 List getActiveEntities()
          Returns a list of all active (in use) log entities that are available by the file logging mechanisms controlled by this logger
protected  String getFileNameSuffixModifier(Log log)
          Returns the file name suffix modifier.
protected  PrintWriter getPrintWriter()
          Returns the PrintWriter the mechanism writes to.
 List getReadableEntities()
          Returns a list of all readable log entities that are available by the file logging mechanisms controlled by this logger
 LogEntityReader getReader(LogEntity entity)
          Returns an entity reader for given log entity
 List getRemoveableEntities()
          Returns a list of all removeable log entities that are available by the file logging mechanisms controlled by this logger
protected  boolean hasDateRolledOver()
          Checks the current date verses the date the log was opened.
protected abstract  boolean isDatedLog()
          Mechanisms can be dated or non-dated.
protected  void logEvent(Log log, LogEvent event)
          Logs an event on the mechanism.
protected  void open(Log log)
          Opens a file log.
 void removeEntity(LogEntity entity)
          Remove a log entity
protected  void rollLogOver(Log log, String reason)
          Rolls a log over, typically on a date change, by closing the log and reopening it.
 String toString()
          Return a nice debug string.
 
Methods inherited from class org.openmdx.kernel.log.impl.AbstractLoggingMechanism
acceptsNotificationLogs, acceptsPerformanceLogs, acceptsStandardLogs, acceptsStatisticLogs, createFormatter, createNotificationEvent, getDateOpend, getFormatter, getLoggers, getName, isOpen, isSharedLog, notifyLogClosed, notifyLoggingLevelChange, notifyLoggingPerformanceChange, notifyLoggingStatisticsChange, notifyLogOpened, setFormatter, setNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractFileLoggingMechanism

public AbstractFileLoggingMechanism()
Method Detail

open

protected void open(Log log)
Opens a file log.

Overrides:
open in class AbstractLoggingMechanism
Parameters:
log - A logger that opens the mechanism

close

protected void close()
Closes a file log

Overrides:
close in class AbstractLoggingMechanism

toString

public String toString()
Return a nice debug string.

Overrides:
toString in class AbstractLoggingMechanism
Returns:
A mechanism description

isDatedLog

protected abstract boolean isDatedLog()
Mechanisms can be dated or non-dated. If dated, the log needs to have a date appended to a file name (if it has one) and it must be rolled over to a new one when the current date changes. The default setting is non-dated, this method must be overridden when dated.


logEvent

protected void logEvent(Log log,
                        LogEvent event)
Logs an event on the mechanism.

Specified by:
logEvent in class AbstractLoggingMechanism
Parameters:
log - the logger this mechanism belongs to
event - a log event

getPrintWriter

protected PrintWriter getPrintWriter()
Returns the PrintWriter the mechanism writes to.

Returns:
a PrintWriter

getActiveEntities

public List getActiveEntities()
Returns a list of all active (in use) log entities that are available by the file logging mechanisms controlled by this logger

Specified by:
getActiveEntities in interface ManageableMechanism
Overrides:
getActiveEntities in class AbstractLoggingMechanism
Returns:
a list of LogEntity objects

getReadableEntities

public List getReadableEntities()
Returns a list of all readable log entities that are available by the file logging mechanisms controlled by this logger

Specified by:
getReadableEntities in interface ManageableMechanism
Overrides:
getReadableEntities in class AbstractLoggingMechanism
Returns:
a list of log entity names

getRemoveableEntities

public List getRemoveableEntities()
Returns a list of all removeable log entities that are available by the file logging mechanisms controlled by this logger

Specified by:
getRemoveableEntities in interface ManageableMechanism
Overrides:
getRemoveableEntities in class AbstractLoggingMechanism
Returns:
a list of log entitiy names

removeEntity

public void removeEntity(LogEntity entity)
Remove a log entity

Specified by:
removeEntity in interface ManageableMechanism
Overrides:
removeEntity in class AbstractLoggingMechanism
Parameters:
String - an entity name

getReader

public LogEntityReader getReader(LogEntity entity)
Returns an entity reader for given log entity

Specified by:
getReader in interface ManageableMechanism
Overrides:
getReader in class AbstractLoggingMechanism
Parameters:
String - an entity name

rollLogOver

protected void rollLogOver(Log log,
                           String reason)
Rolls a log over, typically on a date change, by closing the log and reopening it.

NOTE: Do not call any method that itself calls logEvent() to prevent any loop. E.g. any notification calls do that!

Parameters:
log - The logger under which an event caused a rollover
reason - A rollover reason

hasDateRolledOver

protected boolean hasDateRolledOver()
Checks the current date verses the date the log was opened. If the current date is one or more days greater (that is, have we passed midnight), return true. Else, return false. To make this method reasonably fast, it does not compare years, only days within a year.


getFileNameSuffixModifier

protected String getFileNameSuffixModifier(Log log)
Returns the file name suffix modifier. This is the only part of the log file name a logging mechanism can modify.

Parameters:
log - a log
Returns:
a string


This software is published under the BSD license. Copyright © 2003-2007, OMEX AG, Switzerland, All rights reserved. Use is subject to license terms.