by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 26 20:35
    dpc commented #256
  • May 26 11:45
    Travis Bathtor/term@23f5458 (test-stdout-docs) passed (1)
  • May 26 11:43
    Bathtor commented #256
  • May 26 03:46
    dpc commented #262
  • May 26 03:39
    dpc commented #262
  • May 26 03:35
    dpc commented #256
  • May 25 15:13
    Bathtor commented #256
  • May 25 14:16
    e00E opened #262
  • May 18 21:34
    stouset commented #261
  • May 15 20:50
    dpc commented #261
  • May 15 20:47
    stouset commented #261
  • Apr 25 21:43
    omarabid opened #261
  • Apr 21 18:07
    pdietl commented #260
  • Apr 21 17:27

    dpc on master

    Fixup doc grammar and reword fo… (compare)

  • Apr 21 17:27
    dpc closed #260
  • Apr 21 17:15
    pdietl opened #260
  • Mar 20 06:21
    Flakebi commented #256
  • Mar 19 04:26
    dpc commented #256
  • Mar 12 23:36
    dpc commented #259
  • Mar 12 23:35
    dpc commented #259
Andrey Cherkashin
@andoriyu
Anyway, common pattern is to log only into stderr or stdout, but never both.
f3kilo
@F3kilo
Hi. I use sloggers for log to file with rotation. Do somebody know, how can i specify log level in compile time in this case?
Shane Pearman
@spearman_gitlab
Does anyone know what causes SerdeValue to generate 'Other error'? https://gist.github.com/rust-play/059abbf57b2e8af4ae6e4c74d2676c4f
Ace Eldeib
@alexeldeib

i'd like to switch between json and term logger based on a cli flag (e.g. from clap). Struggling to figure out how to do this, any suggestions? I'm trying along these lines currently

let mut drain;
match log_format {
    LogFormat::json => {
        drain = slog_json::Json::default(std::io::stderr()).fuse();
        drain = slog_async::Async::new(drain).build().fuse();
    }
    LogFormat::text => {
        let decorator = slog_term::TermDecorator::new().build();
        drain = slog_term::FullFormat::new(decorator).build().fuse();
        drain = slog_async::Async::new(drain).build().fuse();
    }
}
let log = slog::Logger::root(drain, o!());

but getting looots of errors like: may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary

matrixbot
@matrixbot
dpc That's more of Rust language question. You probably need to wrap something in https://www.reddit.com/r/rust/comments/7diwt1/why_is_it_safe_to_use_stdpanicassertunwindsafe/
dpc * AssertUnwindSafe
f3kilo
@F3kilo
Hi. Is there some way to initialize dummy logger, that logs nothing?
matrixbot
@matrixbot

dpc > <@gitter_f3kilo:matrix.org> Hi. Is there some way to initialize dummy logger, that logs nothing?

https://docs.rs/slog/2.5.2/slog/struct.Discard.html ?

f3kilo
@F3kilo
@matrixbot Thanks. I searched for keywords: empty, dummy... Discard is surprise for me)
Erlend Langseth
@Ploppz
is it possible at all to somehow decide in the info! statement (so in the record I guess?), to what file the log entry/record is written, using some custom drain?
becaues I have some async tasks that each need to log to a different file. So far I send them the path, and they use file operations. Would be nice if they could instead use slog
I already do multiplex log entries to different files based on a tag but that's not enough for this use case
Denis Lisov
@tanriol
@Ploppz Maybe just pass a custom logger to them and use it instead of the default one?
Erlend Langseth
@Ploppz
Good idea, thanks
fdubois1
@fdubois1

Hi, is it possible with slog to keep logs in the exact same format as before ? For example, here are the same trace without slog and with slog. You can see the time format and the module name are not displayed the same. Before, we were using log4rs to initialize our log

2020-04-27T15:57:52.737929626-04:00 INFO den_server::http::http_server - Loading http controllers
vs
Apr 27 15:55:16.769 INFO Loading http controllers, module: [den_server::http::http_server]

fdubois1
@fdubois1
Ok, I found how to change the time format with slog_term::FullFormatBuilder::use_custom_timestamp
Now, I would like to be able to change the position of the module. Any hint ?
fdubois1
@fdubois1

@dpc Can I configure the position of information printed in log ? As I wrote just before, I would like to keep the format exactly the same as before because our logs are processed by other system (datadog) and we would prefer to keep the same format for now. So I would like to print date level module message

