Skip to main content

FlixelLogger

View source

class

org.flixelgdx.logging.FlixelLogger

public class FlixelLogger implements ApplicationLogger

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)

public FlixelLogger(FlixelLogMode logMode)

Creates a logger that outputs to the console and optionally to a file (when Flixel.logFileHandler is assigned).

Parameters:

NameDescription
logModeThe mode used for console output formatting.

Fields

MAX_LOG_ENTRIES

public static final int MAX_LOG_ENTRIES = 200

Maximum number of lines the in-game debug console keeps. The overlay trims older lines when this is exceeded.


Methods

getLogMode()

public FlixelLogMode getLogMode()

Returns the current log mode used for console output formatting.

Returns: The active log mode, never null.


setLogMode(FlixelLogMode)

public void setLogMode(FlixelLogMode logMode)

Sets the log mode used for console output formatting. If null is passed, the mode defaults to FlixelLogMode.SIMPLE.

Parameters:

NameDescription
logModeThe desired log mode, or null to reset to the default simple mode.

getStackTraceProvider()

public FlixelStackTraceProvider 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)

public void setStackTraceProvider(FlixelStackTraceProvider stackTraceProvider)

Sets the stack trace provider used to resolve the calling class and method name for each log message.

Parameters:

NameDescription
stackTraceProviderThe provider to use for stack trace resolution.

setLogsFolder(String)

public void setLogsFolder(String absolutePathToLogsFolder)

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:

NameDescription
absolutePathToLogsFolderThe absolute path to the logs folder, or null to use the default.

getLogsFolder()

public String getLogsFolder()

canStoreLogs()

public boolean canStoreLogs()

setCanStoreLogs(boolean)

public void setCanStoreLogs(boolean canStoreLogs)

getMaxLogFiles()

public int getMaxLogFiles()

setMaxLogFiles(int)

public void setMaxLogFiles(int maxLogFiles)

startFileLogging()

public void 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()

public void 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>)

public void addLogListener(Consumer<FlixelLogEntry> listener)

Registers a listener that will be notified every time a log message is produced.

Parameters:

NameDescription
listenerA consumer that receives a FlixelLogEntry.

removeLogListener(Consumer<FlixelLogEntry>)

public void removeLogListener(Consumer<FlixelLogEntry> listener)

Removes a previously registered log listener.

Parameters:

NameDescription
listenerThe listener to remove.

debug(Object)

public void debug(Object message)

Logs a debug message using the default tag.

Parameters:

NameDescription
messageThe message to log (converted via toString()).

debug(String, Object)

public void debug(String tag, Object message)

Logs a debug message under a custom tag.

Parameters:

NameDescription
tagThe tag to associate with this log entry.
messageThe message to log (converted via toString()).

debug(String, Object, Object...)

public void debug(String tag, Object message, Object... args)

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:

NameDescription
tagThe tag to associate with this log entry.
messageThe format string, where each {} is replaced by the next argument.
argsThe arguments to substitute into the message.

debugWithSite(Object, String, int, String, String)

public void debugWithSite(Object message, String sourceFileName, int lineNumber, String declaringClassName, String declaringMethodName)

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:

NameDescription
messageThe message to log (converted via toString()).
sourceFileNameThe JVM source file name at the call site (for example MyState.java).
lineNumberThe source line number from debug metadata, or 0 if unknown.
declaringClassNameThe fully qualified name of the class containing the call site.
declaringMethodNameThe simple name of the method containing the call site (no suffix).

debugWithSite(String, Object, String, int, String, String)

public void debugWithSite(String tag, Object message, String sourceFileName, int lineNumber, String declaringClassName, String declaringMethodName)

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:

NameDescription
tagThe tag to associate with this log entry.
messageThe message to log (converted via toString()).
sourceFileNameThe JVM source file name at the call site.
lineNumberThe source line number from debug metadata, or 0 if unknown.
declaringClassNameThe fully qualified name of the class containing the call site.
declaringMethodNameThe simple name of the method containing the call site.

info(Object)

public void info(Object message)

Logs an informational message using the default tag.

Parameters:

NameDescription
messageThe message to log (converted via toString()).

info(String, Object)

public void info(String tag, Object message)

Logs an informational message under a custom tag.

Parameters:

