cz.cuni.amis.pogamut.base.utils.logging
Class AbstractAgentLogger

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.utils.logging.AbstractAgentLogger
All Implemented Interfaces:
IJMXEnabled, IAgentLogger, IJMXAgentLogger
Direct Known Subclasses:
AgentLogger, AgentLoggerJMXProxy

public abstract class AbstractAgentLogger
extends java.lang.Object
implements IAgentLogger

All logging apis are fine ... but we don't want to have loggers for classes but for instances - therefore we've created our wrapper allowing you to do two things quickly:

  1. log things
  2. create new logger categories
1) that's obvious - it should be easy

2) this may prove crucial for your debugging to have own logger for planner and another for emotions of your agents, etc.

Simply - every Agent instance (starting with the first abstract class AbstractAgent) has instance of this class (which is java.logging.Logger(s) wrapper).

Every agent's component has own LogCategory and you may obtain your own via getCategory() method.

LogCategory serves as a gateway for your log messages, it contains methods as you know them from java.logging API (things like fine(), info(), severe(), log(Level, msg), etc.).

Plus it allows you to obtain new LogHandler instances for that category (if you need to publish log messages from that category somewhere else).

Every LogHandler serves for filtering messages for one category and publishing them into one end (console, file, memory, whatever...).

Additionally every LogCategory has AgentLogger as its parent.


Field Summary
protected  IAgentId agentId
           
static java.lang.String LOG_CATEGORY_NAME
           
 
Constructor Summary
AbstractAgentLogger(IAgentId agentName)
           
 
Method Summary
 void addDefaultConsoleHandler()
          Adds console handler to every existing LogCategory plus to every new one.
 java.util.logging.Handler addDefaultFileHandler(java.io.File file)
          Adds console handler to every existing LogCategory plus to every new one.
 void addDefaultHandler(java.util.logging.Handler handler)
          Adds handler to every existing LogCategory plus to every new one.
 void addDefaultNetworkHandler()
          Adds network handler to every existing LogCategory plus to every new one.
 java.util.logging.Handler addDefaultPublisher(ILogPublisher publisher)
          Adds publisher to every existing LogCategory plus to every new one.
 void addToAllCategories(java.util.logging.Handler handler)
          Adds new handler to all categories.
 void addToAllCategories(ILogPublisher logPublisher)
          Adds new publisher to all categories.
 IAgentId getAgentId()
          Returns agent name.
 java.util.Map<java.lang.String,LogCategory> getCategories()
          Return immutable map of all log categories.
 LogCategory getCategory(IComponent component)
          Returns LogCategory for specified IComponent.
 LogCategory getCategory(java.lang.String name)
          Returns LogCategory for specified name.
 java.util.logging.Handler getDefaultConsoleHandler()
          Returns Handler that provides console publishing of all logs.
 java.util.logging.Handler getDefaultNetworkHandler()
          Returns Handler that provides publishing of all logs through NetworkLogPublisher.
protected abstract  ILogCategories getLogCategories()
           
 java.lang.String getNetworkLoggerHost()
          Returns a host where NetworkLogManager is listening.
 java.lang.Integer getNetworkLoggerPort()
          Returns port where NetworkLogManager is listening.
 boolean isDefaultConsoleHandler()
          Tells whether the logger has default console handler attached.
 boolean isDefaultNetworkHandler()
          Tells whether the logger has default network handler attached.
 void removeDefaultConsoleHandler()
          Removes default console handler from every existing LogCategory.
 void removeDefaultHandler(java.util.logging.Handler handler)
          Removes default handler from all existing LogCategory.
 void removeDefaultNetworkHandler()
          Removes default network handler from every existing LogCategory.
 void removeFromAllCategories(java.util.logging.Handler handler)
          Removes a handler from all categories.
 void setLevel(java.util.logging.Level newLevel)
          Set level for all handlers of all categories.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.amis.pogamut.base.agent.jmx.IJMXEnabled
enableJMX
 

Field Detail

LOG_CATEGORY_NAME

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

agentId

protected IAgentId agentId
Constructor Detail

AbstractAgentLogger

@Inject
public AbstractAgentLogger(IAgentId agentName)
Method Detail

getAgentId

public IAgentId getAgentId()
Description copied from interface: IAgentLogger
Returns agent name.

Specified by:
getAgentId in interface IAgentLogger
Returns:

getNetworkLoggerPort

public java.lang.Integer getNetworkLoggerPort()
Description copied from interface: IAgentLogger
Returns port where NetworkLogManager is listening.

Returns null if network logging is not enabled.

Specified by:
getNetworkLoggerPort in interface IAgentLogger
Specified by:
getNetworkLoggerPort in interface IJMXAgentLogger
Returns:

getNetworkLoggerHost

public java.lang.String getNetworkLoggerHost()
Description copied from interface: IAgentLogger
Returns a host where NetworkLogManager is listening.

Returns null if network logging is not enabled.

Specified by:
getNetworkLoggerHost in interface IAgentLogger
Specified by:
getNetworkLoggerHost in interface IJMXAgentLogger
Returns:

getCategories

public java.util.Map<java.lang.String,LogCategory> getCategories()
Description copied from interface: IAgentLogger
Return immutable map of all log categories. You have to synchronize on it before iterating through its elements.

Does not contain agent logger itself.

