org.objectweb.util.monolog.wrapper.printwriter
Class LoggerImpl

java.lang.Object
  extended by org.objectweb.util.monolog.wrapper.printwriter.LoggerImpl
All Implemented Interfaces:
Handler, HandlerFactory, LevelFactory, Logger, LoggerFactory, MonologFactory, TopicalLogger

public class LoggerImpl
extends java.lang.Object
implements TopicalLogger, MonologFactory

This class is a simple implementation of the Logger interface provided by the monolog specification.

Author:
sebastien.chassande@inrialpes.fr

Field Summary
protected  boolean additivity
           
protected  java.util.Hashtable handlers
           
protected  java.util.Map levels
           
protected  java.lang.String name
           
static java.lang.String PRINT_WRITER
           
protected  java.util.Vector topics
           
 
Fields inherited from interface org.objectweb.util.monolog.api.Handler
APPEND_MODE_ATTRIBUTE, BUFFER_ATTRIBUTE, CONSOLE_HANDLER_TYPE, FILE_HANDLER_TYPE, FILE_NUMBER_ATTRIBUTE, GENERIC_HANDLER_TYPE, JMX_HANDLER_TYPE, LEVEL_ATTRIBUTE, LOGGER_HANDLER_TYPE, MAX_SIZE_ATTRIBUTE, OUTPUT_ATTRIBUTE, PATTERN_ATTRIBUTE, ROLLING_FILE_HANDLER_TYPE
 
Fields inherited from interface org.objectweb.util.monolog.api.MonologFactory
DEFAULT, LOG_CONFIGURATION_FILE, LOG_CONFIGURATION_FILE_USE_CLASSPATH, LOG_CONFIGURATION_TYPE, PROPERTY, XML
 
Constructor Summary
LoggerImpl()
          This constructor permits to specify the printWriter linked to this logger
LoggerImpl(java.io.PrintWriter _pw)
          This constructor permits to specify the printWriter linked to this logger
LoggerImpl(java.lang.String n, java.io.PrintWriter _pw)
          This constructor permits to specify the printWriter linked to this logger
 
Method Summary
 void addHandler(Handler h)
          A TopicalLogger manages a list of Handler instances.
 void addMonologFactoryListener(MonologFactoryListener mfl)
          register a listener for the events of this MonologFactory
 void addTopic(java.lang.String topic)
          This method allows adding a topic to a TopicalLogger.
 void configure(java.util.Properties prop)
          This method permits to order to a monolog wrapper to configure the underlying log system.
 Handler createHandler(java.lang.String hn, java.lang.String handlertype)
          It retrieves a new instance of an handler which the type is specified by the parameter.
 Level defineLevel(java.lang.String name, int value)
          It defines a new Level with a name and an integer value.
 Level defineLevel(java.lang.String name, java.lang.String value)
          It defines a new Level with a name and a string value.