NameDescription
tagThe tag to associate with this log entry.
messageThe message to log (converted via toString()).

info(String, Object, Object...)

public void info(String tag, Object message, Object... args)

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:

NameDescription
tagThe tag to associate with this log entry.
messageThe format string, where each {} is replaced by the next argument.
argsThe arguments to substitute into the message.

infoWithSite(Object, String, int, String, String)

public void infoWithSite(Object message, String sourceFileName, int lineNumber, String declaringClassName, String declaringMethodName)

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:

NameDescription
messageThe message to log (converted via toString()).
sourceFileNameThe JVM source file name at the call site (for example MyState.java).
lineNumberThe source line number from debug metadata, or 0 if unknown.
declaringClassNameThe fully qualified name of the class containing the call site.
declaringMethodNameThe simple name of the method containing the call site (no suffix).

infoWithSite(String, Object, String, int, String, String)

public void infoWithSite(String tag, Object message, String sourceFileName, int lineNumber, String declaringClassName, String declaringMethodName)

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:

NameDescription
tagThe tag to associate with this log entry.
messageThe message to log (converted via toString()).
sourceFileNameThe JVM source file name at the call site.
lineNumberThe source line number from debug metadata, or 0 if unknown.
declaringClassNameThe fully qualified name of the class containing the call site.
declaringMethodNameThe simple name of the method containing the call site.

warn(Object)

public void warn(Object message)

Logs a warning message using the default tag.

Parameters:

NameDescription
messageThe message to log (converted via toString()).

warn(String, Object)

public void warn(String tag, Object message)

Logs a warning message under a custom tag.

Parameters:

NameDescription
tagThe tag to associate with this log entry.
messageThe message to log (converted via toString()).

warn(Object, Object...)

public void warn(Object message, Object... args)

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:

NameDescription
messageThe format string, where each {} is replaced by the next argument.
argsThe arguments to substitute into the message.

warn(String, Object, Object...)

public void warn(String tag, Object message, Object... args)

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:

NameDescription
tagThe tag to associate with this log entry.
messageThe format string, where each {} is replaced by the next argument.
argsThe arguments to substitute into the message.

warnWithSite(Object, String, int, String, String)

public void warnWithSite(Object message, String sourceFileName, int lineNumber, String declaringClassName, String declaringMethodName)

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:

NameDescription
messageThe message to log (converted via toString()).
sourceFileNameThe JVM source file name at the call site.
lineNumberThe source line number from debug metadata, or 0 if unknown.
declaringClassNameThe fully qualified name of the class containing the call site.
declaringMethodNameThe simple name of the method containing the call site.

warnWithSite(String, Object, String, int, String, String)

public void warnWithSite(String tag, Object message, String sourceFileName, int lineNumber, String declaringClassName, String declaringMethodName)

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:

NameDescription
tagThe tag to associate with this log entry.
messageThe message to log (converted via toString()).
sourceFileNameThe JVM source file name at the call site.
lineNumberThe source line number from debug metadata, or 0 if unknown.
declaringClassNameThe fully qualified name of the class containing the call site.
declaringMethodNameThe simple name of the method containing the call site.

error(Object)

public void error(Object message)

Logs an error message using the default tag with no throwable.

Parameters:

NameDescription
messageThe message to log (converted via toString()).

error(Object, Throwable)

public void error(Object message, Throwable throwable)

Logs an error message using the default tag, including the throwable's string representation in the output.

Parameters:

NameDescription
messageThe message to log (converted via toString()).
throwableThe exception to append to the log output.

error(String, Object)

public void error(String tag, Object message)

Logs an error message under a custom tag with no throwable.

Parameters:

NameDescription
tagThe tag to associate with this log entry.
messageThe message to log (converted via toString()).

error(String, Object, Throwable)

public void error(String tag, Object message, Throwable throwable)

Logs an error message under a custom tag, optionally including a throwable in the output.

Parameters:

NameDescription
tagThe tag to associate with this log entry.
messageThe message to log (converted via toString()).
throwableThe exception to append to the log output, or null if none.

error(Object, Throwable, Object...)

public void error(Object message, Throwable throwable, Object... args)

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:

NameDescription
messageThe format string, where each {} is replaced by the next argument.
throwableThe exception to append to the log output.
argsThe arguments to substitute into the message.

