Supertester.LoggerIsolation (Supertester v0.6.0)

Copy Markdown View Source

Per-process Logger level isolation utilities for async-safe testing.

Summary

Functions

Capture logs with automatic level isolation.

Capture logs with automatic level isolation and return only the log.

Get the current process isolated level.

Set the Logger level for the current process only.

Check if logger isolation is active.

Restore the process Logger level to its original state.

Initialize logger isolation for the current process.

Initialize logger isolation and update the isolation context.

Execute a function with a temporary Logger level.

Execute a function with a temporary Logger level and capture logs.

Types

capture_opts()

@type capture_opts() :: [
  level: level(),
  colors: boolean(),
  format: String.t(),
  metadata: [atom()]
]

isolate_opts()

@type isolate_opts() :: [{:cleanup, boolean()}]

level()

@type level() ::
  :emergency | :alert | :critical | :error | :warning | :notice | :info | :debug

level_or_all()

@type level_or_all() :: level() | :all | :none

Functions

capture_isolated(level, fun, opts \\ [])

@spec capture_isolated(level_or_all(), (-> term()), capture_opts()) ::
  {String.t(), term()}

Capture logs with automatic level isolation.

capture_isolated!(level, fun, opts \\ [])

@spec capture_isolated!(level_or_all(), (-> term()), capture_opts()) :: String.t()

Capture logs with automatic level isolation and return only the log.

get_isolated_level()

@spec get_isolated_level() :: level() | nil

Get the current process isolated level.

isolate_level(level, opts \\ [])

@spec isolate_level(level_or_all(), isolate_opts()) :: :ok

Set the Logger level for the current process only.

isolated?()

@spec isolated?() :: boolean()

Check if logger isolation is active.

restore_level()

@spec restore_level() :: :ok

Restore the process Logger level to its original state.

setup_logger_isolation()

@spec setup_logger_isolation() :: :ok

Initialize logger isolation for the current process.

setup_logger_isolation(ctx)

@spec setup_logger_isolation(Supertester.IsolationContext.t()) ::
  {:ok, Supertester.IsolationContext.t()}

Initialize logger isolation and update the isolation context.

with_level(level, fun)

@spec with_level(level_or_all(), (-> result)) :: result when result: term()

Execute a function with a temporary Logger level.

with_level_and_capture(level, fun)

@spec with_level_and_capture(level_or_all(), (-> result)) :: {String.t(), result}
when result: term()

Execute a function with a temporary Logger level and capture logs.