static java.lang.String format(java.lang.String msg, int removeTopStack)
          This method permits to format messages.
 boolean getAdditivity()
          It retrieves the additivity flag for this logger instance.
 java.lang.Object getAttribute(java.lang.String name)
          It retrieves the value of an attribute value of the handler.
 java.lang.String[] getAttributeNames()
          It retrieves the attributes of the handler
 int getCurrentIntLevel()
          Gets the CurrentIntLevel attribute of the LoggerImpl object
 Level getCurrentLevel()
          Gets the CurrentLevel attribute of the LoggerImpl object
 Handler[] getHandler()
          It returns the list of the handler associated to this logger.
 Handler getHandler(java.lang.String hn)
          It returns the handler which the name is equals to the parameter
 Handler[] getHandlers()
          It retrieves all handler managed by this factory.
 Level getLevel(int value)
          This method is not synchronized because the configuration is rarely
 Level getLevel(java.lang.String name)
          It retrieves a Level instance which the name is equals to the parameter.
 Level[] getLevels()
          This method is not synchronized because the configuration is rarely
 Logger getLogger(java.lang.String key)
          This method permits to fetch a Logger.
 Logger getLogger(java.lang.String key, java.lang.String resourceBundleName)
          This method permits to fetch a Logger.
 Logger[] getLoggers()
          It retrieves a list of all loggers.
 java.lang.String getName()
          It retrieves the name of the handler
 java.io.PrintWriter getPrintWriter()
           
 java.lang.String getResourceBundleName()
          Accessors to a resource bundle name associated to a LoggerFactory.
 java.lang.String[] getTopic()
          This method allows getting a topic list of this TopicalLogger.
 java.lang.String getTopicPrefix()
          A Logger Factory can have a prefix helping for isolate applications.
 java.util.Enumeration getTopics()
          Gets the Topics attribute of the LoggerImpl object
 java.lang.String getType()
          It retrieves the Handler type
 boolean isLoggable(int l)
          Gets the Loggable attribute of the LoggerImpl object
 boolean isLoggable(Level l)
          Gets the Loggable attribute of the LoggerImpl object
 boolean isOn()
          Gets the On attribute of the LoggerImpl object
 void log(int level, java.lang.Object o)
          Log method
 void log(int level, java.lang.Object o, java.lang.Object location, java.lang.Object method)
          Log method
 void log(int level, java.lang.Object o, java.lang.Throwable t)
          Log method
 void log(int level, java.lang.Object o, java.lang.Throwable t, java.lang.Object location, java.lang.Object method)
          Log method
 void log(Level l, java.lang.Object o)
          Log method
 void log(Level l, java.lang.Object o, java.lang.Object location, java.lang.Object method)
          Log method
 void log(Level l, java.lang.Object o, java.lang.Throwable t)
          Log method
 void log(Level l, java.lang.Object o, java.lang.Throwable t, java.lang.Object location, java.lang.Object method)
          Log method
 void removeAllHandlers()
          A TopicalLogger manages a list of Handler instances.
 void removeHandler(Handler h)
          A TopicalLogger manages a list of Handler instances.
 Handler removeHandler(java.lang.String handlername)
          It removes the handler which the name is specified by the parameter
 void removeLevel(java.lang.String name)
          It removes a Level instance to this manager.
 void removeMonologFactoryListener(MonologFactoryListener mfl)
          forget a listener for the events of this MonologFactory
 void removeTopic(java.lang.String topic)
          This method allows removing a topic to a TopicalLogger.
 void setAdditivity(boolean a)
          It assigns the additivity flag for this logger instance.
 java.lang.Object setAttribute(java.lang.String name, java.lang.Object value)
          It assigns an attributte to the handler.
 void setIntLevel(int l)
          Sets the IntLevel attribute of the LoggerImpl object
 void setLevel(Level l)
          Sets the Level attribute of the LoggerImpl object
 void setName(java.lang.String n)
          It assigns the name of the handler
 void setResourceBundleName(java.lang.String resourceBundleName)
          Accessors to a resource bundle name associated to a LoggerFactory.
 java.lang.String toString()
          The toString method is override to signal the logger imlementation fowards its messages to a printwriter
 void turnOff()
          Turn off this logger
 void turnOn()
          Turn on this logger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PRINT_WRITER

public static final java.lang.String PRINT_WRITER
See Also:
Constant Field Values

name

protected java.lang.String name

topics

protected java.util.Vector topics

handlers

protected java.util.Hashtable handlers

additivity

protected boolean additivity

levels

protected java.util.Map levels
Constructor Detail

LoggerImpl

public LoggerImpl()
This constructor permits to specify the printWriter linked to this logger


LoggerImpl

public LoggerImpl(java.io.PrintWriter _pw)
This constructor permits to specify the printWriter linked to this logger

Parameters:
_pw - the printwriter

LoggerImpl

public LoggerImpl(java.lang.String n,
                  java.io.PrintWriter _pw)
This constructor permits to specify the printWriter linked to this logger

Parameters:
_pw - the printwriter
Method Detail

getPrintWriter

public java.io.PrintWriter getPrintWriter()

addMonologFactoryListener

public void addMonologFactoryListener(MonologFactoryListener mfl)
Description copied from interface: MonologFactory
register a listener for the events of this MonologFactory

Specified by:
addMonologFactoryListener in interface MonologFactory

removeMonologFactoryListener

public void removeMonologFactoryListener(MonologFactoryListener mfl)
Description copied from interface: MonologFactory
forget a listener for the events of this MonologFactory

