Skip to content
Dawid Ciężarkiewicz edited this page Oct 7, 2016 · 19 revisions

Can I try slog without modifying my code (too much)?

Yes. See slog-stdlog crate and slog oldlogging example.

#[macro_use]
extern crate log;
extern crate slog_stdlog;

fn main() {
     slog_stdlog::init().unwrap();
     // Note: this `info!(...)` macro comes from `log` crate
     info!("standard logging redirected to slog");
 }

or if you were using env_logger before:

#[macro_use]
extern crate log;
extern crate slog_envlogger;

fn main() {
     slog_envlogger::init().unwrap();
     // Note: this `info!(...)` macro comes from `log` crate
     info!("standard logging redirected to slog");
 }

Won't info! and similar macros from slog clash with log macros?

If you start a new project, you should just use slog and not log.

If you're just trying out slog in existing project, you can use slog-stdlog and keep using log crate macros. During transition period to slog, you can use alternative names of slog macros. See slog alternative names example

Can I output file, line module and similar.

Yes. Every closure-value is provided with RecordInfo argument which contains that information. Output it under any name you want, any way you want. See slog file-line-module example.

Can I disable some logging levels at compile time

Yes. slog-rs provides the same Cargo.toml-defined feature-s that standard log did, that allow completely disabling given logging levels at compile time.

Do I have to pass Logger around?

Not really. You can help yourself using (slog-scope)[https://crates.io/crates/slog-scope/].