Skip to content

Commit

Permalink
Changed to Json logs & improved some events
Browse files Browse the repository at this point in the history
  • Loading branch information
CEbbinghaus committed Feb 17, 2024
1 parent a53ae7b commit 7a2fdf3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
13 changes: 13 additions & 0 deletions backend/Cargo.lock

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

2 changes: 1 addition & 1 deletion backend/Cargo.toml
Expand Up @@ -28,7 +28,7 @@ toml = "0.8.8"
anyhow = "1.0.79"
lazy_static = "1.4.0"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
tracing-subscriber = { version = "0.3.18", features = ["json"] }

[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }
Expand Down
4 changes: 2 additions & 2 deletions backend/src/log.rs
@@ -1,5 +1,4 @@
use std::fs::File;

use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::Layer;
Expand All @@ -9,7 +8,8 @@ use crate::{get_file_path_and_create_directory, LOG_DIR};
pub fn create_subscriber() {
let log_file_path = get_file_path_and_create_directory(&CONFIG.log_file, &LOG_DIR).expect("Log file to be created");
let file = File::create(log_file_path).expect("Log file to be created");
let mut file_writer = tracing_subscriber::fmt::layer().with_writer(file);

let mut file_writer = tracing_subscriber::fmt::layer().json().with_writer(file);

file_writer.set_ansi(false);

Expand Down
8 changes: 4 additions & 4 deletions backend/src/main.rs
Expand Up @@ -75,7 +75,7 @@ async fn main() {
),
);

debug!("Loading from store {:?}", store_path);
debug!(store_path = store_path.to_str(), "Loading from store");
let store: Arc<Store> =
Arc::new(Store::read_from_file(store_path.clone()).unwrap_or(Store::new(Some(store_path))));

Expand All @@ -100,17 +100,17 @@ async fn main() {
select! {
result = server_future => match result {
Ok(_) => info!("Server ran to completion..."),
Err(err) => error!("Server exited with error: {err}")
Err(err) => error!(error = %err.to_string(), "Server exited with error")
},
result = watch_future => match result {
Ok(_) => info!("Watch ran to completion.."),
Err(err) => error!("Watch exited with error: {err}"),
Err(err) => error!(error = %err.to_string(), "Watch exited with error"),
},
};

info!("Saving Database");
if let Err(err) = store.write_to_file() {
error!("Failed to write datastore to file {err}");
error!(error = %err.to_string(), "Failed to write datastore to file");
}

info!("Exiting...");
Expand Down

0 comments on commit 7a2fdf3

Please sign in to comment.