Skip to content

Commit 24f25db

Browse files
authored
feat(console): feature-flag tracing-journald dependency (#250)
`tracing-journald` depends on relatively recent libc APIs that may not be available on all Linux distros (see #248). Journald support is primarily used for internal debugging of the `tokio-console` API, so many users may not need journald support, even if they are on a compatible Linux distro. Therefore, this commit makes it an off-by-default optional dependency, so that it can be enabled only when needed.
1 parent 931001a commit 24f25db

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

console/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ futures = "0.3"
3535
tui = { version = "0.16.0", default-features = false, features = ["crossterm"] }
3636
tracing = "0.1"
3737
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
38-
tracing-journald = "0.2"
38+
tracing-journald = { version = "0.2", optional = true }
3939
prost-types = "0.9"
4040
crossterm = { version = "0.20", features = ["event-stream"] }
4141
color-eyre = { version = "0.5", features = ["issue-url"] }

console/src/config.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,17 @@ impl Config {
127127

128128
// If we're on a Linux distro with journald, try logging to the system
129129
// journal so we don't interfere with text output.
130-
let journald = tracing_journald::layer().ok();
130+
#[cfg(all(feature = "tracing-journald", target_os = "linux"))]
131+
let (journald, should_fmt) = {
132+
let journald = tracing_journald::layer().ok();
133+
(journald, journald.is_some())
134+
};
135+
136+
#[cfg(not(all(feature = "tracing-journald", target_os = "linux")))]
137+
let should_fmt = true;
131138

132139
// Otherwise, log to stderr and rely on the user redirecting output.
133-
let fmt = if journald.is_none() {
140+
let fmt = if should_fmt {
134141
Some(
135142
tracing_subscriber::fmt::layer()
136143
.with_writer(std::io::stderr)
@@ -140,11 +147,12 @@ impl Config {
140147
None
141148
};
142149

143-
tracing_subscriber::registry()
144-
.with(journald)
145-
.with(fmt)
146-
.with(filter)
147-
.try_init()?;
150+
let registry = tracing_subscriber::registry().with(fmt).with(filter);
151+
152+
#[cfg(all(feature = "tracing-journald", target_os = "linux"))]
153+
let registry = registry.with(journald);
154+
155+
registry.try_init()?;
148156

149157
Ok(())
150158
}

0 commit comments

Comments
 (0)