no.ubicollab.osgi
Class Log

java.lang.Object
  extended by no.ubicollab.osgi.Log

public class Log
extends java.lang.Object

This Class is responsible for the logging of events, and for reading and returning the log on request. The log file will be created in the folder specified in GlobalSettings.STORAGE_ROOT on the system drive.

This class is created as a singleton class to enable logging from everywhere without having to pass around a instance refrence. An instance might not be needed at all.

Since:
0.1
Version:
0.5
Author:
Kim-Steve Johansen

Field Summary
static int DEBUG
          The Constant DEBUG describes a given log-level.
static int ERROR
          The Constant ERROR describes a given log-level.
static int FATAL
          The Constant FATAL describes a given log-level.
static int INFO
          The Constant INFO describes a given log-level.
static int WARNING
          The Constant WARNING describes a given log-level.
 
Method Summary
static Log getInstance()
          Method to get a refrence to the instance.
 java.lang.String readFromLog(int logLevel, int numItems)
          Read from the log and return selected log items in a XML-formatted string.
 void writeToLog(java.lang.String message, int level)
          Method to write a new record (og item) in the log.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final int DEBUG
The Constant DEBUG describes a given log-level.

See Also:
Constant Field Values

INFO

public static final int INFO
The Constant INFO describes a given log-level.

See Also:
Constant Field Values

WARNING

public static final int WARNING
The Constant WARNING describes a given log-level.

See Also:
Constant Field Values

ERROR

public static final int ERROR
The Constant ERROR describes a given log-level.

See Also:
Constant Field Values

FATAL

public static final int FATAL
The Constant FATAL describes a given log-level.

See Also:
Constant Field Values
Method Detail

getInstance

public static Log getInstance()
Method to get a refrence to the instance.

Returns:
the instance

writeToLog

public void writeToLog(java.lang.String message,
                       int level)
Method to write a new record (og item) in the log. If the log file is unreachable, the message will be written to standard output.

Parameters:
level - The log-level for the message.
message - The Stringg to write to the log

readFromLog

public java.lang.String readFromLog(int logLevel,
                                    int numItems)
Read from the log and return selected log items in a XML-formatted string.

The xml-structure used to represent the returned log is:

   <?xml version='1.0'?>
      <Log>
          <Logitem Date="dd.mm.yyyy" 
            Time="hh:mm:ss" 
            Level="String" 
            Message="String"/>
... more log items ...
</Log>

Parameters:
logLevel - The log level to include in the report. Valid arguments are: 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'FATAL' and 'ALL' for all types.
numItems - The number of log items to include in the report
Returns:
the String containg the resulting XML