com.senn.magic.logging
Class SimpleLogger

java.lang.Object
  extended by com.senn.magic.logging.SimpleLogger

public class SimpleLogger
extends Object

This class contains a small and easy to use logger. This logger is not threadsafe so it should only be used in straightforward singlethreaded applications!

Since:
1.1
Author:
Bart Thierens
Last modification: 03/03/2010

Field Summary
static String DATE_NOW_DETAILED
          Date pattern: yyyy-MM-dd HH:mm:ss
static String DATE_NOW_SHORT
          Date pattern: yyyyMMdd
protected  String location
           
protected  Class logClass
           
protected  File logFile
           
protected  String name
           
 
Constructor Summary
SimpleLogger()
          Constructs an instance of SimpleLogger with default settings

SimpleLogger(Class logClass)
          Constructs an instance of SimpleLogger

SimpleLogger(String location)
          Constructs an instance of SimpleLogger

SimpleLogger(String name, Class logClass, String location)
          Constructs an instance of SimpleLogger

 
Method Summary
protected  void createLogFile()
          Protected method that creates the logfile.
protected  void doLog(String message, String type)
          Protected method that does the actual logging.
 void error(String errorMessage)
          Logs an error message to the logfile (provided in Constructor)
protected static String generateDate(String dateFormat)
          Protected method that generates the current date in the format you supply
 String getLocation()
          Gets the location of the logfile
 Class getLogClass()
          Gets the class in which the logging occurs
 File getLogFile()
          Gets the file associated with the logfile
 String getName()
          Gets the name of the logfile
 void log(String message)
          Logs a message to the logfile (provided in Constructor)
protected static String now()
          Protected method that generates the current time in a yyyy-MM-dd HH:mm:ss format.
protected  void setLocation(String location)
          Sets the location of the logfile
protected  void setLogClass(Class logClass)
          Sets the class in which the logging occurs
protected  void setName(String name)
          Sets the name of the logfile
protected static String today()
          Protected method that generates the current time in a yyyyMMdd format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATE_NOW_DETAILED

public static final String DATE_NOW_DETAILED
Date pattern: yyyy-MM-dd HH:mm:ss

See Also:
Constant Field Values

DATE_NOW_SHORT

public static final String DATE_NOW_SHORT
Date pattern: yyyyMMdd

See Also:
Constant Field Values

location

protected String location

logClass

protected Class logClass

name

protected String name

logFile

protected File logFile
Constructor Detail

SimpleLogger

public SimpleLogger(String name,
                    Class logClass,
                    String location)
Constructs an instance of SimpleLogger

Parameters:
name - name of the logfile (the logfile will be named name_yyyyMMdd.log)
logClass - the class in which the logging occurs - can be left null
location - location where the logfile should be placed - if left null it will be placed in the classpath
must be a valid existing path (ie. C:/logs)

SimpleLogger

public SimpleLogger(Class logClass)
Constructs an instance of SimpleLogger

Parameters:
logClass - the class in which the logging occurs - can be left null

SimpleLogger

public SimpleLogger(String location)
Constructs an instance of SimpleLogger

Parameters:
location - location where the logfile should be placed - if left null it will be placed in the classpath
must be a valid existing path (ie. C:/logs)

SimpleLogger

public SimpleLogger()
Constructs an instance of SimpleLogger with default settings

Method Detail

log

public void log(String message)
Logs a message to the logfile (provided in Constructor)

Parameters:
message - message to be logged

error

public void error(String errorMessage)
Logs an error message to the logfile (provided in Constructor)

Parameters:
errorMessage - error message to be logged

doLog

protected void doLog(String message,
                     String type)
Protected method that does the actual logging.
Override this method if you want to change the way something is logged.

Parameters:
message - the message you want to log
type - the type of logging - you see this in between brackets: [ERROR], [DEBUG], [WARN], [INFO], ...

now

protected static String now()
Protected method that generates the current time in a yyyy-MM-dd HH:mm:ss format.

It's exactly the same as:
generateDate(SimpleLogger.DATE_NOW_DETAILED);

Returns:
String - the current time in a yyyyMMdd format

today

protected static String today()
Protected method that generates the current time in a yyyyMMdd format.

It's exactly the same as:
generateDate(SimpleLogger.DATE_NOW_SHORT);

Returns:
String - the current time in a yyyyMMdd format

generateDate

protected static String generateDate(String dateFormat)
Protected method that generates the current date in the format you supply

Parameters:
dateFormat - the date format
Returns:
String - the current date in the provided format

createLogFile

protected void createLogFile()
Protected method that creates the logfile. For internal use.


getLocation

public String getLocation()
Gets the location of the logfile

Returns:
String - the location of the logfile

setLocation

protected void setLocation(String location)
Sets the location of the logfile

Parameters:
location - the location of the logfile (exclude the logfile's name)

getLogClass

public Class getLogClass()
Gets the class in which the logging occurs

Returns:
Class - the class which does the logging

setLogClass

protected void setLogClass(Class logClass)
Sets the class in which the logging occurs

Parameters:
logClass - the class that will do the logging

getName

public String getName()
Gets the name of the logfile

Returns:
String - the name of the logfile

setName

protected void setName(String name)
Sets the name of the logfile

Parameters:
name - the name of the logfile

getLogFile

public File getLogFile()
Gets the file associated with the logfile

Returns:
File - the logfile as a File object