Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 16 07:09
    johnbatty opened #284
  • Jun 07 22:56
    crusty-dave closed #283
  • Jun 07 22:56
    crusty-dave commented #283
  • Jun 04 21:48
    dpc commented #283
  • Jun 02 23:07
    crusty-dave edited #283
  • Jun 02 23:07
    crusty-dave edited #283
  • Jun 02 19:57
    crusty-dave edited #283
  • Jun 02 18:47
    crusty-dave edited #283
  • Jun 02 18:26
    crusty-dave edited #283
  • Jun 02 18:18
    crusty-dave edited #283
  • Jun 02 18:17
    crusty-dave edited #283
  • Jun 02 18:17
    crusty-dave opened #283
  • May 25 17:31
    dpc commented #125
  • May 25 09:36
    Techcable edited #125
  • May 25 09:36
    Techcable commented #125
  • May 25 09:34
    Techcable commented #125
  • May 14 02:07
    Travis slog-rs/scope (master) passed (1350)
  • May 13 02:09
    Travis slog-rs/scope (master) errored (1349)
  • Apr 29 07:15
    Kixunil commented #274
  • Apr 28 23:25
    davepacheco commented #274
Geobert Quach
@Geobert
Hi,
I have a global logger via slog_scope::set_global_logger and kept its guard. Now I want to reconfigure this logger.
I tried to drop the guard and recreate another global logger, but I get a panic when dropping the guard…
Is that normal? according to slog-rs/slog#169 it seems so but then… how should I reconfigure the global logger?
pinging @dpc ^^
Jason Ish
@jasonish
Can slog write to multiple outputs using a different log level for each? I want info type logs to console, but debug and up to a file.
tanriol
@tanriol:matrix.org
[m]
@jasonish: I think you need slog::Duplicate
Silver
@sssilver
Hi all, should I pass slog::Logger by reference or by value?
I guess the advice is to pass them by value
Silver
@sssilver
so it seems like my code becomes littered with log.clone() all over the place. Is this to be expected?
Camilo
@CamiloJac
Can slog write logs to a file in color? I only have info showing up in color at the moment, all the others don't show up in color. I'm using a PlainSyncDecorator to 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?
Malhar Vora
@vbmade2000
I want to create a Drain for log rotation but I don't have any clue for where to start from. Any direction for that ?
ploppz
@ploppz:matrix.org
[m]
Is it incorrect to use slog_term::{FullFormat, PlainDecorator} when the output goes into a file actually? I mean it works fine but is there a 'better' way to output to files?
Erlend Langseth
@Ploppz
@dpc On second thought, about log rotation and the plan of creating slog-flie crate...
Seems like the easiest solution to do log rotation right now is https://docs.rs/file-rotate/0.4.0/file_rotate/ an std::io::Write wrapper. So I guess I don't have to do any of what I planned
One thought I had though, was that... is it beneficial in any way to have more knowledge when doing log rotation, than just the lines written? Like what if there is a multi line log entry, and we want to split into files based on number of records instead of number of lines.
That said, in my deliberation about how to proceed, I had a moment where I was thinking: The relationship between formatting, and output (std::io::Write).... it's currently like this: We have structs Format<Output> that implement Drain. Another idea is to flip it around and have a trait Format and 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
ploppz
@ploppz:matrix.org
[m]
Hey another question about 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
tanriol
@tanriol:matrix.org
[m]
ploppz: I think it does not do actual string formatting there, but just boxes/clones the data for transfer to the other thread...
which does the formatting, before sending
tanriol
@tanriol:matrix.org
[m]
Yeah, looks like it does, sorry :-( on the other hand, that's probably not all the formatting required.
ploppz
@ploppz:matrix.org
[m]
Hmm yeah
Seems to me like potentially the most important thing to keep in another thread is IO operations like writing to a file
Thomas Hatzopoulos
@thatzopoulos_gitlab
Hello, I'm trying to write async logs to a file as structured json and I was successful however if the program ended before logs were finished writing I would get truncated logs. A quick fix for this was to sleep for 500 ms at the end of my program, but I think this should also be doable by using AsyncGuard. I think that I am setting up async guard incorrectly however, as now my log file is being created but nothing is ever written out to it. My current logger setup code is below, and I also tried adding a manual mem::drop of the variable _guard at the end of main and that does not seem to fix the issue either. Does anyone have any suggestions? I could not seem to find a working example of AsyncGuard to compare mine to.
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();
Darwin
@darwin67
hello, does someone know how to disable terminal output when running tests for slog_term?
trying to find options to do that but have very successful so far
Darwin
@darwin67
this is my current setting, tried using 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!())
Darwin
@darwin67
nevermind, tried TestStdoutWriter and i don't see outputs on tests anymore.
James Sewell
@jamessewell
Is there a nice way to map between Error(e) and slog output? Or do I just need to do it manually?
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