Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit 22b7db0

Browse files
authored
Merge pull request #260 from adamreese/feat/ansi-logging
feat(cli): only use ansi logging on tty
2 parents 4d6cf91 + 535638a commit 22b7db0

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ server = ["warp", "openid"]
3131
client = ["mime_guess", "dirs", "time"]
3232
caching = []
3333
test-tools = []
34-
cli = ["clap", "tracing-subscriber"]
34+
cli = ["clap", "tracing-subscriber", "atty"]
3535

3636
[package.metadata.docs.rs]
3737
all-features = true
@@ -75,6 +75,7 @@ openid = { version = "0.9.3", optional = true }
7575
bcrypt = "0.10.1"
7676
either = "1.6.1"
7777
time = { version = "0.3", features = ["serde"], optional = true }
78+
atty = {version = "0.2", optional = true}
7879

7980
# NOTE: This is a workaround due to a dependency issue in oauth2: https://github.com/tkaitchuck/ahash/issues/95#issuecomment-903560879
8081
indexmap = "~1.6.2"

bin/client/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ impl TokenManager for PickYourAuth {
7575
async fn run() -> std::result::Result<(), ClientError> {
7676
let opts = opts::Opts::parse();
7777
// TODO: Allow log level setting outside of RUST_LOG (this is easier with this subscriber)
78-
tracing_subscriber::fmt::init();
78+
tracing_subscriber::fmt()
79+
.with_writer(std::io::stderr)
80+
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
81+
.with_ansi(atty::is(atty::Stream::Stderr))
82+
.init();
7983
let bindle_dir = opts.bindle_dir.unwrap_or_else(|| {
8084
dirs::cache_dir()
8185
.expect("Unable to infer cache directory")

bin/server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ async fn main() -> anyhow::Result<()> {
157157
tracing_subscriber::fmt()
158158
.with_writer(std::io::stderr)
159159
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
160+
.with_ansi(atty::is(atty::Stream::Stderr))
160161
.init();
161162

162163
let config = merged_opts().await?;

0 commit comments

Comments
 (0)