org.locomotive.server
Class Log

java.lang.Object
  |
  +--org.locomotive.server.Log

public class Log
extends java.lang.Object
implements LocomotiveService

A simple logging facility. Data can be logged to a file, along with a simple datestamp (datestamp can be turned off if desired), similiar in form to the UNIX syslog facility.

At midnight, the previous days logfile will be closed, and a new one will be opened. A percent symbol should be placed into the log_path to allow the server to correctly open the new file. An example log_path is the string "logs/loco1-%.log". The standard log of the Loco is of this type, as is the Loco EventLog.

See Also:
Loco

Field Summary
static int CRITICAL_ERROR
          Critical Error- Handler severely disabled.
static int DEBUG
          Debug information.
static int DEBUG_REALLY_VERBOSE
          All debug information, including internal Locomotive state logging.
static int DEBUG_VERBOSE
          More Debug information, including the CGI environment for each request.
static int ERROR
          Error.
static int FATAL_ERROR
          Fatal error- Handler cannot continue.
static int INFO
          Useful information.
static int NO_LOGGING
          If you don't want to do any logging at all, set the logging level of the Log instance to this value.
static int NOTICE
          Important information, including the URL tokens for each request.
static int WARNING
          Potential Problem.
 
Constructor Summary
Log()
          Default constructor for the Log class.
Log(int lev, java.lang.String root, java.lang.String log_path)
          Create a new Log.
 
Method Summary
 void closeLog()
          Closes this Log.
 java.lang.String getLogPath()
          Get relative path to the log file.
 java.lang.String getRootPath()
          Get the root path.
 boolean isRunning()
          Check if the service is running.
 void log(int lev, java.lang.String s)
          logs an line to the logfile, containing the string s.
 void setLevel(int newlev)
          Adjusts the logging level to the specified level.
 void setLogPath(java.lang.String logPath)
          Relative path name to the log file.
 void setPrependDate(boolean prepend)
          Call this method with a prepend value of false to turn off the automatic prepending of the date on each log output line.
 void setRootPath(java.lang.String rootPath)
          Set the root path of that the log file will be written relative to.
 void startService()
          Start the log service.
 void stopService()
          Stop the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_LOGGING

public static final int NO_LOGGING
If you don't want to do any logging at all, set the logging level of the Log instance to this value. Equivalent to 0.

FATAL_ERROR

public static final int FATAL_ERROR
Fatal error- Handler cannot continue. Equivalent to 1.

CRITICAL_ERROR

public static final int CRITICAL_ERROR
Critical Error- Handler severely disabled. Equivalent to 2.

ERROR

public static final int ERROR
Error. equivalent to 3.

WARNING

public static final int WARNING
Potential Problem. Equivalent to 4.

NOTICE

public static final int NOTICE
Important information, including the URL tokens for each request. Equivalent to 5.

INFO

public static final int INFO
Useful information. Equivalent to 6.

DEBUG

public static final int DEBUG
Debug information. Useful for development. Equivalent to 7.

DEBUG_VERBOSE

public static final int DEBUG_VERBOSE
More Debug information, including the CGI environment for each request. Equivalent to 8.

DEBUG_REALLY_VERBOSE

public static final int DEBUG_REALLY_VERBOSE
All debug information, including internal Locomotive state logging. Equivalent to 9.
Constructor Detail

Log

public Log(int lev,
           java.lang.String root,
           java.lang.String log_path)
    throws java.io.IOException
Create a new Log.
Parameters:
lev - the logging level for this log
root - the path to the server root.
log_path - the log path, relative to the server root. If this string contains a '%' (percent), the current date will be substituted into the filename at that location in the path.

Log

public Log()
Default constructor for the Log class.
Method Detail

startService

public void startService()
                  throws ServiceException
Start the log service.
Specified by:
startService in interface LocomotiveService
Throws:
ServiceException - is thrown if the log service not could be started.

stopService

public void stopService()
                 throws ServiceException
Stop the service.
Specified by:
stopService in interface LocomotiveService
Throws:
ServiceException - is throws if this service not could be stopped.

isRunning

public boolean isRunning()
Check if the service is running.
Specified by:
isRunning in interface LocomotiveService
Returns:
false if the service not is running, true otherwise.

setLevel

public void setLevel(int newlev)
Adjusts the logging level to the specified level. Calls to log () with a level higher than that level previously set with a setLevel() call or the constructor will be ignored. Example: if your current logging level in the Log object is ERROR, calls with logging level DEBUG will be ignored, but with level CRITICAL_ERROR it will be written to the logfile.

Parameters:
newlev - the new logging level.

log

public void log(int lev,
                java.lang.String s)
logs an line to the logfile, containing the string s. If the lev parameter is greater than the current log level, the call will simply return, without writing.
Parameters:
lev - the level of this log request. If higher than the current logging level, this request will be ignored
s - the string to be written to the log

closeLog

public void closeLog()
Closes this Log. Any subsequent writes to this Log are simply ignored.

setRootPath

public void setRootPath(java.lang.String rootPath)
Set the root path of that the log file will be written relative to. Normally this is the server install directory.
Parameters:
rootPath - Root path for the log.

getRootPath

public java.lang.String getRootPath()
Get the root path.
Returns:
Returns the root path.

setLogPath

public void setLogPath(java.lang.String logPath)
Relative path name to the log file.
Parameters:
logPath - Relative pathname of the log.If this string contains a '%' (percent), the current date will be substituted into the filename at that location in the path.

getLogPath

public java.lang.String getLogPath()
Get relative path to the log file.
Returns:
Returns the relative path to the log file.

setPrependDate

public void setPrependDate(boolean prepend)
Call this method with a prepend value of false to turn off the automatic prepending of the date on each log output line.

Parameters:
prepend - make this true if you want the Log object to prepend the date to the beginning of your log output lines, or false to turn off the datestamping.