Specified by:
getCategories in interface IAgentLogger
Returns:

getLogCategories

protected abstract ILogCategories getLogCategories()

getCategory

public LogCategory getCategory(java.lang.String name)
Description copied from interface: IAgentLogger
Returns LogCategory for specified name. If category with this name doesn't exist new is created.

Specified by:
getCategory in interface IAgentLogger
Returns:

getCategory

public LogCategory getCategory(IComponent component)
Description copied from interface: IAgentLogger
Returns LogCategory for specified IComponent.

Specified by:
getCategory in interface IAgentLogger
Returns:

setLevel

public void setLevel(java.util.logging.Level newLevel)
Description copied from interface: IAgentLogger
Set level for all handlers of all categories.

Specified by:
setLevel in interface IAgentLogger

addDefaultConsoleHandler

public void addDefaultConsoleHandler()
Description copied from interface: IAgentLogger
Adds console handler to every existing LogCategory plus to every new one.

Shortcut for quick usage.

Specified by:
addDefaultConsoleHandler in interface IAgentLogger

getDefaultConsoleHandler

public java.util.logging.Handler getDefaultConsoleHandler()
Description copied from interface: IAgentLogger
Returns Handler that provides console publishing of all logs.

May return null in case that console logging is not enabled on the logger, i.e., you have to call IAgentLogger.addDefaultConsoleHandler().

Specified by:
getDefaultConsoleHandler in interface IAgentLogger
Returns:

removeDefaultConsoleHandler

public void removeDefaultConsoleHandler()
Description copied from interface: IAgentLogger
Removes default console handler from every existing LogCategory.

Specified by:
removeDefaultConsoleHandler in interface IAgentLogger

isDefaultConsoleHandler

public boolean isDefaultConsoleHandler()
Description copied from interface: IAgentLogger
Tells whether the logger has default console handler attached.

Specified by:
isDefaultConsoleHandler in interface IAgentLogger
Returns:

addDefaultNetworkHandler

public void addDefaultNetworkHandler()
Description copied from interface: IAgentLogger
Adds network handler to every existing LogCategory plus to every new one.

Enables utilization of NetworkLogManager for publishing all logs of this logger.

Specified by:
addDefaultNetworkHandler in interface IAgentLogger
Specified by:
addDefaultNetworkHandler in interface IJMXAgentLogger

getDefaultNetworkHandler

public java.util.logging.Handler getDefaultNetworkHandler()
Description copied from interface: IAgentLogger
Returns Handler that provides publishing of all logs through NetworkLogPublisher.

May return null in case that network logging is not enabled on the logger, i.e., you have to call IAgentLogger.addDefaultNetworkHandler().

Specified by:
getDefaultNetworkHandler in interface IAgentLogger
Returns:

removeDefaultNetworkHandler

public void removeDefaultNetworkHandler()
Description copied from interface: IAgentLogger
Removes default network handler from every existing LogCategory.

Note that this method is automatically called whenever the AbstractAgent is stopped/killed.

Specified by:
removeDefaultNetworkHandler in interface IAgentLogger
Specified by:
removeDefaultNetworkHandler in interface IJMXAgentLogger

isDefaultNetworkHandler

public boolean isDefaultNetworkHandler()
Description copied from interface: IAgentLogger
Tells whether the logger has default network handler attached.

It allows you to query whether the agent logger is outputting its logs to the NetworkLogManager or not.

Specified by:
isDefaultNetworkHandler in interface IAgentLogger
Specified by:
isDefaultNetworkHandler in interface IJMXAgentLogger
Returns:

addDefaultFileHandler

public java.util.logging.Handler addDefaultFileHandler(java.io.File file)
Description copied from interface: IAgentLogger
Adds console handler to every existing LogCategory plus to every new one.

Shortcut for quick usage.

Specified by:
addDefaultFileHandler in interface IAgentLogger
Returns:
new added handler

addDefaultPublisher

public java.util.logging.Handler addDefaultPublisher(ILogPublisher publisher)
Description copied from interface: IAgentLogger
Adds publisher to every existing LogCategory plus to every new one.

Specified by:
addDefaultPublisher in interface IAgentLogger
Returns:
newly added handler

addDefaultHandler

public void addDefaultHandler(java.util.logging.Handler handler)
Description copied from interface: IAgentLogger
Adds handler to every existing LogCategory plus to every new one.

Specified by:
addDefaultHandler in interface IAgentLogger

removeDefaultHandler

public void removeDefaultHandler(java.util.logging.Handler handler)
Description copied from interface: IAgentLogger
Removes default handler from all existing LogCategory.

Specified by:
removeDefaultHandler in interface IAgentLogger

addToAllCategories

public void addToAllCategories(ILogPublisher logPublisher)
Description copied from interface: IAgentLogger
Adds new publisher to all categories.

Specified by:
addToAllCategories in interface IAgentLogger

addToAllCategories

public void addToAllCategories(java.util.logging.Handler handler)
Description copied from interface: IAgentLogger
Adds new handler to all categories.

Specified by:
addToAllCategories in interface IAgentLogger

removeFromAllCategories

public void removeFromAllCategories(java.util.logging.Handler handler)
Description copied from interface: IAgentLogger
Removes a handler from all categories.

Specified by:
removeFromAllCategories in interface IAgentLogger