Class GlobalLogger
-
Field Summary
Fields inherited from class java.util.logging.Logger
global, GLOBAL_LOGGER_NAME
-
Constructor Summary
ConstructorsConstructorDescriptionGlobalLogger
(String loggerName) GlobalLogger class is responsible for creating and configuring a global logger instance.GlobalLogger
(String loggerName, boolean debug, boolean writeLogsToFile) Initializes the GlobalLogger with the specified logger name, debug mode, and whether log files should be written. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull GlobalLogger
createNamedLogger
(String name) Creates a named logger.static @NotNull GlobalLogger
createNamedLogger
(String name, boolean debug, boolean writeLogsToFile) Creates a named logger instance or returns the existing global logger instance.void
Debug method.void
Destroys the logger, closing all handlers and cleaning up resources.void
Logs an error message.void
Logs a message at the FATAL level.static @NotNull GlobalLogger
Get the logger instance for BetterBanSystem.static @NotNull GlobalLogger
Retrieves the GlobalLogger instance with the provided name, creating it if it doesn't exist.void
Logs an informational message.void
Logs an informational message with the given message.boolean
isDebug()
Determines if the application is currently running in debug mode.void
Logs a message with the given log level and arguments.void
setDebug
(boolean debug) Sets the debug mode for the GlobalLogger.void
setWriteLogsToFile
(boolean writeLogsToFile) Sets the flag for writing logs to a file.void
Logs a trace-level message.void
Adds a log record of warning level to the logger.void
Logs a warning message.boolean
Determines whether to write log files.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, getName, getParent, getResourceBundle, getResourceBundleName, getUseParentHandlers, info, isLoggable, log, 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
-
Constructor Details
-
GlobalLogger
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
Initializes the GlobalLogger with the specified logger name, debug mode, and whether log files should be written.- Parameters:
loggerName
- the name of the loggerdebug
- whether debug mode is enabledwriteLogsToFile
- whether log files should be written
-
-
Method Details
-
getLogger
Get the logger instance for BetterBanSystem.- Returns:
- The GlobalLogger instance.
-
getLogger
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
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 loggerdebug
- a boolean indicating if debug mode is enabledwriteLogsToFile
- 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
Logs a message at the FATAL level.- Parameters:
args
- the objects to include in the log message
-
info
Logs an informational message.- Parameters:
args
- the message arguments
-
info
Logs an informational message with the given message. -
trace
Logs a trace-level message.- Parameters:
args
- the objects to be logged
-
debug
Debug method.- Parameters:
args
- The objects to be logged. Can be multiple.
-
error
Logs an error message.- Parameters:
args
- the error message arguments
-
warn
Adds a log record of warning level to the logger.- Parameters:
args
- the objects to be logged as warning messages
-
warning
Logs a warning message. -
log
Logs a message with the given log level and arguments.- Parameters:
level
- the log level to use, must not be nullargs
- 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, otherwisefalse
.
-
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.
-