Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Apr 29 07:15
    Kixunil commented #274
  • Apr 28 23:25
    davepacheco commented #274
  • Apr 28 09:05
    Kixunil commented #274
  • Apr 26 17:10
    dpc commented #274
  • Apr 26 16:49
    davepacheco commented #274
  • Apr 26 15:27
    dpc commented #274
  • Apr 26 07:52
    Kixunil commented #274
  • Apr 26 02:42
    davepacheco commented #274
  • Apr 25 04:05
    dpc commented #274
  • Apr 24 02:05
    davepacheco commented #274
  • Apr 23 23:02
    dpc commented #274
  • Apr 23 22:46
    davepacheco commented #274
  • Apr 23 05:50
    Travis slog-rs/kvfilter (master) broken (61)
  • Apr 09 07:33
    nazar-pc commented #125
  • Mar 25 20:10
    Travis slog-rs/atomic (v3.1.0) passed (1279)
  • Mar 11 22:58
    dpc commented #282
  • Mar 11 21:10
    Jonathas-Conceicao edited #282
  • Mar 11 21:04
    Jonathas-Conceicao edited #282
  • Mar 11 21:02
    Jonathas-Conceicao opened #282
  • Mar 10 22:36
    Travis slog-rs/kvfilter (devel) broken (59)
Jon Barrett
I feel like i must be missing something really simple but is there a way to get the original log template out of the Record? I'm trying to implement a Drain for Seq (https://datalust.co/seq) and it's API wants that.
Denis Lisov
Looks like there's none (it's somewhere inside Arguments, but they don't have a getter for that)
Jon Barrett
Erlend Langseth
    let drain = Duplicate::new(
            Duplicate::new(poller_drain, Duplicate::new(errors_drain, term_drain)),
I don't assume that it is possible to put this in a function that takes a parameter which (at runtime obviously) configures which of these draisn to create and include in the final drain?
Just wanted to say that slog is awesome :) Thanks to the author.
Sean Pianka
Hi guys, does anyone here know how to enumerate the values of a slog::OwnedKVList object?
I am trying to create a new slog drain that sends messages to Slack if the level is error/critical, or it is Info and contains a kv "err" => Some(..)
But I don't know how to iterate through the slog kv pairs to find "err" and see if it is Some()
Sean Pianka
dpc Impl serializer
Sean Pianka
Do I need to impl a serializer? I want to send Slack message, duplicating exact format that sloggers::TerminalLoggerBuilder drains to stdout
I can't figure out how to print Record or OwnedKVList (inside of Drain::log)
Sean Pianka

Reusing the LazyLogString works for now. The remaining issue is conditionally discarding messages whose OwnedKVList does not contain "err" key, or has "err" key but value is in ["", "None"].


// discard
info!(server.logger, ""; "err" => None);
// discard
info!(server.logger, ""; "err" => ""); 
// discard
info!(server.logger, ""; "key" => "value"); 
// do not discard, log with sub-`Drain`
info!(server.logger, ""; "err" => "error!!!");

This is my attempt, however it seems that these semantics are not possible to achieve with the 4 methods available?

let filter = KVFilter::new(drain, Level::Debug)
            HashSet::from_iter(vec!["None".to_string(), "".to_string()]),
    .only_pass_any_on_all_keys(Some(vec![("err".to_string(), HashSet::new())].into_iter().collect()));
Jörg Sommer
Does slog support custom log-levels like notice in Syslog?
Marco Caballero

Hello all, first time poster here with a somewhat unorthodox question (I think).

I have this system I wrote in Rust that spawns multiple processes that perform independent processing, and log their operations to their own log files using slog. Each process performs multiple time-sensitive operations, and logs the result of each one. Given the time sensitivity of the tasks, I'm using the slog-async crate to log in a separate thread and block the processing thread on IO.

Due to the nature of the system, each process ends up having 4~5 threads, which while is not that bad, I believe it starts to become troublesome when I have hundreds of these processes. I'm looking into the possibility of changing my logging approach to get rid of the dedicated logging thread create by the slog-async crate. My ideal solution would be to have a different logging provider in which when you call any of the logging macros, it would simply push the logging record into an mpsc/crossbeam channel, and I whichever thread holds the other end of the channel could write those records into the appropriate sink (file in this case) when appropriate.

Does anything like that exist? I reckon the slog-async crate does ALMOST all that, except that it creates a dedicated thread that holds the other end of the channel and write the records on its own.

Any suggestions? Thanks!

