| |
type Error = Box<dyn std::error::Error>;
|
| |
|
| |
let logger: Result<Option<Logger>, Error> = {
|
| - |
#[cfg(all(feature = "systemd", target_os = "linux"))]
|
| - |
{
|
| - |
use thiserror::Error;
|
| - |
|
| - |
#[derive(Error, Debug)]
|
| - |
#[error("Error connecting to systemd journal: {0}")]
|
| - |
struct JournalError(io::Error);
|
| - |
|
| - |
radicle_systemd::journal::logger::<&str, &str, _>("radicle-node".to_string(), [])
|
| - |
.map_err(|err| Box::new(JournalError(err)) as Error)
|
| - |
}
|
| - |
#[cfg(feature = "structured-logger")]
|
| - |
{
|
| - |
use structured_logger::{json, Builder};
|
| + |
match log_format {
|
| + |
#[cfg(feature = "structured-logger")]
|
| + |
LogFormat::Json => {
|
| + |
use structured_logger::{json, Builder};
|
| |
|
| - |
match log_format {
|
| - |
LogFormat::Json => Ok(Some(Box::new(
|
| + |
Ok(Some(Box::new(
|
| |
Builder::new()
|
| |
.with_default_writer(json::new_writer(io::stdout()))
|
| |
.build(),
|
| - |
))),
|
| - |
_ => Ok(None),
|
| + |
)))
|
| + |
}
|
| + |
_ => {
|
| + |
#[cfg(all(feature = "systemd", target_os = "linux"))]
|
| + |
{
|
| + |
use thiserror::Error;
|
| + |
|
| + |
#[derive(Error, Debug)]
|
| + |
#[error("Error connecting to systemd journal: {0}")]
|
| + |
struct JournalError(io::Error);
|
| + |
|
| + |
radicle_systemd::journal::logger::<&str, &str, _>(
|
| + |
"radicle-node".to_string(),
|
| + |
[],
|
| + |
)
|
| + |
.map_err(|err| Box::new(JournalError(err)) as Error)
|
| + |
}
|
| + |
#[cfg(not(all(feature = "systemd", target_os = "linux")))]
|
| + |
{
|
| + |
// This is constant, and `rustc` will hopefully use it to
|
| + |
// optimize away the `match` below.
|
| + |
Ok(None)
|
| + |
}
|
| |
}
|
| - |
}
|
| - |
#[cfg(not(any(
|
| - |
feature = "structured-logger",
|
| - |
all(feature = "systemd", target_os = "linux")
|
| - |
)))]
|
| - |
{
|
| - |
// This is constant, and `rustc` will hopefully use it to
|
| - |
// optimize away the `match` below.
|
| - |
Ok(None)
|
| |
}
|
| |
};
|
| |
|