FlixelLogger
View sourceclass
org.flixelgdx.logging.FlixelLogger
Logger instance for Flixel that formats and outputs log messages to the console and optionally to a file. Console output respects the current FlixelLogMode; file output always uses a detailed format.
File logging is controlled per instance: use FlixelLogger.setLogsFolder(String) to set a custom logs folder (when running in an IDE the default is the project root; when running from a JAR it is the directory containing the JAR), FlixelLogger.setCanStoreLogs(boolean) and FlixelLogger.setMaxLogFiles(int) to configure file logging, then FlixelLogger.startFileLogging() to start and FlixelLogger.stopFileLogging() to shut down the log writer thread.
Constructors
FlixelLogger(FlixelLogMode)
Creates a logger that outputs to the console and optionally to a file (when Flixel.logFileHandler is assigned).
Parameters:
| Name | Description |
|---|---|
logMode | The mode used for console output formatting. |
Fields
MAX_LOG_ENTRIES
Maximum number of lines the in-game debug console keeps. The overlay trims older lines when this is exceeded.
Methods
getLogMode()
Returns the current log mode used for console output formatting.
Returns: The active log mode, never null.
setLogMode(FlixelLogMode)
Sets the log mode used for console output formatting. If null is passed, the mode defaults to FlixelLogMode.SIMPLE.
Parameters:
| Name | Description |
|---|---|
logMode | The desired log mode, or null to reset to the default simple mode. |
getStackTraceProvider()
Returns the stack trace provider used to determine the caller location when logging messages.
Returns: The current stack trace provider, or null if none has been set.
setStackTraceProvider(FlixelStackTraceProvider)
Sets the stack trace provider used to resolve the calling class and method name for each log message.
Parameters:
| Name | Description |
|---|---|
stackTraceProvider | The provider to use for stack trace resolution. |
setLogsFolder(String)
Sets a custom folder where log files will be stored. Pass an absolute path to the folder that should contain the log files (e.g. /path/to/game/logs). If not set, the default is used: when running in an IDE, the project root's logs folder; when running from a JAR, the logs folder next to the JAR.
Parameters:
| Name | Description |
|---|---|
absolutePathToLogsFolder | The absolute path to the logs folder, or null to use the default. |
getLogsFolder()
canStoreLogs()
setCanStoreLogs(boolean)
getMaxLogFiles()
setMaxLogFiles(int)
startFileLogging()
Starts file logging by delegating to the registered FlixelLogFileHandler. If no handler has been registered (for example, on web/TeaVM) or if FlixelLogger.canStoreLogs() returns false, this method is a no-op.
The handler creates the log folder, prunes old files, opens a new timestamped log file, and (on JVM) starts a background writer thread.
stopFileLogging()
Stops file logging by delegating to the registered FlixelLogFileHandler. The handler flushes any buffered log lines and releases its resources.
Call this during game shutdown (for example from FlixelGame.dispose()) so that logs written during disposal are persisted.
addLogListener(Consumer<FlixelLogEntry>)
Registers a listener that will be notified every time a log message is produced.
Parameters:
| Name | Description |
|---|---|
listener | A consumer that receives a FlixelLogEntry. |
removeLogListener(Consumer<FlixelLogEntry>)
Removes a previously registered log listener.
Parameters:
| Name | Description |
|---|---|
listener | The listener to remove. |
debug(Object)
Logs a debug message using the default tag.
Parameters:
| Name | Description |
|---|---|
message | The message to log (converted via toString()). |
debug(String, Object)
Logs a debug message under a custom tag.
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The message to log (converted via toString()). |
debug(String, Object, Object...)
Logs a debug message under a custom tag, replacing each {} placeholder with the corresponding argument in order.
For example: Flixel.log.debug("Enemy", "there are {} enemies left", enemyCount). If there are fewer arguments than placeholders, the remaining {} tokens are left as-is.
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The format string, where each {} is replaced by the next argument. |
args | The arguments to substitute into the message. |
debugWithSite(Object, String, int, String, String)
Logs a debug message using the default tag with an explicit call site.
Typically invoked by the flixelgdx-logging-plugin bytecode weaver so file and line do not rely on FlixelStackTraceProvider (for example on TeaVM). You don't need to (nor should you) touch this method; you should use the other methods, such as FlixelLogger.debug(Object).
Parameters:
| Name | Description |
|---|---|
message | The message to log (converted via toString()). |
sourceFileName | The JVM source file name at the call site (for example MyState.java). |
lineNumber | The source line number from debug metadata, or 0 if unknown. |
declaringClassName | The fully qualified name of the class containing the call site. |
declaringMethodName | The simple name of the method containing the call site (no suffix). |
debugWithSite(String, Object, String, int, String, String)
Logs a debug message under a custom tag with an explicit call site.
Typically invoked by the flixelgdx-logging-plugin bytecode weaver so file and line do not rely on FlixelStackTraceProvider (for example on TeaVM). You don't need to (nor should you) touch this method; you should use the other methods, such as FlixelLogger.debug(Object).
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The message to log (converted via toString()). |
sourceFileName | The JVM source file name at the call site. |
lineNumber | The source line number from debug metadata, or 0 if unknown. |
declaringClassName | The fully qualified name of the class containing the call site. |
declaringMethodName | The simple name of the method containing the call site. |
info(Object)
Logs an informational message using the default tag.
Parameters:
| Name | Description |
|---|---|
message | The message to log (converted via toString()). |
info(String, Object)
Logs an informational message under a custom tag.
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The message to log (converted via toString()). |
info(String, Object, Object...)
Logs an informational message under a custom tag, replacing each {} placeholder with the corresponding argument in order.
For example: Flixel.log.info("Assets", "loaded {} assets in {}ms", count, elapsed). If there are fewer arguments than placeholders, the remaining {} tokens are left as-is.
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The format string, where each {} is replaced by the next argument. |
args | The arguments to substitute into the message. |
infoWithSite(Object, String, int, String, String)
Logs an informational message using the default tag with an explicit call site.
Typically invoked by the flixelgdx-logging-plugin bytecode weaver so file and line do not rely on FlixelStackTraceProvider (for example on TeaVM). You don't need to (nor should you) touch this method; you should use the other methods, such as FlixelLogger.info(Object).
Parameters:
| Name | Description |
|---|---|
message | The message to log (converted via toString()). |
sourceFileName | The JVM source file name at the call site (for example MyState.java). |
lineNumber | The source line number from debug metadata, or 0 if unknown. |
declaringClassName | The fully qualified name of the class containing the call site. |
declaringMethodName | The simple name of the method containing the call site (no suffix). |
infoWithSite(String, Object, String, int, String, String)
Logs an informational message under a custom tag with an explicit call site.
Typically invoked by the flixelgdx-logging-plugin bytecode weaver so file and line do not rely on FlixelStackTraceProvider (for example on TeaVM). You don't need to (nor should you) touch this method; you should use the other methods, such as FlixelLogger.info(Object).
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The message to log (converted via toString()). |
sourceFileName | The JVM source file name at the call site. |
lineNumber | The source line number from debug metadata, or 0 if unknown. |
declaringClassName | The fully qualified name of the class containing the call site. |
declaringMethodName | The simple name of the method containing the call site. |
warn(Object)
Logs a warning message using the default tag.
Parameters:
| Name | Description |
|---|---|
message | The message to log (converted via toString()). |
warn(String, Object)
Logs a warning message under a custom tag.
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The message to log (converted via toString()). |
warn(Object, Object...)
Logs a warning message using the default tag, replacing each {} placeholder with the corresponding argument in order.
For example: Flixel.log.warn("pool exhausted, {} objects dropped", dropped). If there are fewer arguments than placeholders, the remaining {} tokens are left as-is.
Parameters:
| Name | Description |
|---|---|
message | The format string, where each {} is replaced by the next argument. |
args | The arguments to substitute into the message. |
warn(String, Object, Object...)
Logs a warning message under a custom tag, replacing each {} placeholder with the corresponding argument in order.
For example: Flixel.log.warn("Pool", "pool exhausted, {} objects dropped", dropped). If there are fewer arguments than placeholders, the remaining {} tokens are left as-is.
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The format string, where each {} is replaced by the next argument. |
args | The arguments to substitute into the message. |
warnWithSite(Object, String, int, String, String)
Logs a warning message using the default tag with an explicit call site.
Typically invoked by the flixelgdx-logging-plugin bytecode weaver so file and line do not rely on FlixelStackTraceProvider (for example on TeaVM). You don't need to (nor should you) touch this method; you should use the other methods, such as FlixelLogger.warn(Object).
Parameters:
| Name | Description |
|---|---|
message | The message to log (converted via toString()). |
sourceFileName | The JVM source file name at the call site. |
lineNumber | The source line number from debug metadata, or 0 if unknown. |
declaringClassName | The fully qualified name of the class containing the call site. |
declaringMethodName | The simple name of the method containing the call site. |
warnWithSite(String, Object, String, int, String, String)
Logs a warning message under a custom tag with an explicit call site.
Typically invoked by the flixelgdx-logging-plugin bytecode weaver so file and line do not rely on FlixelStackTraceProvider (for example on TeaVM). You don't need to (nor should you) touch this method; you should use the other methods, such as FlixelLogger.warn(Object).
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The message to log (converted via toString()). |
sourceFileName | The JVM source file name at the call site. |
lineNumber | The source line number from debug metadata, or 0 if unknown. |
declaringClassName | The fully qualified name of the class containing the call site. |
declaringMethodName | The simple name of the method containing the call site. |
error(Object)
Logs an error message using the default tag with no throwable.
Parameters:
| Name | Description |
|---|---|
message | The message to log (converted via toString()). |
error(Object, Throwable)
Logs an error message using the default tag, including the throwable's string representation in the output.
Parameters:
| Name | Description |
|---|---|
message | The message to log (converted via toString()). |
throwable | The exception to append to the log output. |
error(String, Object)
Logs an error message under a custom tag with no throwable.
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The message to log (converted via toString()). |
error(String, Object, Throwable)
Logs an error message under a custom tag, optionally including a throwable in the output.
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The message to log (converted via toString()). |
throwable | The exception to append to the log output, or null if none. |
error(Object, Throwable, Object...)
Logs an error message using the default tag, replacing each {} placeholder with the corresponding argument in order, including the throwable's string representation.
For example: Flixel.log.error("failed to load {} assets", e, count). If there are fewer arguments than placeholders, the remaining {} tokens are left as-is.
Parameters:
| Name | Description |
|---|---|
message | The format string, where each {} is replaced by the next argument. |
throwable | The exception to append to the log output. |
args | The arguments to substitute into the message. |
error(String, Object, Object...)
Logs an error message under a custom tag, replacing each {} placeholder with the corresponding argument in order, with no throwable.
For example: Flixel.log.error("Assets", "failed to load {} of {} assets", failed, total). If there are fewer arguments than placeholders, the remaining {} tokens are left as-is.
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The format string, where each {} is replaced by the next argument. |
args | The arguments to substitute into the message. |
error(String, Object, Throwable, Object...)
Logs an error message under a custom tag, replacing each {} placeholder with the corresponding argument in order, including the throwable's string representation.
For example: Flixel.log.error("Assets", "failed to load {} assets", e, count). If there are fewer arguments than placeholders, the remaining {} tokens are left as-is.
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The format string, where each {} is replaced by the next argument. |
throwable | The exception to append to the log output, or null if none. |
args | The arguments to substitute into the message. |
errorWithSite(Object, String, int, String, String)
Logs an error message using the default tag with an explicit call site and no throwable.
Typically invoked by the flixelgdx-logging-plugin bytecode weaver so file and line do not rely on FlixelStackTraceProvider (for example on TeaVM). You don't need to (nor should you) touch this method; you should use the other methods, such as FlixelLogger.error(Object).
Parameters:
| Name | Description |
|---|---|
message | The message to log (converted via toString()). |
sourceFileName | The JVM source file name at the call site. |
lineNumber | The source line number from debug metadata, or 0 if unknown. |
declaringClassName | The fully qualified name of the class containing the call site. |
declaringMethodName | The simple name of the method containing the call site. |
errorWithSite(Object, Throwable, String, int, String, String)
Logs an error message using the default tag with an explicit call site.
Typically invoked by the flixelgdx-logging-plugin bytecode weaver so file and line do not rely on FlixelStackTraceProvider (for example on TeaVM). You don't need to (nor should you) touch this method; you should use the other methods, such as FlixelLogger.error(Object).
Parameters:
| Name | Description |
|---|---|
message | The message to log (converted via toString()). |
throwable | The exception to append to the log output, or null if none. |
sourceFileName | The JVM source file name at the call site. |
lineNumber | The source line number from debug metadata, or 0 if unknown. |
declaringClassName | The fully qualified name of the class containing the call site. |
declaringMethodName | The simple name of the method containing the call site. |
errorWithSite(String, Object, String, int, String, String)
Logs an error message under a custom tag with an explicit call site and no throwable.
Typically invoked by the flixelgdx-logging-plugin bytecode weaver so file and line do not rely on FlixelStackTraceProvider (for example on TeaVM). You don't need to (nor should you) touch this method; you should use the other methods, such as FlixelLogger.error(Object).
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The message to log (converted via toString()). |
sourceFileName | The JVM source file name at the call site. |
lineNumber | The source line number from debug metadata, or 0 if unknown. |
declaringClassName | The fully qualified name of the class containing the call site. |
declaringMethodName | The simple name of the method containing the call site. |
errorWithSite(String, Object, Throwable, String, int, String, String)
Logs an error message under a custom tag with an explicit call site.
Typically invoked by the flixelgdx-logging-plugin bytecode weaver so file and line do not rely on FlixelStackTraceProvider (for example on TeaVM). You don't need to (nor should you) touch this method; you should use the other methods, such as FlixelLogger.error(Object).
Parameters:
| Name | Description |
|---|---|
tag | The tag to associate with this log entry. |
message | The message to log (converted via toString()). |
throwable | The exception to append to the log output, or null if none. |
sourceFileName | The JVM source file name at the call site. |
lineNumber | The source line number from debug metadata, or 0 if unknown. |
declaringClassName | The fully qualified name of the class containing the call site. |
declaringMethodName | The simple name of the method containing the call site. |
outputLog(String, Object, FlixelLogLevel)
Formats and outputs a log message to the console (according to FlixelLogger.logMode) and, if a file line consumer is set, passes the detailed (plain) line for file output.
outputLog(String, String, FlixelLogLevel, boolean, String, int, String, String)
Writes a log line using either an explicit call site or FlixelLogger.getCaller() when explicitSite is false.
Parameters:
| Name | Description |
|---|---|
tag | The tag for this entry (may be null). |
rawMessage | The message text already evaluated with FlixelLogger.evaluateMessage(Object). |
level | The log level. |
explicitSite | When true, use the four trailing site parameters instead of stack walking. |
sourceFileName | Source file name when explicit; ignored when not explicit. |
lineNumber | Source line when explicit; ignored when not explicit. |
declaringClassName | Fully qualified class name when explicit; ignored when not explicit. |
declaringMethodName | Simple method name when explicit; ignored when not explicit. |
getCaller()
Gets the location of where a log was called from.
Returns: The location of where a log was called from.