-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
5787e79
commit 6e30fcf
Showing
5 changed files
with
206 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.