emit_strwhen I could do, let's say
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?
let drain = Duplicate::new( app_drain, Duplicate::new( web_drain, Duplicate::new(poller_drain, Duplicate::new(errors_drain, term_drain)), ), );
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
// 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) .always_suppress_any(Some( vec![( "err".to_string(), HashSet::from_iter(vec!["None".to_string(), "".to_string()]), )] .into_iter() .collect(), )) .only_pass_any_on_all_keys(Some(vec![("err".to_string(), HashSet::new())].into_iter().collect()));
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!
PlainSyncDecoratorto 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?
Drain. Another idea is to flip it around and have a
trait Formatand 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
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
let file = OpenOptions::new() .create(true) .write(true) .append(true) .open(&log_path) .unwrap(); let drain = slog_json::Json::new(file) .set_pretty(false) // sets output to be one line at a time .add_default_keys() .build() .fuse(); 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(); slog_stdlog::init().unwrap();
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!())