node/log: Define syslog identifier

The argument passed to `fn logger` would only be used as a fallback.
Make it required to pass an identifier, as this is a good practice.
This commit is contained in:
Lorenz Leutgeb 2025-10-01 09:54:36 +02:00
parent ee49e28766
commit 474b97950b
No known key found for this signature in database
2 changed files with 5 additions and 7 deletions

View File

@ -338,7 +338,8 @@ fn initialize_logging(options: &LogOptions) -> Result<(), Box<dyn std::error::Er
return Err(Box::new(JournalError::NotConnected));
}
logger::<&str, &str, _>("radicle-node".to_string(), []).map_err(Box::new)?
const SYSLOG_IDENTIFIER: &str = "radicle-node";
logger::<&str, &str, _>(SYSLOG_IDENTIFIER.to_string(), []).map_err(Box::new)?
}
Logger::Radicle => Box::new(radicle::logger::Logger::new(level)),
}

View File

@ -1,11 +1,8 @@
use systemd_journal_logger::{connected_to_journal, current_exe_identifier, JournalLog};
use systemd_journal_logger::{connected_to_journal, JournalLog};
/// If the current process is directly connected to the systemd journal,
/// return a logger that will write to it.
pub fn logger<K, V, I>(
default_identifier: String,
extra_fields: I,
) -> std::io::Result<Box<dyn log::Log>>
pub fn logger<K, V, I>(identifier: String, extra_fields: I) -> std::io::Result<Box<dyn log::Log>>
where
I: IntoIterator<Item = (K, V)>,
K: AsRef<str>,
@ -13,7 +10,7 @@ where
{
Ok(Box::new(
JournalLog::new()?
.with_syslog_identifier(current_exe_identifier().unwrap_or(default_identifier))
.with_syslog_identifier(identifier)
.with_extra_fields(extra_fields),
))
}