anthill.util
Class Log

java.lang.Object
  |
  +--anthill.util.Log

public class Log
extends Object

This class contains a set of static methods for the management of log files. The log information can be printed on both the standard output and a log file, whose name is generated using the name of the host in which the log class is running and the current time. Different log level may be associated to both the standard output and the log file, in order to obtain different set of information.

Author:
Alberto Montresor

Field Summary
static boolean DEBUG
          True if the log function is active.
 
Constructor Summary
Log()
           
 
Method Summary
static void flush()
           
static void print(int level, Object obj)
          If the log is not active, print an exception on the standard output.
static void print(Object obj)
          Prints the specified information on the standard output.
static void printFile(int level, Object object)
          If the log is not active, print an exception on the standard output.
static void printFile(Object object)
          Prints the specified information on the standard output.
static void println(int level, Object obj)
          If the log is not active, print an exception on the standard output.
static void println(Object obj)
          Prints the specified information on the standard output and terminates the line.
static void printlnFile(int level, Object object)
          If the log is not active, print an exception on the standard output.
static void printlnFile(Object object)
          Prints the specified information on the standard output and terminates the line.
static void printStackTrace(Exception e)
          Print the stack trace of the specified exception on the standard output; if the log function is active, print the stack trace on the log file as well.
static void printStackTrace(int level, Exception e)
          If the log is not active, prints an exception on the standard output.
static void setFileLevel(int level)
          Set the file debug level to level.
static void setOutLevel(int level)
          Set the console log level to level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
True if the log function is active. Putting this variable to false and using an optimizing compiler such as Jikes guarantee that all log code will be removed from the generated bytecode; this to avoid overhead in the execution when log is not needed.

See Also:
Constant Field Values
Constructor Detail

Log

public Log()
Method Detail

setFileLevel

public static void setFileLevel(int level)
Set the file debug level to level.

Parameters:
level - the new logging level.

setOutLevel

public static void setOutLevel(int level)
Set the console log level to level.

Parameters:
level - the new logging level.

printFile

public static void printFile(Object object)
Prints the specified information on the standard output. If the log is active, prints also the information on the log file.


print

public static void print(Object obj)
Prints the specified information on the standard output. If the log is active, prints also the information on the log file.

Parameters:
obj - the object to be printed.

printlnFile

public static void printlnFile(Object object)
Prints the specified information on the standard output and terminates the line. If the log is active, prints also the information on the log file and terminates the line.


println

public static void println(Object obj)
Prints the specified information on the standard output and terminates the line. If the log is active, prints also the information on the log file and terminates the line.

Parameters:
obj - the object to be printed.

printFile

public static void printFile(int level,
                             Object object)
If the log is not active, print an exception on the standard output. If the log is active, prints the specified information on the log file; if level is greater or equal than the current log level, prints the specified information on the standard output as well.

Parameters:
level - the log level of this information

print

public static void print(int level,
                         Object obj)
If the log is not active, print an exception on the standard output. If the log is active, prints the specified information on the log file; if level is greater or equal than the current log level, prints the specified information on the standard output as well.

Parameters:
level - the log level of this information
obj - the object to be printed.

printlnFile

public static void printlnFile(int level,
                               Object object)
If the log is not active, print an exception on the standard output. If the log is active, prints the specified information on the log file and terminates the line; if level is greater or equal than the current log level, prints the specified information on the standard output as well and terminates the line.

Parameters:
level - the log level of this information

println

public static void println(int level,
                           Object obj)
If the log is not active, print an exception on the standard output. If the log is active, prints the specified information on the log file and terminates the line; if level is greater or equal than the current log level, prints the specified information on the standard output as well and terminates the line.

Parameters:
level - the log level of this information
obj - the object to be printed.

printStackTrace

public static void printStackTrace(Exception e)
Print the stack trace of the specified exception on the standard output; if the log function is active, print the stack trace on the log file as well.

Parameters:
e - the exception to be printed.

flush

public static void flush()

printStackTrace

public static void printStackTrace(int level,
                                   Exception e)
If the log is not active, prints an exception on the standard output. If the log is active, prints the stack trace of the specified exception on the log file; if level is greater or equal than the current log level, prints the specified the stack trace on the standard output as well.

Parameters:
e - the exception to be printed.