Logger

Entityceramic.Logger (Class)

Centralized logging system for Ceramic applications that provides colored, categorized output.

The Logger class extends Entity to provide event-based logging with different severity levels. It handles platform-specific output formatting (Unity, Web, Native) and thread-safe logging from background threads. All log messages can be observed through events for custom handling.

The logger supports five severity levels:

  • debug: Development and diagnostic information (magenta in Unity, [debug] prefix)
  • info: General informational messages (cyan in Unity, [info] prefix)
  • success: Success confirmations (lime in Unity, [success] prefix)
  • warning: Warning messages (yellow in Unity, uses console.warn on web)
  • error: Error messages (red in Unity, uses console.error on web)

Example usage:

// Basic logging (accessible via `log` in Ceramic project)
log.info("Game started");
log.debug("Player position: " + player.x + ", " + player.y);
log.warning("Low memory detected");
log.error("Failed to load save file");

// Hierarchical logging with indentation
log.info("Loading assets...");
log.pushIndent();
log.info("Loading textures...");
log.info("Loading sounds...");
log.popIndent();
log.success("Assets loaded!");

// Listen to log events
log.onInfo(this, (value, pos) -> {
    // Custom handling of info messages
    saveToLogFile(value, pos);
});

Compile-time flags:

  • ceramic_mute_logs: Disables all console output (events still fire)
  • ceramic_no_log: Completely removes logging code (no output, no events)
  • ceramic_unity_no_log: Disables Unity-specific console output

Instance Members

debug(value: Dynamic, ?pos: Null<haxe.PosInfos>): Void

Logs a debug message with magenta/[debug] formatting.

Debug messages are intended for development and diagnostic information that helps understand program flow and state during development. These messages are typically filtered out in production builds.

Thread-safe: Can be called from background threads.

Name Type Default Description
value Dynamic The value to log (will be converted to string)
pos Null<haxe.PosInfos> (optional) Source position information (automatically provided)

info(value: Dynamic, ?pos: Null<haxe.PosInfos>): Void

Logs an informational message with cyan/[info] formatting.

Info messages communicate general application state and progress. Use for non-critical information that helps understand what the application is doing during normal operation.

Thread-safe: Can be called from background threads.

Name Type Default Description
value Dynamic The value to log (will be converted to string)
pos Null<haxe.PosInfos> (optional) Source position information (automatically provided)

success(value: Dynamic, ?pos: Null<haxe.PosInfos>): Void

Logs a success message with lime/[success] formatting.

Success messages indicate successful completion of operations. Use to confirm that important actions completed without errors, such as asset loading, save operations, or network requests.

Thread-safe: Can be called from background threads.

Name Type Default Description
value Dynamic The value to log (will be converted to string)
pos Null<haxe.PosInfos> (optional) Source position information (automatically provided)

warning(value: Dynamic, ?pos: Null<haxe.PosInfos>): Void

Logs a warning message with yellow/[warning] formatting.

Warning messages indicate potential issues that don't prevent operation but may cause problems. Uses native console.warn() on web platforms for proper browser dev tools integration.

Thread-safe: Can be called from background threads.

Name Type Default Description
value Dynamic The value to log (will be converted to string)
pos Null<haxe.PosInfos> (optional) Source position information (automatically provided)

error(value: Dynamic, ?pos: Null<haxe.PosInfos>): Void

Logs an error message with red/[error] formatting.

Error messages indicate failures that may affect application behavior. Uses native console.error() on web platforms for proper browser dev tools integration with stack traces.

Thread-safe: Can be called from background threads.

Name Type Default Description
value Dynamic The value to log (will be converted to string)
pos Null<haxe.PosInfos> (optional) Source position information (automatically provided)

pushIndent(): Void

Increases the indentation level for subsequent log messages.

Each call adds 4 spaces to the beginning of log messages, creating a visual hierarchy in the output. Useful for logging nested operations or sub-tasks.

Must be balanced with popIndent() calls.

Example:

logger.info("Processing items...");
logger.pushIndent();
for (item in items) {
    logger.info("Processing: " + item.name);
}
logger.popIndent();
logger.success("Done!");

popIndent(): Void

Decreases the indentation level for subsequent log messages.

Removes 4 spaces from the indentation prefix. Should be called to balance each pushIndent() call.

See: pushIndent

new(): Void

Creates a new Logger instance. Configures platform-specific trace handlers on first initialization.

Private Members

didInitOnce: Bool

indentPrefix: String

Current indentation prefix for hierarchical logging. Each level adds 4 spaces to create visual hierarchy in log output.


emitInfo(value: Dynamic, ?pos: Null<haxe.PosInfos>): Void

Emitted when an info message is logged.

Name Type Default Description
value Dynamic The logged value (converted to string for display)
pos Null<haxe.PosInfos> (optional) Source code position information

emitDebug(value: Dynamic, ?pos: Null<haxe.PosInfos>): Void

Emitted when a debug message is logged.

Name Type Default Description
value Dynamic The logged value (converted to string for display)
pos Null<haxe.PosInfos> (optional) Source code position information

emitSuccess(value: Dynamic, ?pos: Null<haxe.PosInfos>): Void

Emitted when a success message is logged.

Name Type Default Description
value Dynamic The logged value (converted to string for display)
pos Null<haxe.PosInfos> (optional) Source code position information

emitWarning(value: Dynamic, ?pos: Null<haxe.PosInfos>): Void

Emitted when a warning message is logged.

Name Type Default Description
value Dynamic The logged value (converted to string for display)
pos Null<haxe.PosInfos> (optional) Source code position information

emitError(value: Dynamic, ?pos: Null<haxe.PosInfos>): Void

Emitted when an error message is logged.

Name Type Default Description
value Dynamic The logged value (converted to string for display)
pos Null<haxe.PosInfos> (optional) Source code position information

prefixLines(prefix: String, input: Dynamic): String

Adds prefix and indentation to each line of the input. Used internally to format multi-line log messages with proper category prefixes and indentation.

Name Type Description
prefix String The category prefix like "[info] "
input Dynamic The value to format (converted to string)
Returns Description
String The formatted string with prefix on each line

Metadata

Name Parameters
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()
:allow ceramic.App