Class Logger

java.lang.Object
java.util.logging.Logger
eu.cloudnetservice.common.log.Logger
Direct Known Subclasses:
FallbackPassthroughLogger

public abstract class Logger extends Logger
Represents the logger which is used withing CloudNet. This logger extends from the default java.util.logging logger but provides methods to easier log messages instead of needing to wrap them or use huge method calls.
Since:
4.0
  • Constructor Details

    • Logger

      protected Logger(@Nullable @Nullable String name, @Nullable @Nullable String resourceBundleName)
      Constructs a new logger instance.
      Parameters:
      name - the name of the logger, null for anonymous loggers.
      resourceBundleName - the resource bundle name used for localizing messages passed to the logger, can be null.
      Throws:
      MissingResourceException - if the resource bundle is given but no such bundle was found.
  • Method Details

    • forceLog

      public abstract void forceLog(@NonNull @NonNull LogRecord logRecord)
      Force logs the given record by directly flushing it to the underlying handlers. All other log methods will try to pass the messages to the log record dispatcher first which processes them delayed.
      Parameters:
      logRecord - the record to log instantly.
      Throws:
      NullPointerException - if the given record is null.
    • logRecordDispatcher

      @Nullable public abstract @Nullable LogRecordDispatcher logRecordDispatcher()
      Get the log record dispatcher used by this logger. This method returns null if no dispatcher is set, meaning that all log records which are created by this logger will be written to all handlers directly. If a dispatcher is present all records will be posted to the dispatcher which is responsible to process and post them to all registered handlers.
      Returns:
      the log record dispatcher used by this logger, null if no dispatcher is set.
    • logRecordDispatcher

      public abstract void logRecordDispatcher(@Nullable @Nullable LogRecordDispatcher dispatcher)
      Sets the log record dispatcher. If the given dispatcher is null all log records will be passed to the registered handlers directly, if the dispatcher is given it will be responsible to process the given records and pass them to all registered handlers.
      Parameters:
      dispatcher - the new dispatcher to use, null to remove the current log dispatcher.
    • fine

      public void fine(@NonNull @NonNull String message, @Nullable @Nullable Throwable throwable, Object @NonNull ... params)
      Logs the given message using the fine level. This method has no effect if the fine level is not enabled for this logger and will not try to format the given message.

      The message passed to this method must be in a valid formatter format to be formatted. If no arguments are given the message will just get printed out as-is.

      This method call is equivalent to logger.log(Level.FINE, message, throwable, params).

      Parameters:
      message - the message to print and format if parameters are given.
      throwable - the throwable associated with the current log event, can be null.
      params - the params to format the given message with.
      Throws:
      NullPointerException - if the given message or an element of the given params array is null.
      IllegalFormatException - if parameters are present but the given message uses an illegal format.
    • finer

      public void finer(@NonNull @NonNull String message, @Nullable @Nullable Throwable throwable, Object @NonNull ... params)
      Logs the given message using the finer level. This method has no effect if the fine level is not enabled for this logger and will not try to format the given message.

      The message passed to this method must be in a valid formatter format to be formatted. If no arguments are given the message will just get printed out as-is.

      This method call is equivalent to logger.log(Level.FINER, message, throwable, params).

      Parameters:
      message - the message to print and format if parameters are given.
      throwable - the throwable associated with the current log event, can be null.
      params - the params to format the given message with.
      Throws:
      NullPointerException - if the given message or an element of the given params array is null.
      IllegalFormatException - if parameters are present but the given message uses an illegal format.
    • finest

      public void finest(@NonNull @NonNull String message, @Nullable @Nullable Throwable throwable, Object @NonNull ... params)
      Logs the given message using the finest level. This method has no effect if the fine level is not enabled for this logger and will not try to format the given message.

      The message passed to this method must be in a valid formatter format to be formatted. If no arguments are given the message will just get printed out as-is.

      This method call is equivalent to logger.log(Level.FINEST, message, throwable, params).

      Parameters:
      message - the message to print and format if parameters are given.
      throwable - the throwable associated with the current log event, can be null.
      params - the params to format the given message with.
      Throws:
      NullPointerException - if the given message or an element of the given params array is null.
      IllegalFormatException - if parameters are present but the given message uses an illegal format.
    • severe

      public void severe(@NonNull @NonNull String message, @Nullable @Nullable Throwable throwable, Object @NonNull ... params)
      Logs the given message using the severe level. This method has no effect if the fine level is not enabled for this logger and will not try to format the given message.

      The message passed to this method must be in a valid formatter format to be formatted. If no arguments are given the message will just get printed out as-is.

      This method call is equivalent to logger.log(Level.SEVERE, message, throwable, params).

      Parameters:
      message - the message to print and format if parameters are given.
      throwable - the throwable associated with the current log event, can be null.
      params - the params to format the given message with.
      Throws:
      NullPointerException - if the given message or an element of the given params array is null.
      IllegalFormatException - if parameters are present but the given message uses an illegal format.
    • warning

      public void warning(@NonNull @NonNull String message, @Nullable @Nullable Throwable throwable, Object @NonNull ... params)
      Logs the given message using the warning level. This method has no effect if the fine level is not enabled for this logger and will not try to format the given message.

      The message passed to this method must be in a valid formatter format to be formatted. If no arguments are given the message will just get printed out as-is.

      This method call is equivalent to logger.log(Level.WARNING, message, throwable, params).

      Parameters:
      message - the message to print and format if parameters are given.
      throwable - the throwable associated with the current log event, can be null.
      params - the params to format the given message with.
      Throws:
      NullPointerException - if the given message or an element of the given params array is null.
      IllegalFormatException - if parameters are present but the given message uses an illegal format.
    • info

      public void info(@NonNull @NonNull String message, @Nullable @Nullable Throwable throwable, Object @NonNull ... params)
      Logs the given message using the info level. This method has no effect if the fine level is not enabled for this logger and will not try to format the given message.

      The message passed to this method must be in a valid formatter format to be formatted. If no arguments are given the message will just get printed out as-is.

      This method call is equivalent to logger.log(Level.INFO, message, throwable, params).

      Parameters:
      message - the message to print and format if parameters are given.
      throwable - the throwable associated with the current log event, can be null.
      params - the params to format the given message with.
      Throws:
      NullPointerException - if the given message or an element of the given params array is null.
      IllegalFormatException - if parameters are present but the given message uses an illegal format.
    • config

      public void config(@NonNull @NonNull String message, @Nullable @Nullable Throwable throwable, Object @NonNull ... params)
      Logs the given message using the config level. This method has no effect if the fine level is not enabled for this logger and will not try to format the given message.

      The message passed to this method must be in a valid formatter format to be formatted. If no arguments are given the message will just get printed out as-is.

      This method call is equivalent to logger.log(Level.CONFIG, message, throwable, params).

      Parameters:
      message - the message to print and format if parameters are given.
      throwable - the throwable associated with the current log event, can be null.
      params - the params to format the given message with.
      Throws:
      NullPointerException - if the given message or an element of the given params array is null.
      IllegalFormatException - if parameters are present but the given message uses an illegal format.
    • log

      public void log(@NonNull @NonNull Level level, @NonNull @NonNull String message, @Nullable @Nullable Throwable th, Object @NonNull ... params)
      Logs the given message using the provided level. This method has no effect if the fine level is not enabled for this logger and will not try to format the given message.

      The message passed to this method must be in a valid formatter format to be formatted. If no arguments are given the message will just get printed out as-is.

      Parameters:
      level - the level of the log record to log.
      message - the message to print and format if parameters are given.
      th - the throwable associated with the current log event, can be null.
      params - the params to format the given message with.
      Throws:
      NullPointerException - if the given level, message or an element of the params array is null.
      IllegalFormatException - if parameters are present but the given message uses an illegal format.