Class AgentLogger

java.lang.Object
java.util.logging.Logger
madkit.kernel.AgentLogger

public class AgentLogger extends Logger
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 Details

    • LOGS_DIRECTORY

      public static final String LOGS_DIRECTORY
      The name of the directory where the log files are stored.
      See Also:
    • DEFAULT_LOG_DIRECTORY

      public static final Path DEFAULT_LOG_DIRECTORY
      The Constant DEFAULT_LOG_DIRECTORY.
    • AGENT_FORMATTER

      public static final Formatter AGENT_FORMATTER
      Defines the default formatter as : [agent's name] LOG_LEVEL : message
    • TALK

      public static final Level TALK
      Defines the default file formatter as : LOG_LEVEL : message
    • AGENT_FILE_FORMATTER

      public static final Formatter AGENT_FILE_FORMATTER
      Defines the default file formatter as : LOG_LEVEL : message
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • createLogFile

      public void createLogFile(String fileName, Path logDirectory, boolean append, boolean comments)
      Creates a log file for this logger.
      Parameters:
      fileName - May be null, in which case the creation date is used in combination with Logger.getName()
      logDirectory - the logDirectory to use. May be null, in which case the file will be located in a directory named Logs
      append - if true, then bytes will be written to the end of the file rather than the beginning
      comments - if true, includes comments displaying creation and closing dates
      See Also:
    • createLogFile

      public void createLogFile(String fileName, Path logDirectory, boolean append)
      This has the same effect as createLogFile(String, Path, boolean, boolean) (logDirectory, fileName, append, true).
      Parameters:
      fileName - May be null, in which case the creation date is used in combination with Logger.getName()
      logDirectory - the logDirectory to use. May be null, in which case the file will be located in a directory named Logs
      append - if true, then bytes will be written to the end of the file rather than the beginning
    • createLogFile

      public void createLogFile(String fileName, Path logDirectory)
      This has the same effect as createLogFile(String, Path, boolean, boolean) (logDirectory, fileName, true, true).
      Parameters:
      fileName - May be null, in which case the creation date is used in combination with Logger.getName()
      logDirectory - the logDirectory to use. May be null, in which case the file will be located in a directory named Logs
    • createLogFile

      public void createLogFile(String fileName)
      This has the same effect as createLogFile(String, Path, boolean, boolean) (fileName, null, true, true).
      Parameters:
      fileName - May be null, in which case the creation date is used in combination with Logger.getName()
    • createLogFile

      public void createLogFile()
      This has the same effect as createLogFile(String, Path, boolean, boolean) (null, null, true, true).
    • talk

      public void talk(String msg)
      Logs a TALK 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 to System.out

      Parameters:
      msg - the log message
    • log

      public void log(LogRecord record)
      override so that the throwable is printed if not null
      Overrides:
      log in class Logger
    • isLoggable

      public boolean isLoggable(Level level)
      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 class Logger
      Parameters:
      level - a message logging level
      Returns:
      true if the given message level is currently being logged.