Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 15 22:59
    dpc commented #290
  • Nov 15 22:31
    Kixunil commented #290
  • Nov 15 22:27
    dpc commented #290
  • Nov 15 22:05
    Kixunil commented #290
  • Nov 15 20:53
    dpc commented #290
  • Nov 12 15:15
    Kixunil opened #291
  • Nov 12 15:04
    Kixunil commented #238
  • Nov 11 19:11
    Kixunil opened #290
  • Nov 05 11:57
    Ploppz commented #108
  • Nov 05 09:21
    garasubo commented #108
  • Oct 21 18:32
    dpc commented #256
  • Oct 21 18:19
    PureW commented #256
  • Oct 21 17:00
    dpc commented #256
  • Oct 21 16:14
    PureW commented #256
  • Oct 21 16:14
    PureW commented #256
  • Oct 06 05:35

    dpc on master

    Update README.md (compare)

  • Oct 06 05:34

    dpc on master

    Update README.md (compare)

  • Sep 07 17:55
    dpc commented #267
  • Aug 15 03:27
    at15 commented #285
  • Aug 15 03:16
    at15 commented #285
James Sewell
@jamessewell
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
@marlon-sousa

Hello,

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(
        Mutex::new(slog_json::Json::default(std::io::stderr())).map(slog::Fuse),
        o!("version" => env!("CARGO_PKG_VERSION")),
    );

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

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
@as271996_gitlab
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...
f3kilo
@F3kilo
I want to log info!() messages in release build but can't configure slog + slog-term to do this. Can someone help?
tanriol
@tanriol:matrix.org
[m]
@F3kilo: Have you tried reading the docs? Sounds like you have some strange feature configuration there...
f3kilo
@F3kilo

I wrote this:
slog = { version = "2.7.0", features = ["max_level_trace", "release_max_level_trace"] }

But see only error!() messages.

tanriol
@tanriol:matrix.org
[m]
Seems to work for me with this slog-term example
f3kilo
@F3kilo
Thanks. Solved. Problem was in dependency with "release_max_level_warn".
Lance
@BarronKane
Hey I had a quick question here that I can't quite seem to get a handle on: Is log/slog thread safe? I've been told that rust's built in log is safe but I cannot discover where a global mutex might live or another mechanism as such. I'm looking to implement a logger across many threads and crates without having to push a logger struct into everything or call a global logger struct in the same manner.
Both stdout and to files with async
Lance
@BarronKane
@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.