-
Notifications
You must be signed in to change notification settings - Fork 672
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
Add syslog supports #2537
Add syslog supports #2537
Conversation
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
@SteveLauC I'd like to learn the following things:
|
Hi, thanks for the PR!
I am not quite sure I understand the question, you mean how to pick a feature? Putting these interfaces under the feature
Do you mean the conversion between the Nix wrapper types and the C types used by the libc crate?
A few tests to ensure the wrapper would work should be sufficient.
Yeah, it is ok. |
BTW, a changelog is needed, please see CONTRIBUTING.md on how to add one. |
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
This reverts commit 98289d5.
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
@SteveLauC Thanks for your information! All updated.
Updated.
Updated.
Reasonable.
No. As stated at #413 (comment), I think we just simply use Rust's formatting function and pass the formatted string. This is also how Python wraps syslog functionalities.
Included. |
This patch doesn't wrap For For |
Signed-off-by: tison <[email protected]>
#[macro_export]
macro_rules! LOG_MASK
{
($($arg:tt)*) => (
(1 << $($arg)*)
)
}
#[macro_export]
macro_rules! LOG_UPTO
{
($($arg:tt)*) => (
((1 << (($($arg)*) + 1)) - 1)
)
} But I'd like to wait for this patch getting review and perhaps did it in a followup so that we don't push everything at once. |
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
This comment was marked as resolved.
This comment was marked as resolved.
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
@SteveLauC test on unix and updated. I have an idea to implement pub fn setlogmask(maskpri: libc::c_int) -> libc::c_int {
let mask = unsafe { libc::setlogmask(maskpri) };
mask
}
pub fn log_mask(pri: Severity) -> libc::c_int {
1 << (pri as libc::c_int)
}
pub fn log_upto(pri: Severity) -> libc::c_int {
(1 << ((pri as libc::c_int) + 1)) - 1
} Also related test ideas - https://stackoverflow.com/questions/56049852/python-2-7-setlogmask0-not-disabling-syslog |
Signed-off-by: tison <[email protected]>
34dfe60
to
c98a454
Compare
src/syslog.rs
Outdated
/// Logging options of subsequent [`syslog`] calls can be set by calling [`openlog`]. | ||
/// | ||
/// The parameter `ident` is a string that will be prepended to every message. The `logopt` | ||
/// argument specifies logging options. The `facility` parameter encodes a default facility to be | ||
/// assigned to all messages that do not have an explicit facility encoded. | ||
pub fn openlog<S>( | ||
ident: Option<&S>, |
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.
This interface should be good for UNIXs other than Linux, since Linux would store the ident
pointer as-is (will be used during whole process lifetime), we need to add a separate interface for Linux, and gate this with #[cfg(not(target_os = "linux"))]
.
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 thanks for adding the Option here! I didn't catch it in my first round of review.
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.
I'd suggest we remove the ident
param for now.
It's not easy to just add Option<&'static str>
because it may not end with nul
and I don't know how to achieve this.
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.
I don't observe the ident
on macos and linux, perhaps this is because the allocated string is collected 🤣
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.
Maybe Option<&'static CStr>
. Let me try.
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.
Nix does not pursue uniform interfaces across OSes, if they are different, let them be different. I suggest keeping the original interface for non-Linux platforms as they are not constrained by this limit and adding a separate interface for Linux
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.
Could you send a patch to this PR or just edit this PR with the suggested change?
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.
Could you send a patch to this PR
Yeah, let me send a commit
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.
See 596280b
Signed-off-by: tison <[email protected]>
Co-authored-by: SteveLauC <[email protected]>
@SteveLauC Here is an open question on whether to include |
Regarding the /// System log priority mask.
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct LogMask(libc::c_int);
/// Set the process-wide priority mask to `mask` and return the previous mask
/// value.
///
/// Calls to `syslog()` with a priority level not set in `mask` are ignored. The
/// default is to log all priorities.
///
/// If the `mask` argument is `None`, the current logmask is not modified, this
/// can be used to query the current log mask.
pub fn setlogmask(mask: Option<LogMask>) -> LogMask {
let mask = match mask {
Some(mask) => mask.0,
None => 0,
};
let prev_mask = unsafe {
libc::setlogmask(mask)
};
LogMask(prev_mask)
}
impl LogMask {
/// Creates a mask of all priorities up to and including `priority`.
#[doc(alias("LOG_UPTO"))]
pub fn up_to(priority: Severity) -> Self {
todo!()
}
/// Creates a mask for the specified priority.
#[doc(alias("LOG_MASK"))]
pub fn of_priority(priority: Severity) -> Self {
todo!()
}
/// Returns if the mask for the specified `priority` is set.
pub fn contains(&self, priority: Severity) -> bool {
todo!()
}
}
impl std::ops::BitOr for LogMask {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0)
}
} Though I think the C macros |
Yes. Let's review this PR as is now. @SteveLauC Thanks for your following commits! |
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.
Looks good, thanks for the PR, let's merge it! 🚀
This refers to #413.
Hello world works locally:
I'd like to send this patch early for any necessary alignments.