diff --git a/src/syslog.rs b/src/syslog.rs index 85f3657224..12a3d5b324 100644 --- a/src/syslog.rs +++ b/src/syslog.rs @@ -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 + ?Sized>( +pub fn openlog( ident: Option<&S>, logopt: LogFlags, facility: Facility, -) -> Result<()> { +) -> Result<()> +where + S: AsRef + ?Sized, +{ let logopt = logopt.bits(); let facility = facility as libc::c_int; match ident.map(OsStr::new) { @@ -37,7 +40,7 @@ pub fn openlog + ?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 diff --git a/test/test_syslog.rs b/test/test_syslog.rs index 0f7aec6cca..ad83b1e5a9 100644 --- a/test/test_syslog.rs +++ b/test/test_syslog.rs @@ -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(); }