Luky Library - 4.1.1 (20061117-1148)

luky.util
Class Log

java.lang.Object
  extended by luky.util.Log

public class Log
extends Object

The Log class has been created to facilitate in a standard interface to output logging information to a device. The main advantage is that the program using the logging class encapsulates no knownledge on the level to which logging is required and to which output this logging should be directed.
Currently 6 levels of logging are defined:

And 4 different ways of output logging exist:
There is also a fallback parameter implemented. This parameter indicates fallback if the logging tool should try to fall back incase of an output error. For example when logging to disc is activated with fallback and the disc runs out of space, screen logging will be activated to report that the disc write has failed and the logging will continue to the screen. Fallback will only activate when loggings would be lost. If for example one logs to disc and the database, then fallback would not be activated.
Two different forms of output exist:
Use timed logging to get a timestamped message with a module headername, use clean to get the plain message.

usage :
Revision Changes :

Version:
2.07
Author:
Chris Lukassen
 

Field Summary
static int CLEAN
          constant representing CLEAN printing of the log
static int DATABASE
          constant representing DATABASE logging
static int DEBUG
          constant representing logging level 5
static int DETAIL
          constant representing logging level 4
static int FATAL
          constant representing logging level 1
static int FILE
          constant representing FILE logging
static int MAIL
          constant representing MAIL logging
static int MESSAGE
          constant representing logging level 3
static int NONE
          constant representing logging level 0
static int SCREEN
          constant representing SCREEN logging
static int STACK
          constant representing logging level 6
static int TIMED
          constant representing TIMED printing of the log
static int WARNING
          constant representing logging level 2
 
Constructor Summary
Log()
          default constructor
 
Method Summary
static int close()
          close stops the logging, closes the logfiles if needed
protected  void finalize()
          close stops the logging, closes the logfiles if needed
static String getFile()
          returns the file to which the logging is taking place
static String getFormat()
          returns the logging format
static String getLogLevel()
          returns the level of the logging
static int getLogLevelValue()
          returns the level of the logging
static String getModuleName()
          returns the name of module which is logging
static boolean getOutput(int type)
          returns the status of the output devices
static int init()
          Initializes the logging module, not required but handy.
static int print(int printLevel, String msg)
          print, prints the message string to the installed output.
static String removeQuotes(String msg)
          takes a string and removes the quotes so "she said "hello"" becomes:
"she said hello"
static int setDatabase(String url, String driver, String user, String password)
          specifies the database parameters, it will try to connect to the database and fallback if needed.
static int setFile(String file, boolean append)
          specifies the the logfile and if the tool should try to append to the file or reopen it.
static int setFile(String file, boolean append, String backupFile, long maxSize)
          specifies the the logfile and if the tool should try to append to the file or reopen it and the backup file with roll over size
static int setFormat(int type)
          specifies the format used to log messages
static void setLogFallBack(boolean enable)
          specifies whether there is log fallback enabled (default off)
static int setLogLevel(int newLevel)
          specifies the log level (0..6) for the logging.
static int setMail(String toAddress, int newMailLevel)
          specifies the the log level (0..6) for the mail logging, and the address to which the mail should be sent.
static int setModuleName(String moduleName)
          specifies the name used with each log print
static int setOutput(int type, boolean status)
          sets the output on or of
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE

public static final int FILE
constant representing FILE logging

See Also:
Constant Field Values

SCREEN

public static final int SCREEN
constant representing SCREEN logging

See Also:
Constant Field Values

DATABASE

public static final int DATABASE
constant representing DATABASE logging

See Also:
Constant Field Values

MAIL

public static final int MAIL
constant representing MAIL logging

See Also:
Constant Field Values

NONE

public static final int NONE
constant representing logging level 0

See Also:
Constant Field Values

FATAL

public static final int FATAL
constant representing logging level 1

See Also:
Constant Field Values

WARNING

public static final int WARNING
constant representing logging level 2

See Also:
Constant Field Values

MESSAGE

public static final int MESSAGE
constant representing logging level 3

See Also:
Constant Field Values

DETAIL

public static final int DETAIL
constant representing logging level 4

See Also:
Constant Field Values

DEBUG

public static final int DEBUG
constant representing logging level 5

See Also:
Constant Field Values

STACK

public static final int STACK
constant representing logging level 6

See Also:
Constant Field Values

CLEAN

public static final int CLEAN
constant representing CLEAN printing of the log

See Also:
Constant Field Values

TIMED

public static final int TIMED
constant representing TIMED printing of the log

