java.lang.Object
java.util.logging.Logger
me.github.simonplays15.betterbansystem.core.logging.GlobalLogger

public class GlobalLogger extends Logger
The GlobalLogger class provides a global logger instance that can be used to log messages to the console or to log files. It extends the Logger class.
  • Constructor Details

    • GlobalLogger

      public GlobalLogger (String loggerName)
      GlobalLogger class is responsible for creating and configuring a global logger instance. It provides logging functionality at different log levels and supports logging to both console and file.

      Usage: GlobalLogger logger = new GlobalLogger(loggerName, debug, writeLogsToFile);

      Parameters: - loggerName: The name of the logger. - debug: Flag to enable/disable debug mode. Default is false. - writeLogsToFile: Flag to enable/disable writing logs to file. Default is false.

      Example usage: GlobalLogger logger = new GlobalLogger("MyLogger", true, true); logger.info("This is an information message"); logger.error("This is an error message");

      Note: The class inherits from java.util.logging.Logger class.

    • GlobalLogger

      public GlobalLogger (String loggerName, boolean debug, boolean writeLogsToFile)
      Initializes the GlobalLogger with the specified logger name, debug mode, and whether log files should be written.
      Parameters:
      loggerName - the name of the logger
      debug - whether debug mode is enabled
      writeLogsToFile - whether log files should be written
  • Method Details

    • getLogger

      @Contract(" -> new") @NotNull public static @NotNull GlobalLogger getLogger()
      Get the logger instance for BetterBanSystem.
      Returns:
      The GlobalLogger instance.
    • getLogger

      @Contract("_ -> new") @NotNull public static @NotNull GlobalLogger getLogger (String name)
      Retrieves the GlobalLogger instance with the provided name, creating it if it doesn't exist.
      Parameters:
      name - The name of the logger.
      Returns:
      The GlobalLogger instance.
    • createNamedLogger

      @Contract("_ -> new") @NotNull public static @NotNull GlobalLogger createNamedLogger (String name)
      Creates a named logger.
      Parameters:
      name - the name of the logger
      Returns:
      a new instance of GlobalLogger if an instance does not exist, otherwise returns the existing instance
    • createNamedLogger

      @Contract("_, _, _ -> new") @NotNull public static @NotNull GlobalLogger createNamedLogger (String name, boolean debug, boolean writeLogsToFile)
      Creates a named logger instance or returns the existing global logger instance.
      Parameters:
      name - the name of the logger
      debug - a boolean indicating if debug mode is enabled
      writeLogsToFile - a boolean indicating if logs should be written to a file
      Returns:
      the global logger instance
    • destroyLogger

      public void destroyLogger()
      Destroys the logger, closing all handlers and cleaning up resources.
    • fatal

      public void fatal (Object... args)
      Logs a message at the FATAL level.
      Parameters:
      args - the objects to include in the log message
    • info

      public void info (Object... args)
      Logs an informational message.
      Parameters:
      args - the message arguments
    • info

      public void info (String msg)
      Logs an informational message with the given message.
      Overrides:
      info in class Logger
      Parameters:
      msg - The message to log.
    • trace

      public void trace (Object... args)
      Logs a trace-level message.
      Parameters:
      args - the objects to be logged
    • debug

      public void debug (Object... args)
      Debug method.
      Parameters:
      args - The objects to be logged. Can be multiple.
    • error

      public void error (Object... args)
      Logs an error message.
      Parameters:
      args - the error message arguments
    • warn

      public void warn (Object... args)
      Adds a log record of warning level to the logger.
      Parameters:
      args - the objects to be logged as warning messages
    • warning

      public void warning (String string)
      Logs a warning message.
      Overrides:
      warning in class Logger
      Parameters:
      string - the warning message to be logged
    • log

      public void log (@NotNull @NotNull LogLevel level, Object @NotNull ... args)
      Logs a message with the given log level and arguments.
      Parameters:
      level - the log level to use, must not be null
      args - the arguments to log, must not be null
    • isDebug

      public boolean isDebug()
      Determines if the application is currently running in debug mode.
      Returns:
      true if the application is running in debug mode, false otherwise
    • setDebug

      public void setDebug (boolean debug)
      Sets the debug mode for the GlobalLogger.
      Parameters:
      debug - The boolean value indicating whether debug mode should be enabled or not.
    • writeLogFiles

      public boolean writeLogFiles()
      Determines whether to write log files.
      Returns:
      true if log files should be written, otherwise false.
    • setWriteLogsToFile

      public void setWriteLogsToFile (boolean writeLogsToFile)
      Sets the flag for writing logs to a file.
      Parameters:
      writeLogsToFile - if true, logs will be written to a file; if false, logs will not be written to a file.