Specified by:
removeMonologFactoryListener in interface MonologFactory

configure

public void configure(java.util.Properties prop)
               throws java.lang.Exception
Description copied from interface: MonologFactory
This method permits to order to a monolog wrapper to configure the underlying log system.

Specified by:
configure in interface MonologFactory
Parameters:
prop - contains properties which describes the way to configure. In particular three properties could be used:
  • LOG_CONFIGURATION_TYPE
  • LOG_CONFIGURATION_FILE
  • LOG_CONFIGURATION_FILE_USE_CLASSPATH
    • Throws:
      java.lang.Exception

createHandler

public Handler createHandler(java.lang.String hn,
                             java.lang.String handlertype)
Description copied from interface: HandlerFactory
It retrieves a new instance of an handler which the type is specified by the parameter.

Specified by:
createHandler in interface HandlerFactory
handlertype - is the type of the parameter. The possible value are defined in this interface by the XXX_HANDLER_TYPE constants.
Returns:
a new instance of an handler

removeHandler

public Handler removeHandler(java.lang.String handlername)
Description copied from interface: HandlerFactory
It removes the handler which the name is specified by the parameter

Specified by:
removeHandler in interface HandlerFactory
Parameters:
handlername - is the name of the handler
Returns:
the removed handler instance or a null value if it does not exist.

getHandlers

public Handler[] getHandlers()
Description copied from interface: HandlerFactory
It retrieves all handler managed by this factory.

Specified by:
getHandlers in interface HandlerFactory
Returns:
a set of Handler instance or an empty set.

defineLevel

public Level defineLevel(java.lang.String name,
                         int value)
Description copied from interface: LevelFactory
It defines a new Level with a name and an integer value.

Specified by:
defineLevel in interface LevelFactory
Parameters:
name - is the name of the new level
value - is the integer value of the new level
Returns:
a Level instance or a null value if It exists a Level with the same name but with another integer value.

defineLevel

public Level defineLevel(java.lang.String name,
                         java.lang.String value)
Description copied from interface: LevelFactory
It defines a new Level with a name and a string value. The string value is analyzed to obtain the integer value.

Specified by:
defineLevel in interface LevelFactory
Parameters:
name - is the name of the new level
value - is the string value of the new level
Returns:
a Level instance or a null value if It exists a Level with the same name but with another integer value.

getLevel

public Level getLevel(java.lang.String name)
Description copied from interface: LevelFactory
It retrieves a Level instance which the name is equals to the parameter.

Specified by:
getLevel in interface LevelFactory
Parameters:
name - is the name of request Level
Returns:
a Leve instance or a null value if the level does not exist.

getLevel

public Level getLevel(int value)
This method is not synchronized because the configuration is rarely

Specified by:
getLevel in interface LevelFactory
Parameters:
value - is the integer value of request Level
Returns:
a Leve instance or a null value if the level does not exist. As it is possible to define several Levels which have the same integer value this methods returns the Level instance of first name found in the list.

getLevels

public Level[] getLevels()
This method is not synchronized because the configuration is rarely

Specified by:
getLevels in interface LevelFactory

removeLevel

public void removeLevel(java.lang.String name)
Description copied from interface: LevelFactory
It removes a Level instance to this manager.

Specified by:
removeLevel in interface LevelFactory

getLogger

public Logger getLogger(java.lang.String key)
Description copied from interface: LoggerFactory
This method permits to fetch a Logger. If the Logger described by the parameters does not exist, then the LoggerFactory must return a new instance of Logger. The key parameter is a description of the expected Logger. In simple cases, the key is the initial topic of the Logger.

Specified by:
getLogger in interface LoggerFactory

getLogger

public Logger getLogger(java.lang.String key,
                        java.lang.String resourceBundleName)
Description copied from interface: LoggerFactory
This method permits to fetch a Logger. If the Logger described by the parameters does not exist, then the LoggerFactory must return a new instance of Logger. The key parameter is a description of the expected Logger. In simple cases, the key is the initial topic of the Logger. The resourceBundleName parameter allows specifying the name of a resource bundle in order to internationalise the logging.

Specified by:
getLogger in interface LoggerFactory

