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§
- Composite
LogBackend - Thread-safe list of backends; also implements
LogBackendby fan-out. - Effect
LogKey - Tag for
EffectLoggerin aneffectful::Contextstack. Nominal service key (service_key!). ImplementsEqualandEffectHashthrough the standard derives—Brand-style structural equality for this ZST tag. - Effect
LogMin Level Key - Tag for the fiber-local minimum
LogLevelused byEffectLogger::log. Nominal service key (service_key!). ImplementsEqualandEffectHashthrough the standard derives—Brand-style structural equality for this ZST tag. - Effect
Logger - Log sink for use as
effectful::Service<EffectLogKey, Self>; forwards totracing. - Json
LogBackend - 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. - Structured
LogBackend - Human-oriented
key=valuelines (no JSON), still machine-grep-friendly. - Tracing
LogBackend - Forwards to the
tracingcrate (same levels ascrate::EffectLoggerlegacy path).
Enums§
- Effect
Logger Error - Errors that a log sink may produce.
- LogLevel
- Logging level for
EffectLogger.
Traits§
- LogBackend
- Sink for
LogRecordvalues (tracing, JSON file, tests, etc.). - Logger
- Effect.ts-style composable logger:
Self::add,Self::replace,Self::remove. - Needs
Effect Logger - Supertrait alias for
Get<EffectLogKey, Here, Target = EffectLogger>.
Functions§
- annotate_
logs - Run
innerwithkey=valuemerged into the fiber-local annotation map (restored afterward). - layer_
composite_ logger - Layer: install a
CompositeLogBackendon this thread soEffectLogger::logfans out to all registeredLogBackends (seeLogger::add,Logger::replace,Logger::remove). - layer_
effect_ logger effectful::layer_serviceconstructor forEffectLogger.- layer_
log_ metadata - Layer: allocate fiber-local annotation and span-stack
FiberRefs used byannotate_logsandwith_log_span. - layer_
minimum_ log_ level - Layer that allocates a
FiberRef<LogLevel>(defaultinitial) and registers it in a thread-local slot consulted byEffectLogger::log. - with_
log_ span - Run
innerwhile a span label is pushed on the fiber-local span stack (restored afterward).