com.ls.service.log.log4j
Class Logger4j

java.lang.Object
  |
  +--com.ls.service.log.log4j.Logger4j
All Implemented Interfaces:
ILogger, Serializable

public class Logger4j
extends Object
implements Serializable, ILogger

This class is responsible for the logging of activities of agents and generates log entries. This class uses Log4J (http://jakarta.apache.org/log4j).

Version:
$Revision: 1.14 $
Author:
Last modified by $Author: TBerk $
See Also:
Serialized Form

Fields inherited from interface com.ls.service.log.ILogger
ERROR, INFO, LEVEL_INDEPENDENT, LOG_LEVEL, MAX_LOG_LEVEL, TAG_GLOBAL_LOG_PATH, TAG_LOG_FILE, TAG_LOG_LEVEL, TAG_LOG_TYPE, TRACE, TRACE1, TRACE2, TRACE3, TRACE4, TRACE5, WARNING
 
Constructor Summary
Logger4j()
          Empty constructor.
Logger4j(String logFileName, int logLevel, Map map)
          Constructor that includes trying to open the file where the log messages get stored and setting the log level.
Logger4j(String logFileName, Map map)
          Constructor that includes trying to open the file where the log messages get stored.
 
Method Summary
 boolean canLog(int logLevel)
          determines, if a notice with the given log level will be logged
 void closeLogFile()
          closes the logfile
protected  void finalize()
          closes the log file if this object gets deleted
 String getLogFileName()
          gets name of log file, which is currently in use
 int getLogLevel()
          Returns the current loglevel as number.
 String getLogLevelString()
          Returns gets the name of the current log level.
 byte getLogType()
          Returns the log type of this logger.
 String getLogTypeString()
          Returns the log type of this logger, as a string
 boolean hasLogFile()
          Checks, if this Logger4j instance uses a log file or System.out for logging.
 void log(String className, int logLevel, String methodName, Object[] logNotice)
          Logs a given notice, if the given logLevel is equal or more important than the configured agent log level.
Example: [31-Jul-00 09:20:13.560] [warning] [AgentDemo] [demoMethod()] this is a great warning log message
 void log(String className, int logLevel, String methodName, Object[] logNotice, Throwable throwable)
          Logs a given notice, if the given logLevel is equal or more important than the configured agent log level.
Example: [31-Jul-00 09:20:13.560] [warning] [AgentDemo] [demoMethod()] this is a great warning log message
 void log(String className, int logLevel, String methodName, String logNotice)
          Logs a given notice, if the given logLevel is equal or more important than the configured agent log level.
Example: [31-Jul-00 09:20:13.560] [warning] [AgentDemo] [demoMethod()] this is a great warning log message
 void log(String className, int logLevel, String methodName, String logNotice, Throwable throwable)
          Logs a given notice, if the given logLevel is equal or more important than the configured agent log level.
Example: [31-Jul-00 09:20:13.560] [warning] [AgentDemo] [demoMethod()] this is a great warning log message
 void log(String className, int logLevel, String methodName, Throwable throwable)
          Logs a throwable (Exception or Error) including a stack trace, if the given logLevel is equal or more important than the configured agent log level.
Example: [31-Jul-00 09:20:13.560] [error] [AgentDemo] [demoMethod()] ^^^ java.lang.NumberFormatException: null at java.lang.Long.parseLong(Long.java:284) at java.lang.Long.(Long.java:526) at com.ls.lars2.AgentDemo.demoMethod(AgentDemo.java:230) at com.ls.lars2.AgentDemo.interpret(AgentDemo.java:174) at com.ls.lars2.AgentTemplate.executeConfigFileInterpretation(AgentTemplate.java, Compiled Code) at com.ls.lars2.AgentTemplate.run(AgentTemplate.java, Compiled Code)
 void logSystemInformation()
          calls logSystemInformation on all configured system error log implementations and logs the output with log level ILogger.LEVEL_INDEPENDENT to this log file
 void logThreadName(boolean loggingThreadName)
          turns on or off the thread name specification
 void replacementMapPutAll(Map map)
          Puts map to the replacement map, which is used for exchanging variables in a logfile's name with values (for example replace $A with the name of the owning agent).
 boolean setLogFile(String logFileName)
          changes the log file to another file
 void setLogLevel(int logLevel)
          Sets the agent's log level.
 void setLogLevel(String logLevel)
          Sets the agent's log level.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Logger4j

public Logger4j()
Empty constructor. If this constructor is used all log messages will be outputted to the console (as long, as the setLogFile(java.lang.String) method is not called).

Note: variable substitution for logfile names cannot work the way you expect (e.g. exchanging $A with the agents' name) as long as you do not call replacementMapPutAll().


Logger4j

public Logger4j(String logFileName,
                Map map)
Constructor that includes trying to open the file where the log messages get stored.
Parameters:
logFileName - name of the log file
map - a Map containing variable/value pairs needed for variable substitution in log file names (e.g. for exchanging $A with the agent's name)

Logger4j

public Logger4j(String logFileName,
                int logLevel,
                Map map)
Constructor that includes trying to open the file where the log messages get stored and setting the log level.
Parameters:
logFileName - name of the log file
logLevel - determines which messages should be logged
map - a Map containing variable/value pairs needed for variable substitution in log file names (e.g. for exchanging $A with the agent's name)
Method Detail

closeLogFile

public void closeLogFile()
closes the logfile
Specified by:
closeLogFile in interface ILogger
Following copied from interface: com.ls.service.log.ILogger
Throws:
LogException - If any error occures while closing the log file

logSystemInformation

public void logSystemInformation()
calls logSystemInformation on all configured system error log implementations and logs the output with log level ILogger.LEVEL_INDEPENDENT to this log file
Specified by:
logSystemInformation in interface ILogger
See Also:
LoggerFactory.clearSystemErrorLogs(), LoggerFactory.addSystemErrorLog(ISystemErrorLog), LoggerFactory.getSystemErrorLogNames()

canLog

public boolean canLog(int logLevel)
determines, if a notice with the given log level will be logged
Specified by:
canLog in interface ILogger
Parameters:
logLevel - log level to compare against the configured log level
Returns:
true, if the given logLevel is equal or more important than the configured agent log level; false else

log

public void log(String className,
                int logLevel,
                String methodName,
                Throwable throwable)
Logs a throwable (Exception or Error) including a stack trace, if the given logLevel is equal or more important than the configured agent log level.
Example:
 [31-Jul-00 09:20:13.560] [error] [AgentDemo] [demoMethod()]
 ^^^ java.lang.NumberFormatException: null
	at java.lang.Long.parseLong(Long.java:284)
	at java.lang.Long.(Long.java:526)
	at com.ls.lars2.AgentDemo.demoMethod(AgentDemo.java:230)
	at com.ls.lars2.AgentDemo.interpret(AgentDemo.java:174)
	at com.ls.lars2.AgentTemplate.executeConfigFileInterpretation(AgentTemplate.java, Compiled Code)
	at com.ls.lars2.AgentTemplate.run(AgentTemplate.java, Compiled Code)
 
Specified by:
log in interface ILogger
Parameters:
className - Name of the class in which the log message was created
logLevel - level of the message (ILogger.TRACE5 ... ILogger.ERROR) determining, if the notice gets logged or ignored
methodName - Name of the method in which the log message was created
throwable - Throwable (Exception or Error) that should be logged

log

public void log(String className,
                int logLevel,
                String methodName,
                String logNotice)
Logs a given notice, if the given logLevel is equal or more important than the configured agent log level.
Example:
 [31-Jul-00 09:20:13.560] [warning] [AgentDemo] [demoMethod()] this is a great warning log message
 
Specified by:
log in interface ILogger
Parameters:
className - Name of the class in which the logMessage was created
logLevel - level of the message (ILogger.TRACE5 ... ILogger.ERROR) determining, if the notice gets logged or ignored
methodName - Name of the method in which the logMessage was created
logNotice - Content of the logMessage

log

public void log(String className,
                int logLevel,
                String methodName,
                Object[] logNotice)
Logs a given notice, if the given logLevel is equal or more important than the configured agent log level.
Example:
 [31-Jul-00 09:20:13.560] [warning] [AgentDemo] [demoMethod()] this is a great warning log message
 
Specified by:
log in interface ILogger
Parameters:
className - Name of the class in which the logMessage was created
logLevel - level of the message (ILogger.TRACE5 ... ILogger.ERROR) determining, if the notice gets logged or ignored
methodName - Name of the method in which the logMessage was created
logNotice - Content of the logMessage

log

public void log(String className,
                int logLevel,
                String methodName,
                String logNotice,
                Throwable throwable)
Logs a given notice, if the given logLevel is equal or more important than the configured agent log level.
Example:
 [31-Jul-00 09:20:13.560] [warning] [AgentDemo] [demoMethod()] this is a great warning log message
 
Specified by:
log in interface ILogger
Parameters:
className - Name of the class in which the logMessage was created
logLevel - level of the message (ILogger.TRACE5 ... ILogger.ERROR) determining, if the notice gets logged or ignored
methodName - Name of the method in which the logMessage was created
logNotice - Content of the logMessage
throwable - Throwable (Exception or Error) that should be logged

log

public void log(String className,
                int logLevel,
                String methodName,
                Object[] logNotice,
                Throwable throwable)
Logs a given notice, if the given logLevel is equal or more important than the configured agent log level.
Example:
 [31-Jul-00 09:20:13.560] [warning] [AgentDemo] [demoMethod()] this is a great warning log message
 
Specified by:
log in interface ILogger
Parameters:
className - Name of the class in which the logMessage was created
logLevel - level of the message (ILogger.TRACE5 ... ILogger.ERROR) determining, if the notice gets logged or ignored
methodName - Name of the method in which the logMessage was created
logNotice - Content of the logMessage
throwable - Throwable (Exception or Error) that should be logged

finalize

protected void finalize()
closes the log file if this object gets deleted
Overrides:
finalize in class Object

replacementMapPutAll

public void replacementMapPutAll(Map map)
Puts map to the replacement map, which is used for exchanging variables in a logfile's name with values (for example replace $A with the name of the owning agent).
Note: The new key/value pairs will not be used until the next log file is opened!
Specified by:
replacementMapPutAll in interface ILogger
Parameters:
map - a Map containing replacement variables as keys and replacements as values
See Also:
HashMap.putAll(Map)

setLogLevel

public void setLogLevel(int logLevel)
Sets the agent's log level. The agent's log level is used to specify if message of a cretain level has to be logged: If the log level of a log message is at least as important the agent's log level, the message is written, otherwise it is ignored.
Specified by:
setLogLevel in interface ILogger
Parameters:
logLevel - log level as an integer (use defined constants like ILogger.WARNING)

setLogLevel

public void setLogLevel(String logLevel)
                 throws LogException
Sets the agent's log level. The agent's log level is used to specify if message of a cretain level has to be logged: If the log level of a log message is at least as important the agent's log level, the message is written, otherwise it is ignored.
Specified by:
setLogLevel in interface ILogger
Parameters:
logLevel - name of one of the defined constants (e.g. "error"), case is ignored
Throws:
LogException - If given log level is null or unknown
See Also:
LoggerFactory.translateLogLevel(String)

getLogLevel

public int getLogLevel()
Returns the current loglevel as number. Example: 0=ERROR, 1=WARNING, 2=INFO, 3=TRACE ...
Specified by:
getLogLevel in interface ILogger
Returns:
The current loglevel

getLogLevelString

public String getLogLevelString()
Returns gets the name of the current log level. Example: ERROR, WARNING, INFO, TRACE ....
Specified by:
getLogLevelString in interface ILogger
Returns:
Name of the current loglevel

setLogFile

public boolean setLogFile(String logFileName)
changes the log file to another file
Specified by:
setLogFile in interface ILogger
Parameters:
logFileName - name of the file to be used as log file
Returns:
false, if the new log file could not be opened or the old one could not be closed; true else

hasLogFile

public boolean hasLogFile()
Checks, if this Logger4j instance uses a log file or System.out for logging.
Specified by:
hasLogFile in interface ILogger
Returns:
true, if a log file is in use; false if System.out is in use

getLogFileName

public String getLogFileName()
gets name of log file, which is currently in use
Specified by:
getLogFileName in interface ILogger
Returns:
log file's name or "System.out", if no log file is in use

logThreadName

public void logThreadName(boolean loggingThreadName)
turns on or off the thread name specification
Specified by:
logThreadName in interface ILogger
Parameters:
loggingThreadName - specifies if the name of the thread is gona be logged

getLogType

public byte getLogType()
Returns the log type of this logger.
Specified by:
getLogType in interface ILogger
Returns:
The log type of this logger (LOG4J)

getLogTypeString

public String getLogTypeString()
Returns the log type of this logger, as a string
Specified by:
getLogTypeString in interface ILogger
Returns:
The log type of this logger (LOG4J)