Function API
This page documents the function-first logging APIs exported by ComponentLogging
. All functions require the logger to be passed explicitly as the first argument. In application code you will typically define forwarding helpers to avoid threading the logger manually.
The function APIs do not automatically pass the current module, file, or line information; you need to provide them manually if needed. In the example below, the current module, file, and line are explicitly passed at the call site.
clog(logger, :core, 0, "hello"; _module=@__MODULE__, file=@__FILE__, line=@__LINE__)
ComponentLogging.clog
— Functionclog(logger, [group], level, msg...; _module, file, line, kwargs...)
Emit a log message through the given or implicit logger. group
is a Symbol
or NTuple{N,Symbol}
. If omitted, the default group (DEFAULT_SYM,)
is used. level
may be LogLevel
or Integer
. msg
can be one or more values; tuples are passed through as-is.
Keyword arguments file
, line
, and arbitrary kwargs...
are forwarded to the underlying logger sink.
It is recommended to create a forwarding function to implicitly pass the logger:
clog(args...; kwargs...) = clog(logger, args...; kwargs...)
ComponentLogging.clogenabled
— Functionclogenabled(logger, [group], level) -> Bool
Return whether logging is enabled for the given group
and level
using the given or implicit module-bound logger.
It is recommended to create a forwarding function to implicitly pass the logger:
clogenabled(group, level) = clogenabled(logger, group, level)
ComponentLogging.clogf
— Functionclogf(f::Function, logger, [group], level; _module, file, line)
Like clog
, but accepts a zero-argument function f
that is only invoked if logging is enabled for the specified group
and level
. If f()
returns nothing
, no message is emitted. Non-tuple returns are converted to a tuple internally.
It is recommended to create a forwarding function to implicitly pass the logger:
clogf(f, group, level; kwargs...) = clogf(f, logger, group, level; kwargs...)