EQUIP2 Logging
Chris Greenhalgh, 2006-04-27
Contents:
Introduction
One of the potential benefits of using the EQUIP2 approach is that the
dataspace(s) provide a standard point for logging much of the internal
activity of an application, and the standard state/event model allows
the historical state(s) and evolution of a dataspace to be recreated
from a log of actions on the dataspace. This document describes
EQUIP2's current support for logging and the log files produced.
Logging internal API
All of the current dataspace implementation extends equip2.core.impl.DefaultDataspace,
which in turn supports the following constructor option and method:
package equip2.core.impl;
import equip2.core.impl.IDataspaceLogger;
public class DefaultDataspace {
protected DefaultDataspace(IDataspaceLogger dataspaceLogger);
public void setLogger(IDataspaceLogger dataspaceLogger);
}
Either of these can be used to attach a dataspace logger to that
dataspace, to log or otherwise record potentially all changes made to
that dataspace.
The equip2.core.impl.IDataspaceLogger
internal interface (to be implemented by a logger) is as follows:
package equip2.core.impl;
public interface IDataspaceLogger {
public void logBegin(IDataspace dataspace);
public void logChange(IDataspace dataspace, SessionManagedObject changedObjects[]);
public void logEnd(IDataspace dataspace);
}
Note that logEnd will
not be called unless the dataspace shuts down in a well-defined manner
(none of them do at present!), or the logger is replaced or reset (e.g.
a call to the dataspace setLogger(null)).
Consequently, many log files may not be cleanly terminated.
Logging a dataspace
There is currently a common abstract implementation of the dataspace
logger API, equip2.core.logging.AbstractDataspaceLogger,
which can be extended to support different log output methods. The
implement(s) are currently:
To log a dataspace, a dataspace logger object is created and
initialised, and then passed to the dataspace to be logged, either via
its constructor (not support on all dataspace implementations) or using
the setLogger method
(see API section, above).
The test equip2.core.logging.test.j2se.SimpleFileDataspaceLoggerTest
gives an example of logging a dataspace.
Log file format
The default log file format (e.g. as supported by equip2.core.logging.AbstractDataspaceLogger)
uses autogenerated java beans to represent the log file contents:
- equip2.core.logging.LogHeader
to represent the header (generated by logBegin), having properties:
- startTime - long -
start of log, as per java.lang.System.currentTimeMillis (milliseconds
since 1st Jan 1970)
- metadata -
java.util.Hashtable - of name-value metadata pairs (optional);
suggested key/values include:
- hostname - name
of machine dataspace is running on
- ipaddress - IP
address of machine dataspace is running on
- application -
name of application hosting dataspace
- checkpoint -
java.lang.Object[] - array of values in the dataspace when log starts
(optional)
- equip2.core.logging.LogEntry
to represent each dataspace change (generated by each
SessionManagedObject (other than READ) in the array passed to logChange), having properties:
- time - long - of
event (logging), as above
- oldValue -
java.lang.Object - old value, if any (i.e. for delete or modify)
- newValue -
java.lang.Object - new value, if any (i.e. for add or modify)
- metadata -
java.util.Hashtable - optional
- equip2.core.logging.LogTrailer
to represent the trailer of the log (if present) (generated by logEnd), having properties:
- time - long - of
event (logging), as above
- metadata -
java.util.Hashtable - optional
A log file should always start with a single LogHeader object,
followed by any number of LogEntry objects, followed by a single
LogTrailer object (although, as noted above, the LogTrailer and file
ending may often be missing).
An actual file is generated or read using the standard EQUIP2 object
marshalling framework. Currently this supports:
- Hessian binary
serialisation. A log file in this format is just a Hessian byte
sequence resulting from directly marshalling the above sequence of
objects. The preferred file extension in this case is .hessian.
- EQUIP2's own XML serialisation.
A log file in this format has an XML file header (<?xml version="1.0"?>)
and a single document element <equip2log>,
the body of which is the sequence of marshall Log objects, as described
above.
Logging tools
The following tool(s) exist to support working with log files and/or
provide code samples for future tool development:
Note that the log file reader(s) can use custom object helper
registry(s) to allow them to read classes (or versions of classes)
which they do not actually have class files for. E.g. the registry equip2.core.logging.j2se.HashtableFallbackObjectHelperRegistry
will use the generic Hashtable object helper to handle any unknown (not
found) class.
Change log
2006-04-27