See Also:
Constant Field Values
Constructor Detail

Log

public Log()
default constructor

Method Detail

finalize

protected void finalize()
close stops the logging, closes the logfiles if needed

Overrides:
finalize in class Object

close

public static int close()
close stops the logging, closes the logfiles if needed

Returns:
Constants.OK or Constants.NOK

init

public static int init()
Initializes the logging module, not required but handy. (it should be called automatically upon the first method invocation.)

Returns:
Constants.OK or Constants.NOK

setLogFallBack

public static void setLogFallBack(boolean enable)
specifies whether there is log fallback enabled (default off)

Parameters:
enable - true or false

setLogLevel

public static int setLogLevel(int newLevel)
specifies the log level (0..6) for the logging.

Parameters:
newLevel - values are FATAL, WARNING, MESSAGE, DETAIL, DEBUG or STACK
Returns:
Constants.OK or Constants.NOK

getLogLevelValue

public static int getLogLevelValue()
returns the level of the logging

Returns:
a int corresponding to Log.NONE Log.FATAL, Log.WARNING, Log.MESSAGE, Log.DETAIL, Log.DEBUG, or Log.STACK

getLogLevel

public static String getLogLevel()
returns the level of the logging

Returns:
a string "NONE", "FATAL", "WARNING", "MESSAGE", "DETAIL", "DEBUG", or "STACK"

setOutput

public static int setOutput(int type,
                            boolean status)
sets the output on or of

Parameters:
type - constant specifying the LogType, values are FILE, SCREEN, DATABASE or MAIL
status - TRUE or FALSE
Returns:
returns Constants.OK or Constants.NOK

getOutput

public static boolean getOutput(int type)
returns the status of the output devices

Parameters:
type - constant specifying the LogType, values are FILE, SCREEN, DATABASE or MAIL
Returns:
returns TRUE or FALSE

setFormat

public static int setFormat(int type)
specifies the format used to log messages

Parameters:
type - TIMED or CLEAN
Returns:
Constants.OK or Constants.NOK

getFormat

public static String getFormat()
returns the logging format

Returns:
a string "TIMED" or "CLEAN"

setModuleName

public static int setModuleName(String moduleName)
specifies the name used with each log print

Parameters:
moduleName - string specifying the name for the logging
Returns:
Constants.OK or Constants.NOK

setDatabase

public static int setDatabase(String url,
                              String driver,
                              String user,
                              String password)
specifies the database parameters, it will try to connect to the database and fallback if needed.

Parameters:
url - the jdbc url that specifies the database
driver - the driver that is required. It must be on the classpath too
user - the username for the database
password - the password for the database user
Returns:
Constants.OK or Constants.NOK

setMail

public static int setMail(String toAddress,
                          int newMailLevel)
specifies the the log level (0..6) for the mail logging, and the address to which the mail should be sent. The mail logging has not been activated after calling this function, use setOutput for that

Parameters:
toAddress - the mail address to be used
newMailLevel - values are FATAL, WARNING, MESSAGE, DETAIL, DEBUG or STACK
Returns:
Constants.OK or Constants.NOK

setFile

public static int setFile(String file,
                          boolean append,
                          String backupFile,
                          long maxSize)
specifies the the logfile and if the tool should try to append to the file or reopen it and the backup file with roll over size

Parameters:
file - the name used for the file
backupFile - the name used for the backup file
maxSize - the maximum size of the file
append - true or false
Returns:
Constants.OK or Constants.NOK

setFile

public static int setFile(String file,
                          boolean append)
specifies the the logfile and if the tool should try to append to the file or reopen it.

Parameters:
file - the name used for the file
append - true or false
Returns:
Constants.OK or Constants.NOK

getFile

public static String getFile()
returns the file to which the logging is taking place

Returns:
filename

getModuleName

public static String getModuleName()
returns the name of module which is logging

Returns:
module name

removeQuotes

public static String removeQuotes(String msg)
takes a string and removes the quotes so "she said "hello"" becomes:
"she said hello"

Parameters:
msg - the string that must be outputted
Returns:
msg without quotes

print

public static int print(int printLevel,
                        String msg)
print, prints the message string to the installed output. The format is conform the installed type the level must be lower or equal the installed log level

Parameters:
printLevel - specifies the level for this print, legal values are FATAL, WARNING, MESSAGE, DETAIL, DEBUG or STACK
msg - the string that must be outputted
Returns:
Constants.OK or Constants.NOK

Luky Library - 4.1.1 (20061117-1148)