-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
--debug
option for logging and backtraces
Add `env_logger` to be able to print the logs that our libraries already generate. Add some logging to the application code. We'll probably want more log messages, and we might want to upgrade some of them from trace to debug. Add a `--debug` flag that automatically enables `env_logger` as well as backtraces for `anyhow` and panics. ```console $ xh --debug : [2024-06-05T13:54:40Z DEBUG xh] xh 0.22.0 -native-tls +rustls [2024-06-05T13:54:40Z DEBUG xh] Cli { httpie_compat_mode: false, [...] } [2024-06-05T13:54:40Z DEBUG xh] Complete URL: http://localhost/ [2024-06-05T13:54:40Z DEBUG xh] HTTP method: GET [2024-06-05T13:54:40Z DEBUG reqwest::connect] starting new connection: http://localhost/ [2024-06-05T13:54:40Z DEBUG hyper_util::client::legacy::connect::dns] resolving host="localhost" [...] xh: error: error sending request for url (http://localhost/) Caused by: 0: client error (Connect) 1: tcp connect error: Connection refused (os error 111) 2: Connection refused (os error 111) Stack backtrace: 0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.82/src/error.rs:565:25 [...] ``` We could ask users to post `--debug` output when reporting bugs.
- Loading branch information
Showing
17 changed files
with
235 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::ffi::OsString; | ||
use std::fmt::{self, Debug}; | ||
use std::ops::Deref; | ||
use std::str::FromStr; | ||
|
||
/// A String that doesn't show up in Debug representations. | ||
/// | ||
/// This is important for logging, where we maybe want to avoid outputting | ||
/// sensitive data. | ||
#[derive(Clone, PartialEq, Eq)] | ||
pub struct SecretString(String); | ||
|
||
impl FromStr for SecretString { | ||
type Err = std::convert::Infallible; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Ok(Self(s.to_owned())) | ||
} | ||
} | ||
|
||
impl Deref for SecretString { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &String { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl Debug for SecretString { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
// Uncomment this to see the string anyway: | ||
// self.0.fmt(f); | ||
// If that turns out to be frequently necessary we could | ||
// make this configurable at runtime, e.g. by flipping an | ||
// AtomicBool depending on an environment variable. | ||
f.write_str("(redacted)") | ||
} | ||
} | ||
|
||
impl From<SecretString> for OsString { | ||
fn from(string: SecretString) -> OsString { | ||
string.0.into() | ||
} | ||
} |
Oops, something went wrong.