de.fhg.igd.logging
Class LoggerImpl

java.lang.Object
  extended byde.fhg.igd.logging.LoggerImpl
All Implemented Interfaces:
Logger

public final class LoggerImpl
extends Object
implements Logger

This is a generic Logger implementation which provides the defined functionality by means of a Wrapper which depends on the underlying logging system. Instances are being used as targets of LoggerProxy objects.

Version:
"$Id: LoggerImpl.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Matthias Pressfreund

Field Summary
private static Set cache_
          The storage for all deployed logger objects
private  int cnt_
          The reference counter
private  String fgn_
          The formatted group name, ready for printout
protected  String group_
          The logger group
protected  Wrapper wrapper_
          The target wrapper
 
Constructor Summary
private LoggerImpl(String name, String group, Class wclazz)
          Hidden construction.
 
Method Summary
 void caught(LogLevel level, String msg, Throwable thrown)
          This method implicitely calls log(de.fhg.igd.logging.LogLevel, java.lang.String) first, then caught(Throwable).
 void caught(Throwable thrown)
          This method is supposed to be used for logging the catching of a Throwable (and subclasses).
 void debug(String msg)
          Creates a log entry on LogLevel.DEBUG.
 void dismiss()
          Removes this LoggerImpl from the cache in case it is no longer referenced.
 void entering()
          This method is supposed to be used for logging the entry of a parameterless method.
 void entering(Object[] params)
          This method is supposed to be used for logging the entry of a method with a set of parameters.
 boolean equals(Object obj)
           
 void error(String msg)
          Creates a log entry on LogLevel.ERROR.
 void exiting()
          This method is supposed to be used for logging the exit of a method without return value.
 void exiting(Object result)
          This method is supposed to be used for logging the exit of a method with a return value.
 void fatal(String msg)
          Creates a log entry on LogLevel.FATAL.
private  String formatCaught(Throwable thrown)
          Create a generic message for a caught Throwable.
private  String formatGenericMessage(StringBuffer buf)
          Create a generic message using the group name and the current SourceLocation.
private  String formatMethodEntry(Object[] params)
          Create a generic message for a method entry event.
private  String formatMethodExit(Object result)
          Create a generic message for a method exit event.
private  StringBuffer formatStackTrace(Throwable thrown)
          Create a printout for a Throwable.
private  String formatThrowing(Throwable thrown)
          Create a generic message for a Throwable that will cause a method exit.
 String getGroup()
           
 Wrapper getWrapper()
           
 int hashCode()
           
 void info(String msg)
          Creates a log entry on LogLevel.INFO.
 boolean isEnabled(LogLevel level)
          Find out if logging would be performed at the given log level.
 void log(LogLevel level, String msg)
          This is the generic log method to be used for creating a log entry on the specified log level.
(package private) static LoggerImpl requestFor(String name, String group, Class wclazz)
          Request a LoggerImpl instance.
 void severe(String msg)
          Creates a log entry on LogLevel.SEVERE.
 void throwing(LogLevel level, String msg, Throwable thrown)
          This method implicitely calls log(de.fhg.igd.logging.LogLevel, java.lang.String) first, then throwing(Throwable).
 void throwing(Throwable thrown)
          This method is supposed to be used for logging the creation and method exit by a Throwable (and subclasses).
 String toString()
           
 void trace(String msg)
          Creates a log entry on LogLevel.TRACE.
 void warning(String msg)
          Creates a log entry on LogLevel.WARNING.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

cache_

private static Set cache_
The storage for all deployed logger objects


cnt_

private int cnt_
The reference counter


group_

protected String group_
The logger group


fgn_

private String fgn_
The formatted group name, ready for printout


wrapper_

protected Wrapper wrapper_
The target wrapper

Constructor Detail

LoggerImpl

private LoggerImpl(String name,
                   String group,
                   Class wclazz)
Hidden construction.

Parameters:
name - The logger name
group - The logger group
wclazz - The Wrapper implementation class to be used
Method Detail

requestFor

static LoggerImpl requestFor(String name,
                             String group,
                             Class wclazz)
Request a LoggerImpl instance.

Parameters:
wclazz - The Wrapper implementation class to be used
name - The logger name
group - The logger group

getGroup

public String getGroup()

getWrapper

public Wrapper getWrapper()

log

public void log(LogLevel level,
                String msg)
Description copied from interface: Logger
This is the generic log method to be used for creating a log entry on the specified log level.

Specified by:
log in interface Logger
Parameters:
level - The log level to be used for creating the log entry
msg - The message to be written into the log entry

trace

public void trace(String msg)
Description copied from interface: Logger
Creates a log entry on LogLevel.TRACE.

Specified by:
trace in interface Logger
Parameters:
msg - The message to be written into the log entry

debug

public void debug(String msg)
Description copied from interface: Logger
Creates a log entry on LogLevel.DEBUG.

Specified by:
debug in interface Logger
Parameters:
msg - The message to be written into the log entry

info

public void info(String msg)
Description copied from interface: Logger
Creates a log entry on LogLevel.INFO.

Specified by:
info in interface Logger
Parameters:
msg - The message to be written into the log entry