Rogério Sampaio de Almeida
Hello! Please, is there any support for Mapped Diagnostic Context? I couldn't find any crates with mdc support. Thanks!
@rsalmei: You may have a better reply if you describe what that context is :-)
Geobert Quach
I have a global logger via slog_scope::set_global_logger and kept its guard. Now I want to reconfigure this logger.
I tried to drop the guard and recreate another global logger, but I get a panic when dropping the guard…
Is that normal? according to slog-rs/slog#169 it seems so but then… how should I reconfigure the global logger?
pinging @dpc ^^
Jason Ish
Can slog write to multiple outputs using a different log level for each? I want info type logs to console, but debug and up to a file.
@jasonish: I think you need slog::Duplicate
Hi all, should I pass slog::Logger by reference or by value?
I guess the advice is to pass them by value
so it seems like my code becomes littered with log.clone() all over the place. Is this to be expected?
Can slog write logs to a file in color? I only have info showing up in color at the moment, all the others don't show up in color. I'm using a PlainSyncDecorator to create it with a file but I tried to use the TermDecorator for the colors but it seemed that I can't use the term decorator with a file?
Malhar Vora
I want to create a Drain for log rotation but I don't have any clue for where to start from. Any direction for that ?
Is it incorrect to use slog_term::{FullFormat, PlainDecorator} when the output goes into a file actually? I mean it works fine but is there a 'better' way to output to files?
Erlend Langseth
@dpc On second thought, about log rotation and the plan of creating slog-flie crate...
Seems like the easiest solution to do log rotation right now is https://docs.rs/file-rotate/0.4.0/file_rotate/ an std::io::Write wrapper. So I guess I don't have to do any of what I planned
One thought I had though, was that... is it beneficial in any way to have more knowledge when doing log rotation, than just the lines written? Like what if there is a multi line log entry, and we want to split into files based on number of records instead of number of lines.
That said, in my deliberation about how to proceed, I had a moment where I was thinking: The relationship between formatting, and output (std::io::Write).... it's currently like this: We have structs Format<Output> that implement Drain. Another idea is to flip it around and have a trait Format and generally create drains specific for some output like File<F: Format>, which could provide log rotation... Anyway.. not sure if these ideas are of any worth
Hey another question about slog-async: Someone mentioned that it "offloads formatting to another thread", but reading the code, it really seems to format the message in the current thread and then send it.. is this incorrect? https://docs.rs/slog-async/2.6.0/src/slog_async/lib.rs.html#455
ploppz: I think it does not do actual string formatting there, but just boxes/clones the data for transfer to the other thread...
which does the formatting, before sending
Yeah, looks like it does, sorry :-( on the other hand, that's probably not all the formatting required.
Hmm yeah
Seems to me like potentially the most important thing to keep in another thread is IO operations like writing to a file
Thomas Hatzopoulos
Hello, I'm trying to write async logs to a file as structured json and I was successful however if the program ended before logs were finished writing I would get truncated logs. A quick fix for this was to sleep for 500 ms at the end of my program, but I think this should also be doable by using AsyncGuard. I think that I am setting up async guard incorrectly however, as now my log file is being created but nothing is ever written out to it. My current logger setup code is below, and I also tried adding a manual mem::drop of the variable _guard at the end of main and that does not seem to fix the issue either. Does anyone have any suggestions? I could not seem to find a working example of AsyncGuard to compare mine to.
let file = OpenOptions::new()
    let drain = slog_json::Json::new(file)
        .set_pretty(false) // sets output to be one line at a time
    let drain = slog_async::Async::new(drain).build_with_guard().0.fuse();
    let logger = slog::Logger::root(drain, o!());
    let _guard = slog_scope::set_global_logger(logger).cancel_reset();
hello, does someone know how to disable terminal output when running tests for slog_term?
trying to find options to do that but have very successful so far
this is my current setting, tried using stderr() for the decorator but doesn't change anything.
        let decorator = slog_term::TermDecorator::new().stdout().build();
        let drain = slog_term::FullFormat::new(decorator).build().fuse();
        let drain = slog_async::Async::new(drain).build().fuse();

        slog::Logger::root(drain, o!())
nevermind, tried TestStdoutWriter and i don't see outputs on tests anymore.
James Sewell
Is there a nice way to map between Error(e) and slog output? Or do I just need to do it manually?
Also can I make it so when I return from main with Err(e) slog catches it and outputs some (in my case) json
Marlon Brandão de Sousa


I am having a kind of a hard time trying to understand some slog_escope concepts.

Specially, I am not sure how to create nested scopes, and also I am not sure if a nested scope creates a new context.

Here is what I need:

on main function, I have

let rootLogger = slog::Logger::root(
        o!("version" => env!("CARGO_PKG_VERSION")),

info!("Service initialized");
slog_scope::scope(&rootLogger, || {
info!("info 1", o!("info1" => "information 1"));

The handler() function will be called several times. I want to maintain the info1 and the version keys, but I don't want to maintain any other keys the handler() function generate persisted after it returns.

fn1() {
  // I need to create a new context here ... but how?
  slog_scope::scope(/* what goes here? */, || {
Amit Singh
can anyone tell me- why slog_error() fn print error twice or may be how to do that???
I've cloned a Project in that they are using slog for logging. whenever I'm getting any error, slog_error() printing the same thing twice. I just want to know how it is the default feature of slog_error() fn or because of some configuration. I didn't find any config related to this. plz, help me with this...