Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Nov 16, 2024
1 parent 169b5d0 commit 0c61a95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ use std::ffi::OsStr;
/// 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: AsRef<OsStr> + ?Sized>(
pub fn openlog<S>(
ident: Option<&S>,
logopt: LogFlags,
facility: Facility,
) -> Result<()> {
) -> Result<()>
where
S: AsRef<OsStr> + ?Sized,
{
let logopt = logopt.bits();
let facility = facility as libc::c_int;
match ident.map(OsStr::new) {
Expand All @@ -37,7 +40,7 @@ pub fn openlog<S: AsRef<OsStr> + ?Sized>(
/// ```rust
/// use nix::syslog::{openlog, syslog, Facility, LogFlags, Severity};
///
/// openlog(None, LogFlags::LOG_PID, Facility::LOG_USER).unwrap();
/// openlog(None::<&str>, LogFlags::LOG_PID, Facility::LOG_USER).unwrap();
/// syslog(Severity::LOG_EMERG, "Hello, nix!").unwrap();
///
/// // use `format!` to format the message
Expand Down
5 changes: 4 additions & 1 deletion test/test_syslog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use nix::syslog::{openlog, syslog, Facility, LogFlags, Severity};

#[test]
fn test_syslog_hello_world() {
openlog(None, LogFlags::LOG_PID, Facility::LOG_USER).unwrap();
openlog(None::<&str>, LogFlags::LOG_PID, Facility::LOG_USER).unwrap();
syslog(Severity::LOG_EMERG, "Hello, nix!").unwrap();

let name = "syslog";
syslog(Severity::LOG_NOTICE, &format!("Hello, {name}!")).unwrap();
}

0 comments on commit 0c61a95

Please sign in to comment.