error(String, Object, Object...)

public void error(String tag, Object message, Object... args)

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:

NameDescription
tagThe tag to associate with this log entry.
messageThe format string, where each {} is replaced by the next argument.
argsThe arguments to substitute into the message.

error(String, Object, Throwable, Object...)

public void error(String tag, Object message, Throwable throwable, Object... args)

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:

NameDescription
tagThe tag to associate with this log entry.
messageThe format string, where each {} is replaced by the next argument.
throwableThe exception to append to the log output, or null if none.
argsThe arguments to substitute into the message.

errorWithSite(Object, String, int, String, String)

public void errorWithSite(Object message, String sourceFileName, int lineNumber, String declaringClassName, String declaringMethodName)

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:

NameDescription
messageThe message to log (converted via toString()).
sourceFileNameThe JVM source file name at the call site.
lineNumberThe source line number from debug metadata, or 0 if unknown.
declaringClassNameThe fully qualified name of the class containing the call site.
declaringMethodNameThe simple name of the method containing the call site.

errorWithSite(Object, Throwable, String, int, String, String)

public void errorWithSite(Object message, Throwable throwable, String sourceFileName, int lineNumber, String declaringClassName, String declaringMethodName)

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:

NameDescription
messageThe message to log (converted via toString()).
throwableThe exception to append to the log output, or null if none.
sourceFileNameThe JVM source file name at the call site.
lineNumberThe source line number from debug metadata, or 0 if unknown.
declaringClassNameThe fully qualified name of the class containing the call site.
declaringMethodNameThe simple name of the method containing the call site.

errorWithSite(String, Object, String, int, String, String)

public void errorWithSite(String tag, Object message, String sourceFileName, int lineNumber, String declaringClassName, String declaringMethodName)

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:

NameDescription
tagThe tag to associate with this log entry.
messageThe message to log (converted via toString()).
sourceFileNameThe JVM source file name at the call site.
lineNumberThe source line number from debug metadata, or 0 if unknown.
declaringClassNameThe fully qualified name of the class containing the call site.
declaringMethodNameThe simple name of the method containing the call site.

errorWithSite(String, Object, Throwable, String, int, String, String)

public void errorWithSite(String tag, Object message, Throwable throwable, String sourceFileName, int lineNumber, String declaringClassName, String declaringMethodName)

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:

NameDescription
tagThe tag to associate with this log entry.
messageThe message to log (converted via toString()).
throwableThe exception to append to the log output, or null if none.
sourceFileNameThe JVM source file name at the call site.
lineNumberThe source line number from debug metadata, or 0 if unknown.
declaringClassNameThe fully qualified name of the class containing the call site.
declaringMethodNameThe simple name of the method containing the call site.

outputLog(String, Object, FlixelLogLevel)

protected void outputLog(String tag, Object message, FlixelLogLevel level)

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)

protected void outputLog(String tag, String rawMessage, FlixelLogLevel level, boolean explicitSite, String sourceFileName, int lineNumber, String declaringClassName, String declaringMethodName)

Writes a log line using either an explicit call site or FlixelLogger.getCaller() when explicitSite is false.

Parameters:

NameDescription
tagThe tag for this entry (may be null).
rawMessageThe message text already evaluated with FlixelLogger.evaluateMessage(Object).
levelThe log level.
explicitSiteWhen true, use the four trailing site parameters instead of stack walking.
sourceFileNameSource file name when explicit; ignored when not explicit.
lineNumberSource line when explicit; ignored when not explicit.
declaringClassNameFully qualified class name when explicit; ignored when not explicit.
declaringMethodNameSimple method name when explicit; ignored when not explicit.

getCaller()

protected FlixelStackFrame getCaller()

Gets the location of where a log was called from.

Returns: The location of where a log was called from.


getDefaultTag()

public String getDefaultTag()

setDefaultTag(String)

public void setDefaultTag(String defaultTag)

log(String, String)

public void log(String tag, String message)

log(String, String, Throwable)

public void log(String tag, String message, Throwable exception)

error(String, String)

public void error(String tag, String message)

error(String, String, Throwable)

public void error(String tag, String message, Throwable exception)

debug(String, String)

public void debug(String tag, String message)

debug(String, String, Throwable)

public void debug(String tag, String message, Throwable exception)