Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    loggerhead
    @loggerhead
    I created a repo (https://github.com/loggerhead/foo) to repro the problem.
    I didn't do anything except setup the global logger, but it will logging trace level log of mio.
    Dawid Ciężarkiewicz
    @dpc
    @loggerhead DId you create an issue on github? I think I've already replied.
    @loggerhead log has it's own set of cargo features to control compile time logging level
    And unlike slog it defaults to logging everything.
    So you need to change it manually if you want differet behavior.
    loggerhead
    @loggerhead
    How can I change it to logging only my lib?
    Dawid Ciężarkiewicz
    @dpc
    You do want to log only your own lib?
    You can write a custom filter for that.
    loggerhead
    @loggerhead
    slog::slog_trace need pass a logger argument, I think it is not convenient for user only want a global logger.
    I'm not sure what do you mean.
    stdlog global logger handler is set only for old-style log crate logging
    And it works by forwarding everything using old logging (log crate) through that given logger. Just like you would do it with slog info!(that_global_logger, "something").
    loggerhead
    @loggerhead
    Oh, I see. My misunderstood.
    Dawid Ciężarkiewicz
    @dpc
    If you don't want to forward mio (or any other library logging using stadnard log infrastructure), you probably don't want to set globl logger at all.
    It's an escape hatch to support older libraries that don't use slog.
    You might want to use slog-scope instead of you want to avoid passing a Logger instances around.
    loggerhead
    @loggerhead
    Ok, I am try it :smile:
    Dawid Ciężarkiewicz
    @dpc
    :+1:
    loggerhead
    @loggerhead
    BTW, the document link in https://crates.io/crates/slog is out of time, it should be https://docs.rs/slog
    Dawid Ciężarkiewicz
    @dpc
    Yes. It's fixed in master, but I'm not sure if it's worth releasing new version for. Maybe I should just do it. :D
    loggerhead
    @loggerhead
    :clap:
    loggerhead
    @loggerhead
    New question
    #[macro_use(o, slog_log, slog_debug, slog_info, slog_warn, slog_error, slog_trace)]
    extern crate slog;
    #[macro_use]
    extern crate slog_scope;
    extern crate slog_term;
    
    use slog::{Level, DrainExt};
    
    fn main() {
        let drain = slog_term::streamer().stderr().build();
        let d = slog::level_filter(Level::Trace, drain);
        let log = slog::Logger::root(d.fuse(), o!());
    
        slog_scope::set_global_logger(log);
        slog_scope::scope(slog_scope::logger().new(o!()), foo);
    }
    
    fn foo() {
        error!("error {}", "I am foo");
        warn!("warn {}", "I am foo");
        info!("info {}", "I am foo");
        debug!("debug {}", "I am foo");
        trace!("trace {}", "I am foo");
    }
    This code will not output trace level logging
    but if I change to any other level, it works as expected.
    Dawid Ciężarkiewicz
    @dpc
    Yes.
    loggerhead
    @loggerhead
    Thanks very much! I remember there is some document mentioned that, but I just cannot find it... As this behaviour is not very intuition, maybe put it to README is more notable?
    Dawid Ciężarkiewicz
    @dpc
    I think it is mentioned in README too.
    No matter where I put it, someone will miss it anyway. :)
    loggerhead
    @loggerhead
    :smile:
    Dawid Ciężarkiewicz
    @dpc
    At some point Google will display an answer on top, when asked about it.
    loggerhead
    @loggerhead
    Thanks again :+1:
    Dawid Ciężarkiewicz
    @dpc
    Sure. No problem.
    Kevin R. S.
    @BourgondAries
    How do I set the log level of slog_term?
    Kevin R. S.
    @BourgondAries
    Nevermind seems it's shown above :P
    Dawid Ciężarkiewicz
    @dpc
    :smile:
    Jason Ozias
    @CraZySacX
    Can the Drain trait be made &mut self?
    I recently implemented a File drain, and ended up with
    impl Drain for FileDrain {
        type Ok = ();
        type Err = Never;
        fn log(&self, record: &Record, _: &OwnedKVList) -> ::std::result::Result<(), Never> {
            if let Ok(mut log_file) = self.file.try_clone() {
                match writeln!(log_file, "{}", record.msg()) {
                    Ok(()) => {}
                    Err(_e) => {}
                }
            }
            Ok(())
        }
    }
    I'd like to avoid the try_clone, but can't due the the &self restriction.
    Dawid Ciężarkiewicz
    @dpc
    Hmmm... the drain are used on multiple threads at once, so they can't be easily &mut self ...
    Also please move to (not so) new channel! :)
    Jason Ozias
    @CraZySacX
    Ah, didn't notice the big moved at the top. I figured there might be a good reason it was &self, thanks.
    Dawid Ciężarkiewicz
    @dpc
    @CraZySacX Having said that, slog v2 has better support for Drains that are not Sync or Send.
    You can just put whatever you have in RefCell in such drain.
    And to use it in Logger you'll have to synchronize it: wrap it in logger that wil make it Sync. Eg. slog_async::Async or Mutex.
    Yes, Mutex<D : Drain> implements Drain