Skip to content

Commit

Permalink
refactor: Switch to tracing for logs
Browse files Browse the repository at this point in the history
  • Loading branch information
PotentialStyx committed Feb 4, 2024
1 parent ba3b35a commit e2d61d0
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 147 deletions.
92 changes: 52 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ verify_connections = ["dep:hyper", "dep:hyper-tls", "dep:hyper-util", "dep:http-
[dependencies]
goval = { path = "protobuf", package = "protobuf" }
homeval_services = { path = "services", package = "services" }
env_logger = { git = "https://github.com/tmccombs/env_logger", rev = "a47d1d99", features=["kv_unstable"] }
tracing = "0.1.40"
tracing-futures = "0.2.5"
tracing-subscriber = { version = "0.3.18", features = ["tracing-log"]}
futures-channel = "0.3.26"
futures-util = "0.3.26"
log = { version = "0.4.17", features = ["kv_unstable", "kv_unstable_serde"] }
Expand Down
3 changes: 2 additions & 1 deletion services/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ crc32fast = { version = "1.3.2", features = ["nightly"] }
deadqueue = { version = "0.2.4", default-features = false, features = ["unlimited"] }
futures-util = "0.3.28"
goval = { package = "protobuf", path = "../protobuf"}
log = { version = "0.4.17", features = ["kv_unstable", "kv_unstable_serde"] }
notify-debouncer-full = { version = "0.3.1", default-features = false }
portable-pty = "0.8.1"
prost = "0.12.3"
Expand All @@ -22,6 +21,8 @@ serde = "1.0.196"
serde_json = "1.0.112"
similar = "2.2.1"
tokio = "1.28.2"
tracing = "0.1.40"
tracing-futures = "0.2.5"

[lib]
name = "services"
Expand Down
4 changes: 2 additions & 2 deletions services/src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{ClientInfo, IPCMessage, SendSessions};
use super::traits;
use anyhow::{format_err, Result};
use async_trait::async_trait;
use log::{as_debug, warn};
use tracing::warn;

impl Chat {
pub fn new() -> Chat {
Expand Down Expand Up @@ -45,7 +45,7 @@ impl traits::Service for Chat {
Ok(None)
}
_ => {
warn!(cmd = as_debug!(message); "Unknown chat command");
warn!(cmd = ?message, "Unknown chat command");
Ok(None)
}
}
Expand Down
8 changes: 4 additions & 4 deletions services/src/gcsfiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pub struct GCSFiles {}
use super::traits;
use anyhow::{format_err, Result};
use async_trait::async_trait;
use log::{as_debug, as_error, debug, warn};
use tokio::{fs, io::AsyncWriteExt};
use tracing::{debug, warn};

#[async_trait]
impl traits::Service for GCSFiles {
Expand Down Expand Up @@ -58,7 +58,7 @@ impl traits::Service for GCSFiles {
Ok(Some(ret))
}
goval::command::Body::Read(file) => {
debug!(path = file.path; "File path");
debug!(path = file.path, "File path");
let contents = match file.path.as_str() {
// TODO: Read this from in the db
".env" => vec![],
Expand All @@ -78,7 +78,7 @@ impl traits::Service for GCSFiles {
}
_ => match fs::read(&file.path).await {
Err(err) => {
warn!(error = as_error!(err); "Error reading file in gcsfiles");
warn!(error = %err, "Error reading file in gcsfiles");
let ret = goval::Command {
body: Some(goval::command::Body::Error(format!(
"{}: no such file or directory",
Expand Down Expand Up @@ -153,7 +153,7 @@ impl traits::Service for GCSFiles {
Ok(None)
}
_ => {
warn!(cmd = as_debug!(message); "Unknown gcsfiles command");
warn!(cmd = ?message, "Unknown gcsfiles command");
Ok(None)
}
}
Expand Down
11 changes: 7 additions & 4 deletions services/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::ReplspaceMessage;
use super::traits;
use anyhow::{format_err, Result};
use async_trait::async_trait;
use log::{as_debug, warn};
use tokio::sync::mpsc::Sender;
use tracing::warn;

#[async_trait]
impl traits::Service for Git {
Expand All @@ -35,7 +35,7 @@ impl traits::Service for Git {
}
}
None => {
warn!(msg = as_debug!(message), nonce = token.nonce; "Missing replspace response callback for github token");
warn!(msg = ?message, nonce = token.nonce, "Missing replspace response callback for github token");
}
}
}
Expand All @@ -47,7 +47,7 @@ impl traits::Service for Git {
}
}
None => {
warn!(msg = as_debug!(message), nonce = close.nonce; "Missing replspace response callback for close file");
warn!(msg = ?message, nonce = close.nonce, "Missing replspace response callback for close file");
}
}
}
Expand All @@ -65,7 +65,10 @@ impl traits::Service for Git {
respond: Option<Sender<ReplspaceMessage>>,
) -> Result<()> {
if session == 0 {
warn!(msg = as_debug!(msg); "Got replspace message from an unknown session, ignoring");
warn!(
?msg,
"Got replspace message from an unknown session, ignoring"
);
return Ok(());
}

Expand Down
7 changes: 3 additions & 4 deletions services/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ mod types;

use anyhow::format_err;
use anyhow::Result;
use log::as_display;
use log::error;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
use tracing::error;
pub use types::*;

pub struct Channel {
Expand Down Expand Up @@ -88,7 +87,7 @@ impl Channel {
ChannelMessage::Shutdown => match self._inner.shutdown(&self.info).await {
Ok(_) => break,
Err(err) => {
error!(error = as_display!(err); "Error encountered in Service#shutdown");
error!(%err, "Error encountered in Service#shutdown");
break;
}
},
Expand All @@ -101,7 +100,7 @@ impl Channel {
match result {
Ok(_) => {}
Err(err) => {
error!(error = as_display!(err); "Error encountered in service")
error!(%err, "Error encountered in service")
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions services/src/ot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use crate::{client::ClientInfo, fs_watcher::FSWatcher, FSEvent, IPCMessage};
use super::traits;
use anyhow::{format_err, Result};
use async_trait::async_trait;
use log::{as_debug, debug, error, trace, warn};
use similar::TextDiff;
use tokio::fs;
use tracing::{debug, error, trace, warn};

impl OT {
pub async fn new(
Expand Down Expand Up @@ -309,17 +309,22 @@ impl traits::Service for OT {
Ok(Some(ok))
}
_ => {
warn!(cmd = as_debug!(message); "Unknown ot command");
warn!(cmd = ?message, "Unknown ot command");
Ok(None)
}
}
}

async fn fsevent(&mut self, info: &super::types::ChannelInfo, event: FSEvent) -> Result<()> {
trace!(event = as_debug!(event), file_path = self.path; "fs event");
trace!(?event, file_path = self.path, "fs event");
match event {
FSEvent::Modify(path) => {
trace!(condition = (path == self.path), path = path, file_path = self.path; "Conditional time");
trace!(
condition = (path == self.path),
path = path,
file_path = self.path,
"Conditional time"
);
if path == self.path {
let new_contents = fs::read(&path).await?;

Expand Down Expand Up @@ -369,11 +374,11 @@ impl traits::Service for OT {
Ok(())
}
FSEvent::Err(err) => {
error!(error = err; "Error in FS event listener");
error!(err, "Error in FS event listener");
Ok(())
}
_ => {
debug!(message = as_debug!(event); "Ignoing FS event");
debug!(message = ?event, "Ignoing FS event");
Ok(())
}
}
Expand Down
Loading

0 comments on commit e2d61d0

Please sign in to comment.