FileLogger

public class FileLogger extends Component implements Logger

The file logger is a simple logger that log everything to the desired file. Dependency : Piazza Common The sample usage is shown on the below:

 FileLogger log = new FileLogger("../logs/testlog.txt");
log.debug("Test debug statement");
log.error("Test error statement");
log.fatal("Test fatal statement");
log.info ("Test info  statement");
log.warn ("Test warn  statement");

The output in the file logger should be liked these:

[Debug] Test debug statement
[Error] Test error statement
[Fatal] Test fatal statement
[Info]  Test info statement
[Warn]  Test warn statement

SPA Component Guideline:.

Author:Twinsen Tsang

Constructors

FileLogger

public FileLogger(String filepath)

Constructor.

Parameters:
  • filepath – The filepath for logging.
Throws:
  • UtiltiesException – Throw if any IO Operations fail like can not open file or print stream.

FileLogger

public FileLogger(File f)

Constructor. The file logger open a file output stream for writing the log to the file. It use the default log file name “log.txt” for logging if the file object is a directory.

Parameters:
  • f – The file object specified.
Throws:
  • UtilitiesException – Throw if any IO Operations fail like can not open file or print stream.

Methods

debug

public void debug(Object msg)

Override debug print method.

Parameters:
  • msg – debugging object to be printed.

debug

public void debug(Object msg, Throwable t)

Override debug with exception print method.

Parameters:
  • msg – debugging object to be printed.

error

public void error(Object msg)

Override error print method.

Parameters:
  • msg – errorging object to be printed.

error

public void error(Object msg, Throwable t)

Override error with exception print method.

Parameters:
  • msg – errorging object to be printed.

fatal

public void fatal(Object msg)

Override fatal print method.

Parameters:
  • msg – fatalging object to be printed.

fatal

public void fatal(Object msg, Throwable t)

Override fatal with exception print method.

Parameters:
  • msg – fatalging object to be printed.

finalize

protected void finalize()

The method finalized the class.

info

public void info(Object msg)

Override info print method.

Parameters:
  • msg – infoging object to be printed.

info

public void info(Object msg, Throwable t)

Override info with exception print method.

Parameters:
  • msg – infoging object to be printed.

init

protected void init()

Override initialization method. It invokes when the logger is acted as Module Component.

log

public void log(String s)

Log a string to the file by the print stream.

Parameters:
  • s – The string to be logged.

logStackTrace

public void logStackTrace(Throwable e)

Log a exception / throwable to the file by the print stream. The exception element will begin with the tag [Stack Trace] other than debug, error, fatal, warn, info.

Parameters:
  • e – The throwable e to be logged.

toString

public String toString()

toString method().

warn

public void warn(Object msg)

Override warn print method.

Parameters:
  • msg – warnging object to be printed.

warn

public void warn(Object msg, Throwable t)

Override warn with exception print method.

Parameters:
  • msg – warnging object to be printed.