With what I have now with slog, it prints the date, the level, the message then I added code to print the module at the end that way

    slog::Logger::root(
        drain.fuse(),
        o!("module" => slog::FnValue(move |info| {
            format!("[{}]", info.module())
        })),
How can I have something like this :
2020-04-27T15:57:52.737929626-04:00 INFO den_server::http::http_server - Loading http controllers
instead of
2020-04-27T17:17:36.153669861-04:00 INFO Loading http controllers, module: [den_server::http::http_server]
icy-ux
@icy-ux

Hi guys, I'm trying to Async-ronize a Duplicate that feeds both
console and file logging. Right now my code looks like:

let both = slog::Duplicate::new(console, json_file);
let drain = slog_async::Async::new(both).build().fuse();
slog::Logger::root(drain, slog::o!())

Unfortunately this doesn't work:

23  |     let drain = slog_async::Async::new(both).build().fuse();
    |                 ^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found tuple
    |
   ::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/slog-async-2.5.0/lib.rs:676:50
    |
676 |     pub fn new<D: slog::Drain<Err = slog::Never, Ok = ()> + Send + 'static>(
    |                                                  ------- required by this bound in `slog_async::Async::new`
    |
    = note: expected unit type `()`
                   found tuple `((), ())`

It looks like the type signature contains a tuple, whereas Async only
wants drains whose type signature is a unit type.

Is there a way around this?

@dpc
icy-ux
@icy-ux
Never mind, got it, have to use a Mutex
icy-ux
@icy-ux
Is it possible to filter by crate when using slog_stdlog? Most of the standard logger front ends let the consumer choose to log e.g WARN from crate foo, DEBUG from crate bar, etc
matrixbot
@matrixbot
dpc You shouldn't need mutex there. Probably you just need to handle errors with something likeufise) like Fuse.
fdubois1
@fdubois1

@dpc Can I configure the position of information printed in log ? As I wrote just before, I would like to keep the format exactly the same as before because our logs are processed by other system (datadog) and we would prefer to keep the same format for now. So I would like to print date level module message

With what I have now with slog, it prints the date, the level, the message then I added code to print the module at the end that way

    slog::Logger::root(
        drain.fuse(),
        o!("module" => slog::FnValue(move |info| {
            format!("[{}]", info.module())
        })),

How can I have something like this :
2020-04-27T15:57:52.737929626-04:00 INFO den_server::http::http_server - Loading http controllers
instead of
2020-04-27T17:17:36.153669861-04:00 INFO Loading http controllers, module: [den_server::http::http_server]

matrixbot
@matrixbot
dpc Anything is possible. I think you can start with an empty Term drain and add all keys in order you want. Worst case you can fork and modify. Don't be afraid of looking at the source code.
icy-ux
@icy-ux
@dpc I am still trying to work out if there is any way to filter-by-module when handling log messages via slog-stdlog. Is there any way to do this or am I out of luck?
matrixbot
@matrixbot
dpc icy-ux (Gitter): Sure it is. You can inspect module in some custom Drain https://docs.rs/slog/2.5.2/slog/trait.Drain.html#tymethod.log by inspecting Record argument https://docs.rs/slog/2.5.2/slog/struct.Record.html#method.module, and then passing it to one or the other sub-drain.
icy-ux
@icy-ux
@dpc wonderful, thanks!
Nicolas Guiard
@nguiard
@fdubois1 Hi, can you please give a example of use of use_custom_timestamp? I'm trying to figure it out
Nicolas Guiard
@nguiard
@fdubois1 Nevermind I got it. For anyone wondering:
let drain = slog_term::CompactFormat::new(decorator)
    .use_custom_timestamp(|out: &mut dyn std::io::Write| { 
    write!(out, "{}", chrono::Local::now().to_rfc3339()).unwrap();
    Ok(()) 
})
adler99
@adler99

Hi, I know, that's more rust related then slog, but I guess it's still a common use case. I want to log to a buffer and then read the buffers content:

let buf = vec![];
let json_drain = Mutex::new(slog_json::Json::default(buf)).map(slog::Fuse); // <- buf moved here

// ... do a lot of stuff with logging ...

// read buf, e.g. send it as part of a web response   
json!({"log": buf}); // <- will fail

or is there already a Drain implementation that allows you to do that?

matrixbot
@matrixbot
dpc You'll need to stuff your buffer in a Arc<Mutex I guess, and make sure it still implements io::Write
adler99
@adler99
Thanks, I'll try that!
adler99
@adler99
In case someone else wants to do something similar, I found this:
struct Output<W>(Arc<Mutex<W>>);

impl<W: Write> Output<W> {
    pub fn new(w: Arc<Mutex<W>>) -> Self {
        Output(w)
    }
}

impl<W: Write> Write for Output<W> {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        (*self.0.lock().unwrap()).write(buf)
    }
    fn flush(&mut self) -> std::io::Result<()> {
        (*self.0.lock().unwrap()).flush()
    }
}
matrixbot
@matrixbot
dpc I'd consider adding some buffering to write / lock only on flush or something.
dpc But yeah, that's essentially it.
Marc Carré
@marccarre

Hi there :slight_smile: :wave: -- beginner Rustacean here so apologies in advance if I'm missing some basic knowledge, if there are better places to ask questions, etc. :bow:

I was investigating logging for Rust and eventually discovered slog which looked very promising. I am looking for a "HTTP appender", i.e. the equivalent of this https://logging.apache.org/log4j/2.x/manual/appenders.html#HttpAppender for Rust and quick searches on Google, slog's GitHub and crates.io didn't yield anything.

  1. Is there something of that sort available in slog (or more generally, somewhere in the Rust ecosystem)?
  2. If not, where would be a good place to look to start to build one? (and any warning/pitfall/etc. I should be aware of? Is that a matter of implementing a "drain" using slog-stream?)
matrixbot
@matrixbot
dpc I haven't seen one myself, but I'd search on crates.io before starting one.
dpc It's basically a matter of impl slog::Drain for MyOwnHttpAppender
Marc Carré
@marccarre
sounds good, thanks for the confirmation & pointers :+1:
icy-ux
@icy-ux
is there a Drain which will print the entire log record?
@dpc / dpc
I'm trying to use slog_vmodule to filter by module, but it's not going, trying to figure out why
icy-ux
@icy-ux
never mind, looks like I found the issue: slog_vmodule requires you to specify the entire module path
new issue
@dpc I am trying to implent my own simple filter Drain. For log messages which I do not want to pass down the chain, I simply return Ok(D::Ok); where D: Drain is the generic Drain my Drain has been initialised with
icy-ux
@icy-ux
however I get the error no associated item namedOkfound for type parameterDin the current scope
trying to return Ok(Self::Ok) doesn't work either
icy-ux
@icy-ux
Worked out I need to wrap the associated type in an Option, type Ok = Option<D::Ok>, but now it's giving me errors that slog::Logger::root() wants a unit type instead of an option
...fixed that by not calling .fuse() on the child Drain