Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fmt writer for systemd #773

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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