getResourceBundleName

public java.lang.String getResourceBundleName()
Description copied from interface: LoggerFactory
Accessors to a resource bundle name associated to a LoggerFactory.

Specified by:
getResourceBundleName in interface LoggerFactory

setResourceBundleName

public void setResourceBundleName(java.lang.String resourceBundleName)
Description copied from interface: LoggerFactory
Accessors to a resource bundle name associated to a LoggerFactory.

Specified by:
setResourceBundleName in interface LoggerFactory

getLoggers

public Logger[] getLoggers()
Description copied from interface: LoggerFactory
It retrieves a list of all loggers.

Specified by:
getLoggers in interface LoggerFactory

getTopicPrefix

public java.lang.String getTopicPrefix()
Description copied from interface: LoggerFactory
A Logger Factory can have a prefix helping for isolate applications. To assume the isolation, a prefix can be used for topic name.

Specified by:
getTopicPrefix in interface LoggerFactory
Returns:
the prefix of the topic name.

setIntLevel

public void setIntLevel(int l)
Sets the IntLevel attribute of the LoggerImpl object

Specified by:
setIntLevel in interface Logger
Parameters:
l - The new IntLevel value

setLevel

public void setLevel(Level l)
Sets the Level attribute of the LoggerImpl object

Specified by:
setLevel in interface Logger
Parameters:
l - The new Level value

getCurrentIntLevel

public int getCurrentIntLevel()
Gets the CurrentIntLevel attribute of the LoggerImpl object

Specified by:
getCurrentIntLevel in interface Logger
Returns:
The CurrentIntLevel value

getCurrentLevel

public Level getCurrentLevel()
Gets the CurrentLevel attribute of the LoggerImpl object

Specified by:
getCurrentLevel in interface Logger
Returns:
The CurrentLevel value

isLoggable

public boolean isLoggable(int l)
Gets the Loggable attribute of the LoggerImpl object

Specified by:
isLoggable in interface Logger
Parameters:
l - Description of Parameter
Returns:
The Loggable value

isLoggable

public boolean isLoggable(Level l)
Gets the Loggable attribute of the LoggerImpl object

Specified by:
isLoggable in interface Logger
Parameters:
l - Description of Parameter
Returns:
The Loggable value

isOn

public boolean isOn()
Gets the On attribute of the LoggerImpl object

Specified by:
isOn in interface Logger
Returns:
The On value

getTopics

public java.util.Enumeration getTopics()
Gets the Topics attribute of the LoggerImpl object

Specified by:
getTopics in interface TopicalLogger
Returns:
The Topics value

log

public void log(int level,
                java.lang.Object o)
Log method

Specified by:
log in interface Logger

log

public void log(Level l,
                java.lang.Object o)
Log method

Specified by:
log in interface Logger

log

public void log(int level,
                java.lang.Object o,
                java.lang.Throwable t)
Log method

Specified by:
log in interface Logger

log

public void log(Level l,
                java.lang.Object o,
                java.lang.Throwable t)
Log method

Specified by:
log in interface Logger

log

public void log(int level,
                java.lang.Object o,
                java.lang.Object location,
                java.lang.Object method)
Log method

Specified by:
log in interface Logger

log

public void log(Level l,
                java.lang.Object o,
                java.lang.Object location,
                java.lang.Object method)
Log method

Specified by:
log in interface Logger

log

public void log(int level,
                java.lang.Object o,
                java.lang.Throwable t,
                java.lang.Object location,
                java.lang.Object method)
Log method

Specified by:
log in interface Logger

log

public void log(Level l,
                java.lang.Object o,
                java.lang.Throwable t,
                java.lang.Object location,
                java.lang.Object method)
Log method

Specified by:
log in interface Logger

turnOn

public void turnOn()
Turn on this logger

Specified by:
turnOn in interface Logger

turnOff

public void turnOff()
Turn off this logger

Specified by:
turnOff in interface Logger

toString

public java.lang.String toString()
The toString method is override to signal the logger imlementation fowards its messages to a printwriter

Overrides:
toString in class java.lang.Object

addHandler

public void addHandler(Handler h)
                throws java.lang.Exception
