Common Types
ComponentLogging.ComponentLogging
— ModuleComponentLogging
Component-scoped logging utilities for Julia built on top of Logging
. This package provides:
- A
ComponentLogger
with hierarchical rule keys to control log levels per component path, e.g.(:net, :http)
. - Lightweight functions
clog
,clogenabled
,clogf
for emitting messages and checking if logging is enabled. - Macros
@clog
,@clogf
,@clogenabled
that capture the caller module/source location for accurate provenance. - A simple
PlainLogger
sink for pretty, colored output without timestamps/prefixes.
Typical usage:
using ComponentLogging
rules = Dict(
:core => Info,
:io => Warn,
:net => Debug
)
clogger = ComponentLogger(rules; sink=PlainLogger())
clog(clogger, :core, Info, "something happened")
ComponentLogging.ComponentLogger
— TypeComponentLogger(; sink=ConsoleLogger(Debug))
ComponentLogger(rules::AbstractDict; sink=ConsoleLogger(Debug))
A logger that delegates to an underlying sink (AbstractLogger
) while applying component-based minimum level rules. Rules are defined on paths of symbols (NTuple{N,Symbol}
). A lookup walks up the path and falls back to (:__default__,)
.
sink
: the underlyingAbstractLogger
that actually handles messages.rules
: mapping fromNTuple{N,Symbol}
toLogLevel
. The default entry((DEFAULT_SYM,), Info)
is created automatically when needed.
The effective minimum level is the minimum of all values in rules
, cached in the min
field for fast checks.
ComponentLogging.PlainLogger
— TypePlainLogger(stream::IO, min_level::LogLevel=Info)
PlainLogger(min_level::LogLevel=Info)
A simple AbstractLogger
implementation that prints messages without standard prefixes/timestamps, with minimal coloring by level.
stream
: target stream; if closed, falls back tostderr
.min_level
: minimum enabled level for the sink.
Intended for tests, demos, or embedding in custom sinks.
ComponentLogging.set_log_level!
— Functionset_log_level!(logger, group, lvl) -> ComponentLogger
Set or update the minimum level for a specific component group
on logger
. group
may be a Symbol
or a NTuple{N,Symbol}
tuple; lvl
can be LogLevel
or Integer
. Updates the internal min
cache appropriately.
ComponentLogging.with_min_level
— Functionwith_min_level(f, logger, lvl)
Temporarily set logger.min
to lvl
while executing f()
, restoring the original value afterward even if an exception is thrown.