Class AgentLogger
java.lang.Object
java.util.logging.Logger
madkit.kernel.AgentLogger
This class defines a
Logger
specialized for MaDKit agents. Especially, it
provides a specific AgentFormatter
for agents. It also defines a special log
level, TALK
, and its corresponding method talk(String)
, which are
used to produce messages that will be rendered as they are, without any formatting work
nor end-of-line character.
This class also provides a way to create log files easily. By default, the log files
will be located in a directory named LOGS_DIRECTORY
and will be named using
Agent.getName()
.
An agent logger can be created by calling Agent.getLogger()
.
- Since:
- MaDKit 5.0.0.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Formatter
Defines the default file formatter as : LOG_LEVEL : messagestatic final Formatter
Defines the default formatter as : [agent's name] LOG_LEVEL : messagestatic final Path
The Constant DEFAULT_LOG_DIRECTORY.static final String
The name of the directory where the log files are stored.static final Level
Defines the default file formatter as : LOG_LEVEL : messageFields inherited from class java.util.logging.Logger
global, GLOBAL_LOGGER_NAME
-
Method Summary
Modifier and TypeMethodDescriptionvoid
This has the same effect as createLogFile(String, Path, boolean, boolean)(null, null, true, true)
.void
createLogFile
(String fileName) This has the same effect as createLogFile(String, Path, boolean, boolean)(fileName, null, true, true)
.void
createLogFile
(String fileName, Path logDirectory) This has the same effect as createLogFile(String, Path, boolean, boolean)(logDirectory, fileName, true, true)
.void
createLogFile
(String fileName, Path logDirectory, boolean append) This has the same effect as createLogFile(String, Path, boolean, boolean)(logDirectory, fileName, append, true)
.void
createLogFile
(String fileName, Path logDirectory, boolean append, boolean comments) Creates a log file for this logger.boolean
isLoggable
(Level level) Check if a message of the given level would actually be logged by this logger.void
override so that the throwable is printed if notnull
void
Logs aTALK
message.toString()
Methods inherited from class java.util.logging.Logger
addHandler, 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, setLevel, setParent, setResourceBundle, setUseParentHandlers, severe, severe, throwing, warning, warning
-
Field Details
-
LOGS_DIRECTORY
The name of the directory where the log files are stored.- See Also:
-
DEFAULT_LOG_DIRECTORY
The Constant DEFAULT_LOG_DIRECTORY. -
AGENT_FORMATTER
Defines the default formatter as : [agent's name] LOG_LEVEL : message -
TALK
Defines the default file formatter as : LOG_LEVEL : message -
AGENT_FILE_FORMATTER
Defines the default file formatter as : LOG_LEVEL : message
-
-
Method Details
-
toString
-
createLogFile
Creates a log file for this logger.- Parameters:
fileName
- May benull
, in which case the creation date is used in combination withLogger.getName()
logDirectory
- the logDirectory to use. May benull
, in which case the file will be located in a directory named Logsappend
- iftrue
, then bytes will be written to the end of the file rather than the beginningcomments
- iftrue
, includes comments displaying creation and closing dates- See Also:
-
createLogFile
This has the same effect as createLogFile(String, Path, boolean, boolean)(logDirectory, fileName, append, true)
.- Parameters:
fileName
- May benull
, in which case the creation date is used in combination withLogger.getName()
logDirectory
- the logDirectory to use. May benull
, in which case the file will be located in a directory named Logsappend
- iftrue
, then bytes will be written to the end of the file rather than the beginning
-
createLogFile
This has the same effect as createLogFile(String, Path, boolean, boolean)(logDirectory, fileName, true, true)
.- Parameters:
fileName
- May benull
, in which case the creation date is used in combination withLogger.getName()
logDirectory
- the logDirectory to use. May benull
, in which case the file will be located in a directory named Logs
-
createLogFile
This has the same effect as createLogFile(String, Path, boolean, boolean)(fileName, null, true, true)
.- Parameters:
fileName
- May benull
, in which case the creation date is used in combination withLogger.getName()
-
createLogFile
public void createLogFile()This has the same effect as createLogFile(String, Path, boolean, boolean)(null, null, true, true)
. -
talk
Logs aTALK
message. 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.OFF
then the given message is forwarded to all the registered output Handler objects.If the logger's level is
Level.OFF
then the message is only printed toSystem.out
- Parameters:
msg
- the log message
-
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. Has been overridden for improving performances.- Overrides:
isLoggable
in classLogger
- Parameters:
level
- a message logging level- Returns:
- true if the given message level is currently being logged.
-