Class L2pLogger

java.lang.Object
java.util.logging.Logger
i5.las2peer.logging.L2pLogger
All Implemented Interfaces:
NodeObserver

public final class L2pLogger extends Logger implements NodeObserver
  • Field Details

  • Constructor Details

    • L2pLogger

      protected L2pLogger(String name, String resourceBundleName) throws IllegalArgumentException
      Just calls the parent constructor and adds the new instance to the LogManager.
      Parameters:
      name - A name for the logger. This should be a dot-separated name and should normally be based on the package name or class name of the subsystem, such as java.net or javax.swing. It may be null for anonymous Loggers.
      resourceBundleName - name of ResourceBundle to be used for localizing messages for this logger. May be null if none of the messages require localization.
      Throws:
      IllegalArgumentException - If a logger with the given name is already registered.
  • Method Details

    • printStackTrace

      public void printStackTrace(Throwable e)
      Prints a stack trace as nicely as e.printStackTrace(), but uses the logging system as output.
      Parameters:
      e - A Throwable thats stack trace should be printed.
    • printStackTrace

      protected static void printStackTrace(StringBuilder sb, Throwable e)
      Appends the stack trace for the given Throwable to the given StringBuilder.
      Parameters:
      sb - StringBuilder as output for the stack trace.
      e - A Throwable which stack trace should be appended. If null given, nothing is appended.
    • setGlobalLogDirectory

      public static void setGlobalLogDirectory(String directory) throws IOException
      Same as setLogDirectory(String) for the global static instance.
      Parameters:
      directory - A directory path given as String. null is equal to "" and the class loader directory.
      Throws:
      IOException - If the log file could not be written
    • setLogDirectory

      public void setLogDirectory(String directory) throws IOException
      Sets the directory to store log files.
      Parameters:
      directory - A directory path given as String. null is equal to "" and the class loader directory.
      Throws:
      IOException - If the log file could not be written
    • setGlobalLogfilePrefix

      public static void setGlobalLogfilePrefix(String prefix) throws IOException
      Same as setLogfilePrefix(String) for global static instance.
      Parameters:
      prefix - If null is given, file logging will be disabled.
      Throws:
      IOException - If the log file could not be written
    • setLogfilePrefix

      public void setLogfilePrefix(String prefix) throws IOException
      Sets the prefix used to generate log files.
      Parameters:
      prefix - If null is given, file logging will be disabled.
      Throws:
      IOException - If the log file could not be written
    • setGlobalConsoleLevel

      public static void setGlobalConsoleLevel(Level level)
      Same as setConsoleLevel(Level) for the global static instance.
      Parameters:
      level - The log level to set.
    • setConsoleLevel

      public void setConsoleLevel(Level level)
      Sets the log level for the console output of this logger.
      Parameters:
      level - The log level to set.
    • setGlobalLogfileLevel

      public static void setGlobalLogfileLevel(Level level)
      Same as setLogfileLevel(Level) for global static instance.
      Parameters:
      level - The log level to set.
    • setLogfileLevel

      public void setLogfileLevel(Level level)
      Sets the log level for the log files used in this logger.
      Parameters:
      level - The log level to set.
    • log

      public void log(LogRecord record)
      Overrides:
      log in class Logger
    • logEvent

      @Deprecated public static void logEvent(MonitoringEvent event, String message)
      Deprecated.
      Use Context.monitorEvent(MonitoringEvent, String) Writes a log message. The given event can be used to differentiate between different log messages.
      Parameters:
      event - used to differentiate between different log messages
      message - A message to log in the monitoring data
    • logEvent

      @Deprecated public static void logEvent(MonitoringEvent event, Agent actingUser, String message)
      Deprecated.
      Use Context.monitorEvent(Object, MonitoringEvent, String, boolean) Writes a log message. The given event can be used to differentiate between different log messages.
      Parameters:
      event - used to differentiate between different log messages
      actingUser - can be set to null if unknown / not desired
      message - A message to log in the monitoring data
    • logEvent

      @Deprecated public static void logEvent(Object from, MonitoringEvent event, String message)
      Deprecated.
      Use Context.monitorEvent(Object, MonitoringEvent, String) Logs a message to the l2p system using the observers. Since this method will/should only be used in an L2pThread, the message will come from a service or a helper, so a SERVICE_MESSAGE is assumed. Then this message will not be monitored by the monitoring observer.
      Parameters:
      from - the calling class
      event - used to differentiate between different log messages
      message - A message to log in the monitoring data
    • logEvent

      @Deprecated public static void logEvent(Object from, MonitoringEvent event, String message, Agent serviceAgent, Agent actingUser)
      Deprecated.
      Use Context.monitorEvent(Object, MonitoringEvent, String, boolean) Writes a log message. The given event can be used to differentiate between different log messages. The serviceAgent and actingUser can be set to null if not known. Then this message will not be monitored by the monitoring observer.
      Parameters:
      from - the calling class
      event - used to differentiate between different log messages
      message - A message to log in the monitoring data
      serviceAgent - can be set to null if unknown / not desired
      actingUser - can be set to null if unknown / not desired
    • logEvent

      @Deprecated public static void logEvent(Node node, Object from, MonitoringEvent event, String message, Agent serviceAgent, Agent actingUser)
      Deprecated.
      Use Context.monitorEvent(Object, MonitoringEvent, String, boolean) Writes a log message. The given event can be used to differentiate between different log messages. The serviceAgent and actingUser can be set to null if not known. Then this message will not be monitored by the monitoring observer.
      Parameters:
      node - The node that should be noticed about this event
      from - the calling class
      event - used to differentiate between different log messages
      message - A message to log in the monitoring data
      serviceAgent - can be set to null if unknown / not desired
      actingUser - can be set to null if unknown / not desired
    • log

      public void log(MonitoringEvent event)
      Same as #log(MonitoringEvent, String) without any remarks, just logs the plain event.
      Parameters:
      event - A monitoring event to log
    • log

      public void log(MonitoringEvent event, String remarks)
      Same as #log(MonitoringEvent, String, String, String) with context main agent as default source agent.
      Parameters:
      event - A monitoring event to log
      remarks - Arbitrary data to log along with the event
    • log

      public void log(MonitoringEvent event, String sourceAgentId, String destinationAgentId, String remarks)
      Same as log(Long, MonitoringEvent, String, String, String, String, String) with current system timestamp and no source or destination node.
      Parameters:
      event - A monitoring event to log
      sourceAgentId - A source agent id for this monitoring event
      destinationAgentId - A destination agent id for this monitoring event
      remarks - Arbitrary data to log along with the event
    • log

      @Deprecated public void log(Long timestamp, MonitoringEvent event, String sourceNode, String sourceAgentId, String destinationNode, String destinationAgentId, String remarks)
      Deprecated.
      Use log(Long, MonitoringEvent, String, String, String, String, String) instead. The coupling between nodes and services is softened now.
      Description copied from interface: NodeObserver
      Each call represents one event to log by this observer. All parameters except the time stamp and the event may be null.
      Specified by:
      log in interface NodeObserver
      Parameters:
      timestamp - UNIX time stamp of the event
      event - the event to log
      sourceNode - a source (p2p) node of the event (e.g. message sender)
      sourceAgentId - a source (las2peer) agent of the event (e.g. message sender)
      destinationNode - a destination (p2p) node for the event (e.g. message receiver)
      destinationAgentId - a destination (las2peer) agent of the event (e.g. message receiver)
      remarks - (optional) additional remarks
    • getGlobalConsoleFormatter

      public static Formatter getGlobalConsoleFormatter()
      This method returns the default Formatter currently used to format log output for console.
      Returns:
      Returns the console formatter.
    • getGlobalLogfileFormatter

      public static Formatter getGlobalLogfileFormatter()
      This method returns the default Formatter currently used to format log output for log files.
      Returns:
      Returns the log file formatter.
    • getInstance

      public static L2pLogger getInstance(Class<?> cls) throws ClassCastException
      This method is used to retrieve a L2pLogger instance.
      Parameters:
      cls - Should be the class this instance is used with.
      Returns:
      Returns a L2pLogger instance for the given class.
      Throws:
      ClassCastException - If someone overloaded the loggers instance by adding some other logger implementation with the same name. In this case you may use Java native method by calling Logger.getLogger(String).
    • getInstance

      public static L2pLogger getInstance(String name) throws ClassCastException
      This method is used to retrieve a L2pLogger instance.
      Parameters:
      name - A name for the new logger instance. Should be the name of your current class by default. Like L2pLogger.class.getCanonicalName()
      Returns:
      Returns a L2pLogger instance for the given name.
      Throws:
      ClassCastException - If someone overloaded the loggers instance by adding some other logger implementation with the same name. In this case you may use Java native method by calling Logger.getLogger(String).