Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 29 07:15
    Kixunil commented #274
  • Apr 28 23:25
    davepacheco commented #274
  • Apr 28 09:05
    Kixunil commented #274
  • Apr 26 17:10
    dpc commented #274
  • Apr 26 16:49
    davepacheco commented #274
  • Apr 26 15:27
    dpc commented #274
  • Apr 26 07:52
    Kixunil commented #274
  • Apr 26 02:42
    davepacheco commented #274
  • Apr 25 04:05
    dpc commented #274
  • Apr 24 02:05
    davepacheco commented #274
  • Apr 23 23:02
    dpc commented #274
  • Apr 23 22:46
    davepacheco commented #274
  • Apr 23 05:50
    Travis slog-rs/kvfilter (master) broken (61)
  • Apr 09 07:33
    nazar-pc commented #125
  • Mar 25 20:10
    Travis slog-rs/atomic (v3.1.0) passed (1279)
  • Mar 11 22:58
    dpc commented #282
  • Mar 11 21:10
    Jonathas-Conceicao edited #282
  • Mar 11 21:04
    Jonathas-Conceicao edited #282
  • Mar 11 21:02
    Jonathas-Conceicao opened #282
  • Mar 10 22:36
    Travis slog-rs/kvfilter (devel) broken (59)
Wojciech Niedźwiedź
@Niedzwiedzw
and it's a field on another struct I'm implementing slog::KV for
what's the approach here?
matrixbot
@matrixbot
dpc I think there's a crate to derive KV and it (hopefulhy) is recursive?
Wojciech Niedźwiedź
@Niedzwiedzw
just checked it out and it's not
well
another question is how do I make outputs colorful?
cause it looks kinda boring
divma
@divagant-martian
hey, any idea how do ? and % work? I'm trying to implement KV for a struct where every field implements either Debug or Display or both and I would like to do it without allocating a new String for each, every time I log something
divma
@divagant-martian

@dpc I'm looking to stop doing things like
info!(logger, "some msg"; "a" => %thing.a, "b" => %thing.b, "c" => %thing.c, "d" => %thing.d, "e" => %thing.e);
by being able to do
info!(logger, "some msg"; thing);
but without paying the price of creating a String every time like

        serializer.emit_str("a", &self.a.to_string())?;
        serializer.emit_str("b", &self.a.to_string())?;
        serializer.emit_str("c", &self.a.to_string())?;
        serializer.emit_str("d", &self.a.to_string())?;
        serializer.emit_str("e", &self.a.to_string())?;

as far as I understand from the docs, the first one does not allocate Strings, how do I do it?

Nick Stockton
@sputnick1124
Is it possible to Send a Drain to a new process? I'm trying to accomplish something similar to this, but using slog-json instead of println to print from the child process. I am quite new to slog (and pretty new to multi-processing), so I'm not sure if I'm just trying to do something that is not possible.
I would have thought that the Logger made in the main thread would have been copied by fork and that I could simply reuse it from the child process, but I am not getting any prints from the child at all.
divma
@divagant-martian
@sputnick1124 how are you doing it? why not just clone the Logger?
Nick Stockton
@sputnick1124
I am, but that has not had the effect I would have expected.
pub struct ProcessManager {
    log: Logger,
    num_descendants: Arc<AtomicUsize>,
}

impl ProcessManager {
    pub fn new(log: Logger) -> Self {
        unsafe {
            prctl(PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0);
        }
        Self {
            log,
            num_descendants: Arc::new(AtomicUsize::new(0)),
        }
    }

