improvement: better config, better logs

This commit is contained in:
Timo Kösters 2020-12-31 21:07:05 +01:00
parent df16b2ba98
commit edfd3c1f34
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
8 changed files with 68 additions and 60 deletions

View file

@ -121,29 +121,45 @@ impl log::Log for ConduitLogger {
fn log(&self, record: &log::Record<'_>) {
let output = format!("{} - {}", record.level(), record.args());
eprintln!("{}", output);
if self.enabled(record.metadata())
&& record
&& (record
.module_path()
.map_or(false, |path| path.starts_with("conduit::"))
|| record
.module_path()
.map_or(true, |path| !path.starts_with("rocket::")) // Rockets logs are annoying
&& record.metadata().level() <= log::Level::Warn)
{
let first_line = output
.lines()
.next()
.expect("lines always returns one item");
eprintln!("{}", output);
let mute_duration = match record.metadata().level() {
log::Level::Error => Duration::from_secs(60 * 5), // 5 minutes
log::Level::Warn => Duration::from_secs(60 * 60 * 24), // A day
_ => Duration::from_secs(60 * 60 * 24 * 7), // A week
};
if self
.last_logs
.read()
.unwrap()
.get(&output)
.map_or(false, |i| i.elapsed() < Duration::from_secs(60 * 30))
.get(first_line)
.map_or(false, |i| i.elapsed() < mute_duration)
// Don't post this log again for some time
{
return;
}
if let Ok(mut_last_logs) = &mut self.last_logs.try_write() {
mut_last_logs.insert(output.clone(), Instant::now());
mut_last_logs.insert(first_line.to_owned(), Instant::now());
}
self.db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(output),
message::MessageEventContent::notice_plain(output),
));
}
}