Description copied from interface: TopicalLogger
A TopicalLogger manages a list of Handler instances. This method allows adding a handler to this list. The addHandler method returns true only if the Handler did not exist

Specified by:
addHandler in interface TopicalLogger
Throws:
java.lang.Exception

addTopic

public void addTopic(java.lang.String topic)
              throws java.lang.Exception
Description copied from interface: TopicalLogger
This method allows adding a topic to a TopicalLogger. This actions change the hierarchical structure, but also the list of handlers. The list of handlers of a TopicalLogger is composed of its handlers and all handlers inherited from its parents. Adding a topic changes the inherited handlers list.

Specified by:
addTopic in interface TopicalLogger
Throws:
java.lang.Exception

removeHandler

public void removeHandler(Handler h)
                   throws java.lang.Exception
Description copied from interface: TopicalLogger
A TopicalLogger manages a list of Handler instances. This method allows removing a handler to this list.

Specified by:
removeHandler in interface TopicalLogger
Throws:
java.lang.Exception

removeAllHandlers

public void removeAllHandlers()
                       throws java.lang.Exception
Description copied from interface: TopicalLogger
A TopicalLogger manages a list of Handler instances. This method allows removing all handler.

Specified by:
removeAllHandlers in interface TopicalLogger
Throws:
java.lang.Exception

removeTopic

public void removeTopic(java.lang.String topic)
                 throws java.lang.Exception
Description copied from interface: TopicalLogger
This method allows removing a topic to a TopicalLogger. This actions change the hierarchical structure, but also the list of handlers. The list of handlers of a TopicalLogger is composed of its handlers and all handlers inherited from its parents. Removing a topic changes the inherited handlers list.

Specified by:
removeTopic in interface TopicalLogger
Throws:
java.lang.Exception

setAdditivity

public void setAdditivity(boolean a)
Description copied from interface: TopicalLogger
It assigns the additivity flag for this logger instance.

Specified by:
setAdditivity in interface TopicalLogger

getAdditivity

public boolean getAdditivity()
Description copied from interface: TopicalLogger
It retrieves the additivity flag for this logger instance.

Specified by:
getAdditivity in interface TopicalLogger

getHandler

public Handler[] getHandler()
Description copied from interface: TopicalLogger
It returns the list of the handler associated to this logger.

Specified by:
getHandler in interface TopicalLogger
Returns:
an array of Handler or an empty array.

getHandler

public Handler getHandler(java.lang.String hn)
Description copied from interface: TopicalLogger
It returns the handler which the name is equals to the parameter

Specified by:
getHandler in interface HandlerFactory
Specified by:
getHandler in interface TopicalLogger
Parameters:
hn - is the name of the handler
Returns:
an Handler or a null value.

getTopic

public java.lang.String[] getTopic()
Description copied from interface: TopicalLogger
This method allows getting a topic list of this TopicalLogger.

Specified by:
getTopic in interface TopicalLogger

getName

public java.lang.String getName()
Description copied from interface: Handler
It retrieves the name of the handler

Specified by:
getName in interface Handler

setName

public void setName(java.lang.String n)
Description copied from interface: Handler
It assigns the name of the handler

Specified by:
setName in interface Handler

getType

public java.lang.String getType()
Description copied from interface: Handler
It retrieves the Handler type

Specified by:
getType in interface Handler

getAttributeNames

public java.lang.String[] getAttributeNames()
Description copied from interface: Handler
It retrieves the attributes of the handler

Specified by:
getAttributeNames in interface Handler

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface: Handler
It retrieves the value of an attribute value of the handler.

Specified by:
getAttribute in interface Handler
Parameters:
name - is an attribute name

setAttribute

public java.lang.Object setAttribute(java.lang.String name,
                                     java.lang.Object value)
Description copied from interface: Handler
It assigns an attributte to the handler.

Specified by:
setAttribute in interface Handler
Parameters:
name - is the attribute name
value - is the attribute value
Returns:
the old value is the attribute was already defined

format

public static java.lang.String format(java.lang.String msg,
                                      int removeTopStack)
This method permits to format messages. More exatcly this method find the class name and the method name where the log call was done. In order to find the right class name and method name, this method is parametrable either the number of call done in this logger.