Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 28 23:23
    willbuckner commented #319
  • Nov 28 06:36
    Techcable commented #319
  • Nov 28 06:28
    Techcable labeled #319
  • Nov 28 06:28
    Techcable labeled #319
  • Nov 24 00:24
    dpc commented #319
  • Nov 23 22:15
    willbuckner opened #319
  • Nov 09 16:56
    dpc closed #317
  • Nov 09 16:55
    dpc locked #317
  • Nov 09 16:55
    dpc commented #317
  • Nov 09 12:51
    xbladesub opened #317
  • Oct 12 05:26
    Techcable commented #315
  • Oct 11 03:51
    andrewbaxter commented #315
  • Oct 11 03:44
    andrewbaxter commented #316
  • Oct 10 16:33
    dpc commented #315
  • Oct 10 06:52
    Techcable labeled #315
  • Oct 10 06:52
    Techcable labeled #315
  • Oct 10 06:52
    Techcable commented #315
  • Oct 10 04:55
    Techcable labeled #316
  • Oct 10 04:55
    Techcable labeled #316
  • Oct 10 04:55
    Techcable commented #316
Lance
@BarronKane
Both stdout and to files with async
@dpc
tanriol
@tanriol:matrix.org
[m]
@BarronKane: Not sure about slog, but log requires any logger used to be thread-safe, so it's thread safe too unless the logger is lying about that.
Lance
@BarronKane
Is this inherent with rust or is the safety to be implemented by the developer?
Rick Richardson
@rrichardson
I am trying to set up a simple async logger which either initializes as a term, or as json, depend on an env var.. but I am missing something regarding async Err and Send that I'm not quite understanding..
the async drain expects private::NeverStruct which.. I'm assuming is because those sources can never emit an error.. which is fine
but I'm not sure how to describe that in the type... Err = () doesn't work either.. whether I use fuse() or not
Rick Richardson
@rrichardson
I made it work by just initializing everything in each branch.. which seems wasteful.. but oh well.
so if I wanted to make slog not panic on error, how would I do that with async? do I have to route those errors to a different drain?
Boiethios
@fedavi:matrix.org
[m]
Hi there, I'm writing a product, and I'm looking for a logger that can log efficiently in multiple files: for example, if the current file has more than 10k lines, it's closed and another file is opened for continuing the logging: does slog provide this feature? Thanks by advance!
dpc:
Boiethios
@fedavi:matrix.org
[m]
:point_up: Edit: @dpc
Boiethios
@fedavi:matrix.org
[m]
Also, everything is async, so if the logging is async, it's even better
Charles Samborski
@demurgos
Hi!
I am looking into adding logging to my library.
It is scraping HTML pages and I would like to log the input/output pairs
My main question is how to deal with structs
My output is a Rust struct with 2-3 levels of nesting.
trace!(self.logger, "scrape_ok"; "html" => html, "data" => res);
This line requires res (my output struct) to implement slog::Value
I already have very extensive support for serde
@dpc What is the recommended way to log my serde-serializable struct as JSON with slog?
Charles Samborski
@demurgos
I am a bit lost with the recommended solution: do I need to implement SerdeValue? Do I need to derive another trait on my struct? Is there a way to reuse my serde support so logging requires minimal changes?
tanriol
@tanriol:matrix.org
[m]
@demurgos: Have you enabled the nested-values feature flag?
Charles Samborski
@demurgos
Yes, I enabled both erased-serde and nested-values
The issue is that I did not implement any slog-specific trait to my output because I don't know which ones to actually implement
This message was deleted
error[E0277]: the trait bound `DinoparcInventoryResponse: slog::Value` is not satisfied
    --> crates/dinoparc_client/src/http.rs:288:18
     |
288  |       Ok(res) => trace!(self.logger, "scrape_ok"; "html" => html, "data" => res),
     |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `slog::Value` is not implemented for `DinoparcInventoryResponse`
     | 
    ::: /home/demurgos/.cargo/registry/src/github.com-1ecc6299db9ec823/slog-2.7.0/src/lib.rs:3286:8
     |
