mirror of
https://github.com/stalwartlabs/mail-server.git
synced 2025-02-25 00:12:58 +08:00
Filter out invalid timestamps on log entries
This commit is contained in:
parent
e8205a27ca
commit
0e8961937e
1 changed files with 3 additions and 5 deletions
|
@ -4,6 +4,7 @@ use std::{
|
|||
path::Path,
|
||||
};
|
||||
|
||||
use chrono::DateTime;
|
||||
use rev_lines::RevLines;
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
|
@ -120,14 +121,11 @@ fn read_log_files(
|
|||
impl LogEntry {
|
||||
fn from_line(line: &str) -> Option<Self> {
|
||||
let (timestamp, rest) = line.split_once(' ')?;
|
||||
let timestamp = timestamp
|
||||
.rsplit_once('.')
|
||||
.filter(|(_, z)| z.ends_with('Z'))
|
||||
.map_or_else(|| timestamp.to_string(), |(t, _)| format!("{t}Z"));
|
||||
let timestamp = DateTime::parse_from_rfc3339(timestamp).ok()?;
|
||||
let (level, message) = rest.trim().split_once(' ')?;
|
||||
let message = message.split_once(": ").map_or(message, |(_, v)| v);
|
||||
Some(Self {
|
||||
timestamp,
|
||||
timestamp: timestamp.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
|
||||
level: level.to_string(),
|
||||
message: message.to_string(),
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue