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

feat: support journald appender #80

Merged
merged 7 commits into from
Nov 14, 2024
Merged

feat: support journald appender #80

merged 7 commits into from
Nov 14, 2024

Conversation

tisonkun
Copy link
Contributor

This fixes #76

Comment on lines +40 to +60
fn write_escaped_key(key: &str, buffer: &mut Vec<u8>) {
// Key length is limited to 64 bytes
let mut remaining = 64;

let escaped = key
.to_ascii_uppercase()
.replace(|c| !is_valid_key_char(c), "_");

if escaped.starts_with(|c: char| matches!(c, '_' | '0'..='9')) {
buffer.extend_from_slice(b"ESCAPED_");
remaining -= 8;
}

for b in escaped.into_bytes() {
if remaining == 0 {
break;
}
buffer.push(b);
remaining -= 1;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swsnr This is a solution for your leaving TODO.

Sorry I don't directly depend your crate mainly due to this crate is also a logger implementation and I only need part of your code. The credit and origin are documented, though.

Comment on lines +93 to +99
impl PutAsFieldValue for Value<'_> {
fn put_field_value(self, buffer: &mut Vec<u8>) {
// SAFETY: no more than an allocate-less version
// buffer.extend_from_slice(format!("{}", self))
write!(buffer, "{}", self).unwrap();
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swsnr

And for this leaving TODO "We can probably write the value more efficiently by visiting it?", I noticed that we actually format integers as their string representation instead of bytes. Thus visiting the value only add extra code without certain efficiency improvement.

Signed-off-by: tison <[email protected]>
Comment on lines -110 to -111
log::Level::Info => fasyslog::Severity::INFORMATIONAL,
log::Level::Debug => fasyslog::Severity::DEBUG,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common mapping.

May or may not we can later add a custom mapping config, but only until there is real-world demand.

Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
@tisonkun tisonkun merged commit b12f378 into main Nov 14, 2024
9 checks passed
@tisonkun tisonkun deleted the journald branch November 14, 2024 02:30
@swsnr
Copy link

swsnr commented Nov 14, 2024

@tisonkun Why am I being mentioned here? I'm sorry but I'm entirely missing the context 🤔

@tisonkun
Copy link
Contributor Author

@swsnr I'm using your code from systemd-journal-logger.rs and here to share patches or ideas on these two TODOs in your code:

Perhaps open an issue/PR at systemd-journal-logger.rs a better choice .. Just found quoted code here can be easier to convey the background.

@swsnr
Copy link

swsnr commented Nov 14, 2024

Ah, thanks. That's the background I was missing. I'll take a look 🙏

If you can find the time to make a PR that be appreciated a lot 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support log to journald
2 participants