Skip to content

Commit

Permalink
Use fmt writer for systemd
Browse files Browse the repository at this point in the history
This uses a custom fmt writer for systemd output to preserve all
information within the message field.

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Oct 4, 2022
1 parent 5787e79 commit 6e30fcf
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 20 deletions.
176 changes: 161 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion conmon-rs/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ strum = { version = "0.24.1", features = ["derive"] }
shadow-rs = "=0.16.1"
multimap = "0.8.3"
tracing = "0.1.36"
tracing-journald = "0.3.0"
tracing-subscriber = "0.3.15"
uuid = { version = "1.1.2", features = ["v4", "fast-rng", "macro-diagnostics"] }
regex = "1.6.0"
Expand All @@ -37,6 +36,7 @@ tokio-eventfd = "0.2.0"
lazy_static = "1.4.0"
tz-rs = "0.6.14"
tokio-fd = "0.3.0"
libsystemd = "0.5.0"

[build-dependencies]
shadow-rs = "=0.16.1"
Expand Down
35 changes: 35 additions & 0 deletions conmon-rs/server/src/journal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use libsystemd::logging::{journal_print, Priority};
use std::{
io::{self, Error, ErrorKind, Write},
str,
};
use tracing_subscriber::fmt::writer::MakeWriter;

macro_rules! io_err {
($x:expr) => {
$x.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?
};
}

#[derive(Default)]
pub struct Journal;

impl Write for Journal {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
let s = io_err!(str::from_utf8(buf));
io_err!(journal_print(Priority::Notice, s));
Ok(s.len())
}

fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}

impl<'a> MakeWriter<'a> for Journal {
type Writer = Journal;

fn make_writer(&'a self) -> Self::Writer {
Journal::default()
}
}
1 change: 1 addition & 0 deletions conmon-rs/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod container_io;
mod container_log;
mod cri_logger;
mod init;
mod journal;
mod listener;
mod oom_watcher;
mod rpc;
Expand Down
Loading

0 comments on commit 6e30fcf

Please sign in to comment.