Class MMLogger
- All Implemented Interfaces:
Serializable,org.apache.logging.log4j.Logger,org.apache.logging.log4j.spi.ExtendedLogger,org.apache.logging.log4j.spi.LocationAwareLogger
Utility class to handle logging functions as well as reporting exceptions to Sentry. To deal with general recommendations of confirming log level before logging, additional checks are added to ensure we're only ever logging data based upon the currently active log level.
How to use:
To utilize this class properly, it must be initialized within each class that will use it. For example for use with
the megamek.MegaMek.class.
private static final MMLogger LOGGER = MMLogger.create(MegaMek.class);
And then for use, use LOGGER.info(message) and pass a string to it. Currently supported levels include trace,
info, warn, debug, error, and fatal. Warn, Error and Fatal can take any Throwable for sending to Sentry and has an
overload for a title to allow for displaying of a dialog box.
This class also implements both the parametric pattern and the string format for the functions that are overridden and added here. This means that you can use the following formats for the messages in some cases:
LOGGER.info("number: {} string: {}", 42, "Hello");
LOGGER.info("number: %d string: %s", 42, "Hello");
Due to how the LOGGER works, the first format using curly braces is preferred, but the second one is grandfathered exclusively for logs already existing, and it is not recommended for any new log.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAn extra button offered on error dialogs, installed by the user interface layer. -
Field Summary
Fields inherited from class org.apache.logging.log4j.spi.ExtendedLoggerWrapper
loggerFields inherited from class org.apache.logging.log4j.spi.AbstractLogger
CATCHING_MARKER, DEFAULT_FLOW_MESSAGE_FACTORY_CLASS, DEFAULT_MESSAGE_FACTORY_CLASS, ENTRY_MARKER, EXCEPTION_MARKER, EXIT_MARKER, FLOW_MARKER, name, THROWING_MARKER -
Method Summary
Modifier and TypeMethodDescriptionstatic MMLoggercreate()Returns a custom Logger with the name of the calling class.static MMLoggerReturns a custom Logger using the fully qualified name of the Class as the Logger name.static MMLoggerReturns a custom Logger using a specific string as the Logger name.voidDebug Level LoggingvoidDebug Level LoggingvoidError Level Logging w/o Exception.voidError Level Logging w/ Exception This one was made to make it easier to replace the Log4J CallsvoidError Level Logging w/ ExceptionvoidError Level Logging w/ ExceptionvoiderrorDialog(String title, String message, Object... args) Formatted Error Level Logging w/o Exception w/ Dialog.voiderrorDialog(Throwable exception, String message, String title, Object... args) Formatted Error Level Logging w/ Exception w/ Dialog.voidFatal Level Logging w/ Exception.voidfatalDialog(String message, String title) Fatal Level Logging w/o Exception w/ DialogvoidfatalDialog(Throwable exception, String message, String title) Fatal Level Logging w/ Exception w/ DialogvoidInfo Level Logging.booleanisLevelLessSpecificThan(org.apache.logging.log4j.Level checkedLevel) Takes the passed in Level and checks if the current log level is less specific than provided.booleanisLevelMoreSpecificThan(org.apache.logging.log4j.Level checkedLevel) Takes the passed in Level and checks if the current log level is more specific than provided.static voidsetErrorDialogButton(MMLogger.ErrorDialogButton errorDialogButton) Installs an extra button shown on every error dialog, typically one offering to report the problem.voidWarning Level LoggingvoidWarning Level LoggingMethods inherited from class org.apache.logging.log4j.spi.ExtendedLoggerWrapper
getLevel, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, logMessageMethods inherited from class org.apache.logging.log4j.spi.AbstractLogger
always, atDebug, atError, atFatal, atInfo, atLevel, atTrace, atWarn, catching, catching, catching, catchingMsg, checkMessageFactory, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, enter, enter, enter, enter, enter, entry, entry, entry, entryMsg, entryMsg, entryMsg, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, exit, exit, exit, exit, exitMsg, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, getFlowMessageFactory, getLogBuilder, getMessageFactory, getName, getRecursionDepth, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, isDebugEnabled, isDebugEnabled, isEnabled, isEnabled, isErrorEnabled, isErrorEnabled, isFatalEnabled, isFatalEnabled, isInfoEnabled, isInfoEnabled, isTraceEnabled, isTraceEnabled, isWarnEnabled, isWarnEnabled, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, printf, printf, requiresLocation, throwing, throwing, throwing, throwingMsg, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, traceEntry, traceEntry, traceEntry, traceEntry, traceEntry, traceExit, traceExit, traceExit, traceExit, traceExit, traceExit, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn
-
Method Details
-
create
Returns a custom Logger with the name of the calling class.- Returns:
- The custom Logger for the calling class.
-
create
Returns a custom Logger using the fully qualified name of the Class as the Logger name.- Parameters:
loggerName- The Class whose name should be used as the Logger name. If null it will default to the calling class.- Returns:
- The custom Logger.
-
create
Returns a custom Logger using a specific string as the Logger name.- Parameters:
loggerName- The name to be used as the Logger name. Cannot be null nor blank.- Returns:
- The custom Logger.
-
info
Info Level Logging.- Specified by:
infoin interfaceorg.apache.logging.log4j.Logger- Overrides:
infoin classorg.apache.logging.log4j.spi.AbstractLogger- Parameters:
message- Message to be sent to the log file.args- Variable list of arguments for the message
-
warn
Warning Level Logging- Specified by:
warnin interfaceorg.apache.logging.log4j.Logger- Overrides:
warnin classorg.apache.logging.log4j.spi.AbstractLogger- Parameters:
message- Message to be logged.args- Variable list of arguments for the message
-
warn
Warning Level Logging- Parameters:
exception- Exception to be logged.message- Message to be logged.args- Variable list of arguments for the message
-
debug
Debug Level Logging- Specified by:
debugin interfaceorg.apache.logging.log4j.Logger- Overrides:
debugin classorg.apache.logging.log4j.spi.AbstractLogger- Parameters:
message- Message to be logged.args- Variable list of arguments for the message
-
debug
Debug Level Logging- Parameters:
exception- Exception to be logged.message- Message to be logged.args- Variable list of arguments for the message
-
error
Error Level Logging w/ Exception- Parameters:
exception- Exception to be logged.message- Additional message.
-
error
Error Level Logging w/ Exception- Parameters:
exception- Exception to be logged.message- Additional message to be logged.args- Variable list of arguments for the message
-
error
Error Level Logging w/ Exception This one was made to make it easier to replace the Log4J Calls- Specified by:
errorin interfaceorg.apache.logging.log4j.Logger- Overrides:
errorin classorg.apache.logging.log4j.spi.AbstractLogger- Parameters:
message- Message to be logged.exception- Exception to be logged.
-
error
Error Level Logging w/o Exception.- Specified by:
errorin interfaceorg.apache.logging.log4j.Logger- Overrides:
errorin classorg.apache.logging.log4j.spi.AbstractLogger- Parameters:
message- Message to be logged.
-
errorDialog
Formatted Error Level Logging w/ Exception w/ Dialog.- Parameters:
exception- Exception to be logged.message- Message to write to the log file AND be displayed in the error pane.title- Title of the error message box.args- Variable list of arguments for the message.
-
errorDialog
Formatted Error Level Logging w/o Exception w/ Dialog.- Parameters:
title- Title of the error message box.message- Message to write to the log file AND be displayed in the error pane.args- Variable list of arguments for the message
-
setErrorDialogButton
Installs an extra button shown on every error dialog, typically one offering to report the problem.An error dialog is the moment a player is most likely to want to file a bug, so this lets the user interface put the reporting tools directly in front of them instead of expecting them to find a menu.
- Parameters:
errorDialogButton- the button to offer, ornullto show a plain OK dialog as before
-
fatal
Fatal Level Logging w/ Exception.- Parameters:
exception- Exception that was triggered. Probably uncaught.message- Message to report to the log file.
-
fatalDialog
Fatal Level Logging w/ Exception w/ Dialog- Parameters:
exception- Exception that was triggered. Probably uncaught.message- Message to report to the log file.title- Title of the error message box.
-
fatalDialog
Fatal Level Logging w/o Exception w/ Dialog- Parameters:
message- Message to report to the log file.title- Title of the error message box.
-
isLevelMoreSpecificThan
public boolean isLevelMoreSpecificThan(org.apache.logging.log4j.Level checkedLevel) Takes the passed in Level and checks if the current log level is more specific than provided. This is a helper method around the default LOGGER's method.- Parameters:
checkedLevel- Passed in Level to compare to.- Returns:
- True if the current log level is more specific than the passed in
-
isLevelLessSpecificThan
public boolean isLevelLessSpecificThan(org.apache.logging.log4j.Level checkedLevel) Takes the passed in Level and checks if the current log level is less specific than provided. This is a helper method around the default LOGGER's method.- Parameters:
checkedLevel- Passed in Level to compare to.- Returns:
- True if the current log level is less specific than the passed in
-