Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fmt::Display instead of fmt::Debug in logging if possible #38

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions taxy/src/certs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl Cert {
let cert = match rcgen::Certificate::from_params(params) {
Ok(cert) => cert,
Err(err) => {
error!(?err);
error!(%err);
return Err(Error::FailedToGerateSelfSignedCertificate);
}
};
Expand All @@ -249,7 +249,7 @@ impl Cert {
let ca_cert = match rcgen::Certificate::from_params(ca_params) {
Ok(cert) => cert,
Err(err) => {
error!(?err);
error!(%err);
return Err(Error::FailedToGerateSelfSignedCertificate);
}
};
Expand Down Expand Up @@ -278,7 +278,7 @@ impl Cert {
let cert = match rcgen::Certificate::from_params(params) {
Ok(cert) => cert,
Err(err) => {
error!(?err);
error!(%err);
return Err(Error::FailedToGerateSelfSignedCertificate);
}
};
Expand All @@ -301,7 +301,7 @@ impl Cert {
match self.certified_impl() {
Ok(certified) => Ok(certified),
Err(err) => {
error!(?err);
error!(%err);
Err(Error::FailedToReadPrivateKey)
}
}
Expand Down
22 changes: 11 additions & 11 deletions taxy/src/config/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl FileStorage {
let mut doc = match self.load_document(path).await {
Ok(doc) => doc,
Err(err) => {
warn!(?path, ?err, "failed to load config");
warn!(?path, %err, "failed to load config");
Document::new()
}
};
Expand Down Expand Up @@ -127,7 +127,7 @@ impl FileStorage {
let mut doc = match self.load_document(path).await {
Ok(doc) => doc,
Err(err) => {
warn!(?path, ?err, "failed to load config");
warn!(?path, %err, "failed to load config");
Document::new()
}
};
Expand Down Expand Up @@ -168,7 +168,7 @@ impl FileStorage {
let mut doc = match self.load_document(path).await {
Ok(doc) => doc,
Err(err) => {
warn!(?path, ?err, "failed to load config");
warn!(?path, %err, "failed to load config");
Document::new()
}
};
Expand All @@ -187,7 +187,7 @@ impl FileStorage {
let mut doc = match self.load_document(path).await {
Ok(doc) => doc,
Err(err) => {
warn!(?path, ?err, "failed to load config");
warn!(?path, %err, "failed to load config");
Document::new()
}
};
Expand Down Expand Up @@ -309,30 +309,30 @@ impl FileStorage {
let accounts = match self.load_accounts().await {
Ok(accounts) => accounts,
Err(err) => {
error!(?err, "failed to load accounts: {err}");
error!(%err, "failed to load accounts: {err}");
return Err(Error::InvalidLoginCredentials);
}
};

let account = match accounts.get(name) {
Some(account) => account,
None => {
error!(?name, "account not found: {name}");
error!(%name, "account not found: {name}");
return Err(Error::InvalidLoginCredentials);
}
};

let parsed_hash = match PasswordHash::new(&account.password) {
Ok(parsed_hash) => parsed_hash,
Err(err) => {
error!(?err, "failed to parse password hash: {err}");
error!(%err, "failed to parse password hash: {err}");
return Err(Error::InvalidLoginCredentials);
}
};

let argon2 = Argon2::default();
if let Err(err) = argon2.verify_password(password.as_bytes(), &parsed_hash) {
error!(?err, "failed to verify password: {err}");
error!(%err, "failed to verify password: {err}");
return Err(Error::InvalidLoginCredentials);
}

Expand All @@ -347,15 +347,15 @@ impl FileStorage {
let accounts = match self.load_accounts().await {
Ok(accounts) => accounts,
Err(err) => {
error!(?err, "failed to load accounts: {err}");
error!(%err, "failed to load accounts: {err}");
return Err(Error::InvalidLoginCredentials);
}
};

let account = match accounts.get(name) {
Some(account) => account,
None => {
error!(?name, "account not found: {name}");
error!(%name, "account not found: {name}");
return Err(Error::InvalidLoginCredentials);
}
};
Expand All @@ -365,7 +365,7 @@ impl FileStorage {
.to_bytes()
.map_err(|_| Error::InvalidLoginCredentials)?,
None => {
error!(?name, "totp not found: {name}");
error!(%name, "totp not found: {name}");
return Err(Error::InvalidLoginCredentials);
}
};
Expand Down
7 changes: 6 additions & 1 deletion taxy/src/proxy/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ pub struct HttpPortContext {

impl HttpPortContext {
pub fn new(entry: &PortEntry) -> Result<Self, Error> {
let span = span!(Level::INFO, "proxy", resource_id = entry.id.to_string(), listen = ?entry.port.listen);
let span = span!(
Level::INFO,
"proxy",
resource_id = entry.id.to_string(),
listen = %entry.port.listen
);
let enter = span.clone();
let _enter = enter.enter();

Expand Down
2 changes: 1 addition & 1 deletion taxy/src/proxy/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct TcpPortContext {

impl TcpPortContext {
pub fn new(entry: &PortEntry) -> Result<Self, Error> {
let span = span!(Level::INFO, "proxy", resource_id = entry.id.to_string(), listen = ?entry.port.listen);
let span = span!(Level::INFO, "proxy", resource_id = entry.id.to_string(), listen = %entry.port.listen);
let enter = span.clone();
let _enter = enter.enter();

Expand Down
10 changes: 5 additions & 5 deletions taxy/src/server/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl ServerState {
ports.update(ctx);
}
Err(err) => {
error!(?err, "failed to create proxy state");
error!(%err, "failed to create proxy state");
}
};
}
Expand Down Expand Up @@ -260,15 +260,15 @@ impl ServerState {
.await
{
span.in_scope(|| {
error!(?err, "failed to setup port");
error!(%err, "failed to setup port");
});
}
}
}

pub async fn run_background_tasks(&mut self, app_info: &AppInfo) {
if let Err(err) = self.cleanup_old_logs(app_info).await {
error!(?err, "failed to cleanup old logs");
error!(%err, "failed to cleanup old logs");
}

self.start_http_challenges().await;
Expand All @@ -292,7 +292,7 @@ impl ServerState {
}
for id in &removing_items {
if let Err(err) = self.certs.delete(*id) {
error!(?err, "failed to delete cert");
error!(%err, "failed to delete cert");
}
}
if !removing_items.is_empty() {
Expand Down Expand Up @@ -398,7 +398,7 @@ impl ServerState {
}
Err(err) => {
let _enter = span.enter();
error!(?err, "failed to start challenge");
error!(%err, "failed to start challenge");
}
}
}
Expand Down
Loading