Skip to main content

Crate effectful_logger

Crate effectful_logger 

Source
Expand description

Injectable EffectLogger service for the effect system.

§Service/Tag pattern

Extract the logger from the environment once with bind* EffectLogger, then call its methods as regular effectful steps:

effect!(|_r: &mut R| {
    let logger = bind* EffectLogger;
    bind* logger.warn("something suspicious");
    bind* logger.info("all good");
    result
})

The environment R only needs to satisfy R: Get<EffectLogKey, Here, Target = EffectLogger>. The caller composes layers at the top of the program. For a minimal stack that only provides EffectLogger, build Context::new(Cons(layer_effect_logger().build().expect(\"…\"), Nil)) or Context::new(Cons(Service::<EffectLogKey, _>::new(EffectLogger), Nil)) at the program edge.

Log methods accept impl Into<Cow<'static, str>>: literals stay zero-copy; runtime text passes as String or format!(...).

Structs§

CompositeLogBackend
Thread-safe list of backends; also implements LogBackend by fan-out.
EffectLogKey
Tag for EffectLogger in an effectful::Context stack. Nominal service key (service_key!). Implements Equal and EffectHash through the standard derives—Brand-style structural equality for this ZST tag.
EffectLogMinLevelKey
Tag for the fiber-local minimum LogLevel used by EffectLogger::log. Nominal service key (service_key!). Implements Equal and EffectHash through the standard derives—Brand-style structural equality for this ZST tag.
EffectLogger
Log sink for use as effectful::Service<EffectLogKey, Self>; forwards to tracing.
JsonLogBackend
One JSON object per line (serde_json), for files or test buffers.
LogContext
Metadata attached to log lines (wall-clock UTC, etc.).
LogRecord
One log event passed to each backend in a CompositeLogBackend.
StructuredLogBackend
Human-oriented key=value lines (no JSON), still machine-grep-friendly.
TracingLogBackend
Forwards to the tracing crate (same levels as crate::EffectLogger legacy path).

Enums§

EffectLoggerError
Errors that a log sink may produce.
LogLevel
Logging level for EffectLogger.

Traits§

LogBackend
Sink for LogRecord values (tracing, JSON file, tests, etc.).
Logger
Effect.ts-style composable logger: Self::add, Self::replace, Self::remove.
NeedsEffectLogger
Supertrait alias for Get<EffectLogKey, Here, Target = EffectLogger>.

Functions§

annotate_logs
Run inner with key=value merged into the fiber-local annotation map (restored afterward).
layer_composite_logger
Layer: install a CompositeLogBackend on this thread so EffectLogger::log fans out to all registered LogBackends (see Logger::add, Logger::replace, Logger::remove).
layer_effect_logger
effectful::layer_service constructor for EffectLogger.
layer_log_metadata
Layer: allocate fiber-local annotation and span-stack FiberRefs used by annotate_logs and with_log_span.
layer_minimum_log_level
Layer that allocates a FiberRef<LogLevel> (default initial) and registers it in a thread-local slot consulted by EffectLogger::log.
with_log_span
Run inner while a span label is pushed on the fiber-local span stack (restored afterward).