SuperCache.Log (SuperCache v1.3.0)

Copy Markdown View Source

Conditional logging for SuperCache.

Debug output is suppressed by default. Enable in two ways:

Compile-time (evaluated at compile time, zero overhead when disabled):

# config/config.exs
config :super_cache, debug_log: true

Runtime (can be toggled while the system is running):

SuperCache.Log.enable(true)

All internal logging calls are routed through this module so that when debug is disabled, no message strings are built and no function calls are made — the macro expands to :ok.

Examples

require SuperCache.Log

# Lazy evaluation — only called when debug is enabled
SuperCache.Log.debug(fn -> "expensive: #{inspect(large_data)}" end)

# Direct string or iodata
SuperCache.Log.debug("simple message")
SuperCache.Log.info("operation completed")

Summary

Functions

Emit a debug log if debug logging is enabled.

Enable or disable debug logging at runtime.

Returns whether debug logging is currently enabled.

Emit an error log.

Emit an info log.

Emit a warning log.

Functions

debug(chardata_or_fun)

(macro)

Emit a debug log if debug logging is enabled.

Accepts a string, iodata, or a zero-arity anonymous function (lazy evaluation). When disabled, this macro expands to :ok so no work is performed.

Examples

require SuperCache.Log

SuperCache.Log.debug("starting operation")
SuperCache.Log.debug(fn -> "data: #{inspect(large_struct)}" end)

enable(enabled)

@spec enable(boolean()) :: :ok

Enable or disable debug logging at runtime.

This overrides the compile-time setting. Pass true to enable, false to disable.

Examples

SuperCache.Log.enable(true)
SuperCache.Log.enable(false)

enabled?()

@spec enabled?() :: boolean()

Returns whether debug logging is currently enabled.

Checks the runtime toggle first; if not set, falls back to the compile-time configuration.

error(chardata_or_fun)

(macro)

Emit an error log.

Always logs — not gated by the debug toggle.

Examples

SuperCache.Log.error("3PC commit failed: timeout")

info(chardata_or_fun)

(macro)

Emit an info log.

Unlike debug/1, this always logs (info is not gated by the debug toggle), but it still accepts lazy functions for consistency.

Examples

SuperCache.Log.info("cache started with 8 partitions")

warning(chardata_or_fun)

(macro)

Emit a warning log.

Always logs — not gated by the debug toggle.

Examples

SuperCache.Log.warning("node not reachable, will retry")