3286 |     V: Value;
     |        ----- required by this bound in `SingleKV`
     |
     = note: required because of the requirements on the impl of `slog::Value` for `&DinoparcInventoryResponse`
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
This is the error I get
Jacob Hill
@jchillin
Hey there. I was looking to get slog-rs working for some json to file logging. Looking over one of the examples I see this slog_json drain wrapped in a mutex and I was curious why: https://github.com/slog-rs/misc/blob/91bee9a5b7b185e958e8261068f81ae578d18e57/examples/duplicate.rs#L14
1 reply
#[macro_use]
extern crate slog;
extern crate slog_term;
extern crate slog_json;

use slog::Drain;

use std::io;
use std::sync::Mutex;

fn main() {
    let plain = slog_term::PlainSyncDecorator::new(std::io::stdout());
    let d1 = slog_term::FullFormat::new(plain).build().fuse();
    let d2 = Mutex::new(slog_json::Json::default(io::stdout())).fuse();
    let log = slog::Logger::root(slog::Duplicate::new(d1, d2).fuse(), o!("version" => env!("CARGO_PKG_VERSION")));

    trace!(log, "logging a trace message");
    debug!(log, "debug values"; "x" => 1, "y" => -1);
    info!(log, "some interesting info"; "where" => "right here");
    warn!(log, "be cautious!"; "why" => "you never know...");
    error!(log, "wrong {}", "foobar"; "type" => "unknown");
    crit!(log, "abandoning test");
Tomasz
@Jarema
Hey!
I have a quick question: is there a way to change default key for log messages from msg to message?
1 reply
Matt Smith
@alastor-erinyes
Does anyone have an example of usage for emit_serde()? I've implemented Serializer with nested-values enabled, but I'm having trouble understanding how I leverage it since the macros seem to only want to accept slog::Value objects and not serde::Serialize objects
Andy Grover
@agrover
hi, I'm new to slog and trying to add a new KV to logs. It looks like some of my KV keys are being logged as foo.bar when I just want a new key to be bar. Since I don't see where the "foo" is coming from I don't know how to turn it off. Any tips? Don't know if this is a slog thing or specific to my code base.
hottea773
@hottea773

I seem to be getting a panic running a simple test only slightly beyond the example. Anyone know why this is? Seems bugged to me, but perhaps I'm doing something wrong?

fn main() {
    use slog::info;
    use slog::Drain;
    use slog::o;

    let decorator = slog_term::TermDecorator::new().build();
    let drain = slog_term::FullFormat::new(decorator).build().fuse();
    let drain = slog_async::Async::new(drain).build().fuse();

    let logger = slog::Logger::root(drain, o!());
    info!(logger, "Hello World!");

    #[derive(Debug, serde::Serialize, slog_extlog::SlogValue, Clone, PartialEq, Default)]
    pub struct MyStruct {
        pub my_string: String,
    }

    let my_struct = MyStruct::default();
    info!(logger, "this is my struct"; "my_struct" => &my_struct);

}

leads to

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/test_slog`
thread 'main' panicked at '`ToSendSerializer` can't fail: Other', /opt/rust/registry/src/<crates mirror>/slog-async-2.7.0/lib.rs:480:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Oct 14 12:41:56.746 INFO Hello World!
Anthony Ramine
@nox
Hello, any chance we could have new releases for slog-term and slog-json?
dpc
@dpc:matrix.org
[m]
Please create github issues and keep reminding me. I'm extra busy lately.
gamgi
@gamgi:matrix.org
[m]

Hi all, I'm looking for an example of a Drain implementation that alters the KV values. I'm working with nested-values and they work great with slog_json, but they panic in slog_term. I'd like to omit some or all KV values in order to avoid the panic. The most trivial example that would help me would be a drain that drops all values and just forwards the record message.

This seems to be a topic that has raised questions previously both regarding panicking [1] [2] and requests for examples [3] [4]. The drain examples I have found so far [5] [6] [7] either omit logging based on existing values, or serialize some trivial values, or are outdated [8].

All help is greatly appreciated!

[1] slog-rs/slog#232
[2] slog-rs/slog#233
[3] slog-rs/slog#211
[4] slog-rs/slog#281
[5] https://gist.github.com/przygienda/f7386a432c876988f35f7e05bfc0c0b3
[6] https://github.com/slog-rs/kvfilter/blob/devel/src/lib.rs
[7] https://github.com/kata-containers/kata-containers/blob/1.x-eol/src/agent/logging/src/lib.rs
[8] https://github.com/input-output-hk/jormungandr/pull/1509/files

gamgi
@gamgi:matrix.org
[m]

I am progressing, but still can't create a custom Drain that just forwards the record.msg() (see above).

The following

use slog::{b, o, record_static, Drain, OwnedKVList, Record};

struct MyDrain<D> {
    drain: D,
}

impl<D: Drain> MyDrain<D> {
    pub fn new(drain: D) -> Self {
        MyDrain { drain }
    }
}

impl<D> Drain for MyDrain<D>
where
    D: Drain,
{
    type Ok = ();
    type Err = D::Err;

    fn log(&self, record: &Record<'_>, _values: &OwnedKVList) -> Result<Self::Ok, Self::Err> {
        let args = format_args!("how do i put record.msg() here?");
        let record_static = record_static!(record.level(), record.tag());

        let new_record = Record::new(&record_static, &args, b!(()));
        let new_values = OwnedKVList::from(o!());

        // Call child logger without old values
        // (and also with a new record, since it otherwise still panics).
        self.drain.log(&new_record, &new_values)?;
        Ok(())
    }
}

Does almost what i want. I just can't seem to pass the message to the child drain in any meaningful way.

ShellWowza
@ShellWowza
hello, I'm setting up cargo deny, which uses the rustsec security database to tell us about vulnerabilities in our dependencies. I'm looking to replace chrono with time in everything as a result. I've filed two PRs: slog-rs/json#28 && slog-rs/bunyan#11 - there's also slog-rs/term#39 filed by someone else - is there any way I can help get these into a release? :)
4 replies
Techcable
@Techcable
@dpc:matrix.org I have released PRs for term, json, and bunyan that will switch to Github actions and add a new release.
dpc
@dpc:matrix.org
[m]
Techcable: Please don't feel like it's necessarily to block on me. I can't really actively maintain slog, and would like to take a back seat. Please let me know whenever I'm blocking you on anything.
Erlend Langseth
@Ploppz
Is it possible in any way to merge two BorrowedKV?
1 reply
NiiightmareXD
@NiiightmareXD
hi is there a way instead of using info!(log, "Test") use just info!("Test")?
1 reply
NiiightmareXD
@NiiightmareXD
ok, I used slog_scope but now only logs from the main function work do I have to put all of my function into the slog_scope::scope? is there a way to make it work with all functions? without putting them in slog_scope::scope? like the standard log crate
3 replies
El Bouchaibi Yassine
@YassineElbouchaibi
Hi guys and @dpc:matrix.org , I was wondering if there is way to test what a function logs via unit tests. For example setting up a drain that drains the logs into a vector and then parsing that vector at the end of my test
dpc
@dpc:matrix.org
[m]
@YassineElbouchaibi: I think there are existing unit tests like that in slog itself.
Mario Reder
@Tarnadas

Hey, I'm trying to use slog in integration tests, but the logging seems to overlap and that makes it unreadable:

Nov 22 10:14:02.362Nov 22 10:14:02.362  Nov 22 10:14:02.362INFOINFO Nov 22 10:14:02.362 Nov 22 10:14:02.362INFO  Hi from orders::test_create_limit_order_sell_should_increase_existing_order testINFO
 Hi from orders::test_create_limit_order_buy_should_create_orders_at_different_prices test

Here's how I set up my logger:

    let logger = {
        let decorator = TermDecorator::new().build();
        let drain = CompactFormat::new(decorator).build();
        let drain = Mutex::new(drain).fuse();

        Logger::root(drain, o!())
    };
Mario Reder
@Tarnadas
It seems like if I use PlainSyncDecorator then it works, but then I have no colors :cry:
referring to this: https://github.com/slog-rs/slog/issues/256#issuecomment-948895623