warning

public void warning(String msg)
Description copied from interface: Logger
Creates a log entry on LogLevel.WARNING.

Specified by:
warning in interface Logger
Parameters:
msg - The message to be written into the log entry

error

public void error(String msg)
Description copied from interface: Logger
Creates a log entry on LogLevel.ERROR.

Specified by:
error in interface Logger
Parameters:
msg - The message to be written into the log entry

severe

public void severe(String msg)
Description copied from interface: Logger
Creates a log entry on LogLevel.SEVERE.

Specified by:
severe in interface Logger
Parameters:
msg - The message to be written into the log entry

fatal

public void fatal(String msg)
Description copied from interface: Logger
Creates a log entry on LogLevel.FATAL.

Specified by:
fatal in interface Logger
Parameters:
msg - The message to be written into the log entry

entering

public void entering()
Description copied from interface: Logger
This method is supposed to be used for logging the entry of a parameterless method. Hereby, the used log level will be LogLevel.TRACE.

Specified by:
entering in interface Logger

entering

public void entering(Object[] params)
Description copied from interface: Logger
This method is supposed to be used for logging the entry of a method with a set of parameters. Hereby, the used log level will be LogLevel.TRACE.

Specified by:
entering in interface Logger
Parameters:
params - The method parameters, for printing the toString() method will be called on each object

exiting

public void exiting()
Description copied from interface: Logger
This method is supposed to be used for logging the exit of a method without return value. Hereby, the used log level will be LogLevel.TRACE.

Specified by:
exiting in interface Logger

exiting

public void exiting(Object result)
Description copied from interface: Logger
This method is supposed to be used for logging the exit of a method with a return value. Hereby, the used log level will be LogLevel.TRACE.

Specified by:
exiting in interface Logger
Parameters:
result - The return value, for printing the toString() method will be called

throwing

public void throwing(Throwable thrown)
Description copied from interface: Logger
This method is supposed to be used for logging the creation and method exit by a Throwable (and subclasses). Hereby, the used log level will be LogLevel.TRACE.

Specified by:
throwing in interface Logger
Parameters:
thrown - The exception that will be thrown

throwing

public void throwing(LogLevel level,
                     String msg,
                     Throwable thrown)
Description copied from interface: Logger
This method implicitely calls Logger.log(de.fhg.igd.logging.LogLevel, java.lang.String) first, then Logger.throwing(Throwable).

Specified by:
throwing in interface Logger
Parameters:
level - The log level to be used for creating the log entry
msg - The message to be written into the log entry
thrown - The exception that will be thrown

caught

public void caught(Throwable thrown)
Description copied from interface: Logger
This method is supposed to be used for logging the catching of a Throwable (and subclasses). Hereby, the used log level will be LogLevel.TRACE.

Specified by:
caught in interface Logger
Parameters:
thrown - The exception that has been caught

caught

public void caught(LogLevel level,
                   String msg,
                   Throwable thrown)
Description copied from interface: Logger
This method implicitely calls Logger.log(de.fhg.igd.logging.LogLevel, java.lang.String) first, then Logger.caught(Throwable).

Specified by:
caught in interface Logger
Parameters:
level - The log level to be used for creating the log entry
msg - The message to be written into the log entry
thrown - The exception that has been caught

isEnabled

public boolean isEnabled(LogLevel level)
Description copied from interface: Logger
Find out if logging would be performed at the given log level.

This method might be useful in cases of costly log message creation which should be performed only if really needed.

Specified by:
isEnabled in interface Logger
Parameters:
level - The log level to check for
Returns:
whether or not logging would be performed at the given log level

dismiss

public void dismiss()
Removes this LoggerImpl from the cache in case it is no longer referenced.


formatGenericMessage

private String formatGenericMessage(StringBuffer buf)
Create a generic message using the group name and the current SourceLocation.

Parameters:
buf - The plain message text
Returns:
The formatted message printout, ready to be written into the log output

formatMethodEntry

private String formatMethodEntry(Object[] params)
Create a generic message for a method entry event.

Parameters:
params - The method's parameter values
Returns:
The formatted message printout, ready to be written into the log output

formatMethodExit

private String formatMethodExit(Object result)
Create a generic message for a method exit event.

Parameters:
result - The method's return value
Returns:
The formatted message printout, ready to be written into the log output

formatThrowing

private String formatThrowing(Throwable thrown)
Create a generic message for a Throwable that will cause a method exit.

Parameters:
thrown - The stacktrace origin to be thrown
Returns:
The formatted message printout, ready to be written into the log output

formatCaught

private String formatCaught(Throwable thrown)
Create a generic message for a caught Throwable.

Parameters:
thrown - The stacktrace origin that got caught
Returns:
The formatted message printout, ready to be written into the log output

formatStackTrace

private StringBuffer formatStackTrace(Throwable thrown)
Create a printout for a Throwable.

Parameters:
thrown - The stacktrace origin
Returns:
The formatted message printout, ready to be written into the log output

equals

public boolean equals(Object obj)

hashCode

public int hashCode()

toString

public String toString()


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.