    pub fn fork(&self) {
        match unsafe { fork() } {
            Ok(ForkResult::Parent { child }) => {
                let pid = getpid().as_raw() as i32;
                let cpid = child.as_raw() as i32;
                let n = self.num_descendants.fetch_add(1, Ordering::SeqCst);
                debug!(self.log, "forking a new process"; 
                    "pid" => pid,
                    "child_pid" => cpid,
                    "descendants" => n + 1);
            }
            Ok(ForkResult::Child) => {
                let pid = getpid().as_raw() as i32;
                let ppid = getppid().as_raw() as i32;
                let log = self.log.new(o!());
                info!(log, "forked as new process"; "pid" => pid, "ppid" => ppid);
                unsafe { exit(0) };
            }
            Err(err) => error!(self.log, "fork failed"; "err" => format!("{}", err)),
        }
    }
}
I've tried cloning before the actual fork as well, but I think there's something obvious I'm missing
Denis Lisov
@tanriol
@sputnick1124 You don't use the async drain, do you?
@divagant-martian Note that emit_str is not the only method Serializer has...
Nick Stockton
@sputnick1124
@tanriol , I am using the async drain.
Denis Lisov
@tanriol
It uses a separate thread, which fork does not clone, so I'm absolutely not surprised it does not work after fork :-)
Nick Stockton
@sputnick1124
Ah right, there's the obvious thing I was missing, thanks!
divma
@divagant-martian
@tanriol I know, but the fields of my struct are not basic types
so it's not like I'm trying to avoid a String by using emit_strwhen I could do, let's say emit_u8
thanks for the answer regardless. If you have any other suggestion i'm all ears
but also, the types of those fields are not mine so I can't impl Value for them
Denis Lisov
@tanriol
@divagant-martian IIUC, both % and ? use emit_arguments
divma
@divagant-martian
I see what you are suggesting and I think Ive tried it and failed. But you know what? I'l check again
thanks
Denis Lisov
@tanriol
You may want to look at the impl_default_as_fmt macro
divma
@divagant-martian
this looks like what I was needing thanks @tanriol
Jon Barrett
@joncb_gitlab
I feel like i must be missing something really simple but is there a way to get the original log template out of the Record? I'm trying to implement a Drain for Seq (https://datalust.co/seq) and it's API wants that.
Denis Lisov
@tanriol
Looks like there's none (it's somewhere inside Arguments, but they don't have a getter for that)
Jon Barrett
@joncb_gitlab
Bugger.
Erlend Langseth
@Ploppz
    let drain = Duplicate::new(
        app_drain,
        Duplicate::new(
            web_drain,
            Duplicate::new(poller_drain, Duplicate::new(errors_drain, term_drain)),
        ),
    );
I don't assume that it is possible to put this in a function that takes a parameter which (at runtime obviously) configures which of these draisn to create and include in the final drain?
helgoboss
@helgoboss
Just wanted to say that slog is awesome :) Thanks to the author.
Sean Pianka
@seanpianka
Hi guys, does anyone here know how to enumerate the values of a slog::OwnedKVList object?
I am trying to create a new slog drain that sends messages to Slack if the level is error/critical, or it is Info and contains a kv "err" => Some(..)
But I don't know how to iterate through the slog kv pairs to find "err" and see if it is Some()
Sean Pianka
@seanpianka
@dpc
matrixbot
@matrixbot
dpc Impl serializer
Sean Pianka
@seanpianka
Do I need to impl a serializer? I want to send Slack message, duplicating exact format that sloggers::TerminalLoggerBuilder drains to stdout
I can't figure out how to print Record or OwnedKVList (inside of Drain::log)
Sean Pianka
@seanpianka

Reusing the LazyLogString works for now. The remaining issue is conditionally discarding messages whose OwnedKVList does not contain "err" key, or has "err" key but value is in ["", "None"].

i.e.:

// discard
info!(server.logger, ""; "err" => None);
// discard
info!(server.logger, ""; "err" => ""); 
// discard
info!(server.logger, ""; "key" => "value"); 
// do not discard, log with sub-`Drain`
info!(server.logger, ""; "err" => "error!!!");

This is my attempt, however it seems that these semantics are not possible to achieve with the 4 methods available?

let filter = KVFilter::new(drain, Level::Debug)
    .always_suppress_any(Some(
        vec![(
            "err".to_string(),
            HashSet::from_iter(vec!["None".to_string(), "".to_string()]),
        )]
        .into_iter()
        .collect(),
    ))
    .only_pass_any_on_all_keys(Some(vec![("err".to_string(), HashSet::new())].into_iter().collect()));
Jörg Sommer
@joerg:alea.gnuu.de
[m]
Does slog support custom log-levels like notice in Syslog?
Marco Caballero
@Dash83

Hello all, first time poster here with a somewhat unorthodox question (I think).

I have this system I wrote in Rust that spawns multiple processes that perform independent processing, and log their operations to their own log files using slog. Each process performs multiple time-sensitive operations, and logs the result of each one. Given the time sensitivity of the tasks, I'm using the slog-async crate to log in a separate thread and block the processing thread on IO.

Due to the nature of the system, each process ends up having 4~5 threads, which while is not that bad, I believe it starts to become troublesome when I have hundreds of these processes. I'm looking into the possibility of changing my logging approach to get rid of the dedicated logging thread create by the slog-async crate. My ideal solution would be to have a different logging provider in which when you call any of the logging macros, it would simply push the logging record into an mpsc/crossbeam channel, and I whichever thread holds the other end of the channel could write those records into the appropriate sink (file in this case) when appropriate.

Does anything like that exist? I reckon the slog-async crate does ALMOST all that, except that it creates a dedicated thread that holds the other end of the channel and write the records on its own.

Any suggestions? Thanks!

Rogério Sampaio de Almeida
@rsalmei
Hello! Please, is there any support for Mapped Diagnostic Context? I couldn't find any crates with mdc support. Thanks!
tanriol
@tanriol:matrix.org
[m]
@rsalmei: You may have a better reply if you describe what that context is :-)
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?