Skip to content

Commit

Permalink
feat: add better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Umatriz committed Jul 13, 2024
1 parent 63007c8 commit f93f986
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions crates/nomi-core/src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use std::path::Path;

use anyhow::anyhow;
use serde::{de::DeserializeOwned, Serialize};
use tokio::io::AsyncWriteExt;
use tracing::Level;

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()))]
pub async fn write_toml_config<T>(data: &T, path: impl AsRef<Path>) -> anyhow::Result<()>
where
T: Serialize + ?Sized,
Expand All @@ -16,6 +19,7 @@ where
Ok(())
}

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()))]
pub async fn read_toml_config<T>(path: impl AsRef<Path>) -> anyhow::Result<T>
where
T: DeserializeOwned + ?Sized,
Expand All @@ -30,6 +34,7 @@ where
Ok(body)
}

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()))]
pub fn read_toml_config_sync<T>(path: impl AsRef<Path>) -> anyhow::Result<T>
where
T: DeserializeOwned + ?Sized,
Expand All @@ -38,6 +43,7 @@ where
runtime.block_on(read_toml_config::<T>(path))
}

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()))]
pub fn write_toml_config_sync<T>(data: &T, path: impl AsRef<Path>) -> anyhow::Result<()>
where
T: Serialize + ?Sized,
Expand All @@ -50,10 +56,12 @@ pub async fn read_json_config<T>(path: impl AsRef<Path>) -> anyhow::Result<T>
where
T: DeserializeOwned + ?Sized,
{
let path = path.as_ref();
let s = tokio::fs::read_to_string(path).await?;
Ok(serde_json::from_str::<T>(&s)?)
}

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()), level = Level::DEBUG)]
pub async fn write_json_config<T>(data: &T, path: impl AsRef<Path>) -> anyhow::Result<()>
where
T: Serialize + ?Sized,
Expand All @@ -68,6 +76,7 @@ where
Ok(())
}

#[tracing::instrument(skip_all, fields(path = path.as_ref().to_string_lossy().to_string()))]
pub async fn write_to_file(data: &[u8], path: impl AsRef<Path>) -> anyhow::Result<()> {
let path = path.as_ref();
if let Some(dir) = path.parent() {
Expand Down
2 changes: 1 addition & 1 deletion crates/nomi-core/src/instance/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct LaunchInstance {
}

impl LaunchInstance {
#[tracing::instrument(err)]
#[tracing::instrument(skip(self), err)]
pub async fn delete(&self, delete_client: bool, delete_libraries: bool, delete_assets: bool) -> anyhow::Result<()> {
let manifest = read_json_config::<Manifest>(&self.settings.manifest_file).await?;
let arguments_builder = ArgumentsBuilder::new(self, &manifest).with_classpath();
Expand Down

0 comments on commit f93f986

Please sign in to comment.