-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
Signed-off-by: tison <[email protected]>
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; | ||
} | ||
} |
There was a problem hiding this comment.
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.
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(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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]>
log::Level::Info => fasyslog::Severity::INFORMATIONAL, | ||
log::Level::Debug => fasyslog::Severity::DEBUG, |
There was a problem hiding this comment.
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 Why am I being mentioned here? I'm sorry but I'm entirely missing the context 🤔 |
@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 |
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 😊 |
This fixes #76