Package madkit.kernel
Class AgentLogger
java.lang.Object
java.util.logging.Logger
madkit.kernel.AgentLogger
This class defines a logger specialized for MaDKit agents.
- Since:
- MaDKit 5.0.0.5
- Version:
- 1
- Author:
- Fabien Michel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FormatterDefines the default file formatter as : LOG_LEVEL : messagestatic final FormatterDefines the default formatter as : [agent's name] LOG_LEVEL : messageFields inherited from class java.util.logging.Logger
global, GLOBAL_LOGGER_NAME -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFileHandler(Path logDirectory, String fileName, boolean append, boolean includeDefaultComment) Adds a newFileHandlerto this logger.voidaddHandler(Handler handler) voidCreates a default log file for this logger.static voidCreate a log file for each agent having a nonnulllogger.voidDisables the logging ofLevel.WARNINGmessages related with failed queries over the artificial society.voidPrevents this logger to change its level whensetAllLoggersAtLevelAll()orsetAllLogLevels(Level)are used.voidEnables the logging ofLevel.WARNINGmessages related with failed queries over the artificial society.Deprecated.booleanTells if CGR warnings (Community, Group, Role) are enabled.booleanisLoggable(Level level) Check if a message of the given level would actually be logged by this logger.voidstatic voidreset all loggers to the level specified byMadkit.LevelOption.agentLogLevelstatic voidA convenient way of activating a debug sessionstatic voidsetAllLogLevels(Level level) Set all the agents' loggers to the specified levelvoidSet the log level for the corresponding agent.voidsetWarningLogLevel(Level warningLogLevel) Deprecated.as of MaDKit 5.2, replaced byenableCGRWarnings()voidThis call bypasses any settings and always produces severe log messages whatever the logger's current level.voidThis call bypasses any settings and always produces severe log messages displaying the stack trace of the throwable if it is notnullvoidLogs aTALKmessage.toString()Methods inherited from class java.util.logging.Logger
config, config, entering, entering, entering, exiting, exiting, fine, fine, finer, finer, finest, finest, getAnonymousLogger, getAnonymousLogger, getFilter, getGlobal, getHandlers, getLevel, getLogger, getLogger, getName, getParent, getResourceBundle, getResourceBundleName, getUseParentHandlers, info, info, log, log, log, log, log, log, logp, logp, logp, logp, logp, logp, logrb, logrb, logrb, logrb, logrb, logrb, logrb, logrb, removeHandler, setFilter, setParent, setResourceBundle, setUseParentHandlers, severe, severe, throwing, warning, warning
-
Field Details
-
AGENT_FORMATTER
Defines the default formatter as : [agent's name] LOG_LEVEL : message -
AGENT_FILE_FORMATTER
Defines the default file formatter as : LOG_LEVEL : message
-
-
Method Details
-
setLevel
Set the log level for the corresponding agent. IfnewLevelisLevel.ALLthenenableCGRWarnings()is automatically triggered. -
doNotReactToDebugMode
public void doNotReactToDebugMode()Prevents this logger to change its level whensetAllLoggersAtLevelAll()orsetAllLogLevels(Level)are used. -
isCGRWarningsOn
public boolean isCGRWarningsOn()Tells if CGR warnings (Community, Group, Role) are enabled.- Returns:
trueif CGR warnings are enabled for this logger- See Also:
-
enableCGRWarnings
public void enableCGRWarnings()Enables the logging ofLevel.WARNINGmessages related with failed queries over the artificial society. For instance, if an agent tries to get agent addresses usingAbstractAgent.getAgentsWithRole(String, String, String)over a CGR location which does not exist then there will be a warning about that. Since such results could be obtained by agents on purpose, this method provides a convenient way of enabling these kind of traces as will. -
disableCGRWarnings
public void disableCGRWarnings()Disables the logging ofLevel.WARNINGmessages related with failed queries over the artificial society.- See Also:
-
getEnableCGRWarningsAction
- Returns:
- an
Actionfor building UI with this feature
-
createLogFile
public void createLogFile()Creates a default log file for this logger. This call is equivalent toaddLogFile(null, null, false, true)This file will be located in the directory specified by the MaDKit propertyMadkit.Option.logDirectory, which is set to "logs" by default. -
addFileHandler
public void addFileHandler(Path logDirectory, String fileName, boolean append, boolean includeDefaultComment) Adds a newFileHandlerto this logger. This method provides an easy way of creating a new file handler with an agent formatting and with a corresponding file located in a specified directory. The related file will be located in the directory specified by the MaDKit propertyMadkit.Option.logDirectory, which is set to "logs" followed by a directory named according to the date of the run.- Parameters:
logDirectory- the logDirectory to be used may benull, in which case the file will be located in the directory specified by the MaDKit propertyMadkit.Option.logDirectorywhich is set to "logs" by default.fileName- may benull, in which caseLogger.getName()is usedappend- iftrue, then bytes will be written to the end of the file rather than the beginningincludeDefaultComment- iftrue, includes comments displaying creation and closing dates- See Also:
-
addHandler
- Overrides:
addHandlerin classLogger
-
talk
Logs aTALKmessage. This uses a special level which could be used to produce messages that will be rendered as they are, without any formatting work nor end-of-line character.If the logger's level is not
Level.OFFthen the given message is forwarded to all the registered output Handler objects.If the logger's level is
Level.OFFthen the message is only printed toSystem.out- Parameters:
msg- The string message
-
toString
-
log
-
isLoggable
Check if a message of the given level would actually be logged by this logger. This check is based on the Loggers effective level, which may be inherited from its parent.- Overrides:
isLoggablein classLogger- Parameters:
level- a message logging level- Returns:
- true if the given message level is currently being logged.
-
severeLog
This call bypasses any settings and always produces severe log messages displaying the stack trace of the throwable if it is notnull- Parameters:
message- the message to displayt- the related exception if any. It can benull
-
severeLog
This call bypasses any settings and always produces severe log messages whatever the logger's current level.- Parameters:
message- the message to display
-
setAllLogLevels
Set all the agents' loggers to the specified level- Parameters:
level- the new level
-
setAllLoggersAtLevelAll
public static void setAllLoggersAtLevelAll()A convenient way of activating a debug session -
resetAllLoggersToDefaultLevel
public static void resetAllLoggersToDefaultLevel()reset all loggers to the level specified byMadkit.LevelOption.agentLogLevel -
createLogFiles
public static void createLogFiles()Create a log file for each agent having a nonnulllogger.- See Also:
-
getWarningLogLevel
Deprecated.as of MaDKit 5.2, replaced byenableCGRWarnings()now useless. -
setWarningLogLevel
Deprecated.as of MaDKit 5.2, replaced byenableCGRWarnings()now useless.
-
enableCGRWarnings()