pub fn init_modules<'a, I, K, S>(
modname: S,
modules: I,
l: Level,
f: FacadeVariant,
o: Options,
) -> Result<()>
Expand description
Initialize a Scope
with a list of provided LogKey
s.
The passed Level
, FacadeVariant
and Options
will be used for the Scope
and passed down to the each LogKey unless they provide custom values via the LogKey
trait implementation.
The given modname S
is the name of the scope used for logging like the binary name in
syslog. The modules I
input is everything which can be converted to a iterator.
This is a shortcut for calling init()
and add_submodules()
in sequence.
§Examples
use hclog::{Scope, Level, FacadeVariant, options::Options, Result};
#[derive(Copy, Clone)]
enum LogKeys { IA, IB, IC }
impl Scope for LogKeys {
fn init<S: std::fmt::Display>(
name: S, level: Level, facade: FacadeVariant, options: Options
) -> Result<()> {
// instead of calling:
// hclog::init<Self, S>(name, level, facade, options)?;
// hclog::add_submodules(&[Self::IA, Self::IB, Self::IC])
// you could call:
hclog::init_modules(name, &[Self::IA, Self::IB, Self::IC], level, facade, options)
}
}
§Errors
Returns an error if:
- ContextLock: the internal context can’t be accessed
- LogCompatInitialized: the compatibility layer is already initialized