From 308c503f0912c35ef6ed199b2ffdc99e0ab36eca Mon Sep 17 00:00:00 2001 From: Ellis Haker Date: Mon, 27 May 2024 20:19:42 -0700 Subject: [PATCH 1/5] changed default log file to ~/.odilia.log --- Cargo.lock | 33 ++++++++++++++++++++++++++++++--- common/Cargo.toml | 1 + common/src/settings/log.rs | 12 ++++++++---- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 089551d5..91d9714b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -835,7 +835,16 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" dependencies = [ - "dirs-sys", + "dirs-sys 0.3.7", +] + +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys 0.4.1", ] [[package]] @@ -859,6 +868,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -1601,7 +1622,6 @@ dependencies = [ name = "odilia-cache" version = "0.3.0" dependencies = [ - "async-trait", "atspi", "atspi-client", "atspi-common 0.5.0", @@ -1628,6 +1648,7 @@ dependencies = [ "atspi", "atspi-common 0.5.0", "bitflags 1.3.2", + "dirs 5.0.1", "figment", "serde", "serde_plain", @@ -1690,6 +1711,12 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "ordered-stream" version = "0.2.0" @@ -2236,7 +2263,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d20c8da60d51225982d675776f18b55c6bd41763b01c03f431190e0ad99c9dbf" dependencies = [ "async-std", - "dirs", + "dirs 4.0.0", "log", "ssip-common", "strum", diff --git a/common/Cargo.toml b/common/Cargo.toml index 65ca163f..ee98b43b 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -21,3 +21,4 @@ thiserror = "1.0.37" zbus.workspace = true serde_plain.workspace = true figment = "0.10.15" +dirs = "5.0.1" diff --git a/common/src/settings/log.rs b/common/src/settings/log.rs index d687f976..d927b89b 100644 --- a/common/src/settings/log.rs +++ b/common/src/settings/log.rs @@ -1,3 +1,4 @@ +use dirs::home_dir; use std::path::PathBuf; use serde::{Deserialize, Serialize}; @@ -16,10 +17,13 @@ pub struct LogSettings { } impl Default for LogSettings { fn default() -> Self { - Self { - level: "info".to_owned(), - logger: LoggingKind::File("/var/log/odilia.log".into()), - } + let mut log_path = match home_dir() { + Some(dir) => dir, + None => ".".into(), + }; + log_path.push("odilia.log"); + + Self { level: "info".to_owned(), logger: LoggingKind::File(log_path) } } } From 699ed537feb8a790eb27b1e1b94db3923cc6c5be Mon Sep 17 00:00:00 2001 From: Ellis Haker Date: Tue, 28 May 2024 16:13:55 -0700 Subject: [PATCH 2/5] updated to use env instead of dirs home_dir, need to create odilia directory in .local/share --- Cargo.lock | 32 ++------------------------------ common/Cargo.toml | 1 - common/src/settings/log.rs | 19 ++++++++++++------- 3 files changed, 14 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 91d9714b..50819897 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -835,16 +835,7 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" dependencies = [ - "dirs-sys 0.3.7", -] - -[[package]] -name = "dirs" -version = "5.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" -dependencies = [ - "dirs-sys 0.4.1", + "dirs-sys", ] [[package]] @@ -868,18 +859,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "dirs-sys" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" -dependencies = [ - "libc", - "option-ext", - "redox_users", - "windows-sys 0.48.0", -] - [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -1648,7 +1627,6 @@ dependencies = [ "atspi", "atspi-common 0.5.0", "bitflags 1.3.2", - "dirs 5.0.1", "figment", "serde", "serde_plain", @@ -1711,12 +1689,6 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" -[[package]] -name = "option-ext" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" - [[package]] name = "ordered-stream" version = "0.2.0" @@ -2263,7 +2235,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d20c8da60d51225982d675776f18b55c6bd41763b01c03f431190e0ad99c9dbf" dependencies = [ "async-std", - "dirs 4.0.0", + "dirs", "log", "ssip-common", "strum", diff --git a/common/Cargo.toml b/common/Cargo.toml index ee98b43b..65ca163f 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -21,4 +21,3 @@ thiserror = "1.0.37" zbus.workspace = true serde_plain.workspace = true figment = "0.10.15" -dirs = "5.0.1" diff --git a/common/src/settings/log.rs b/common/src/settings/log.rs index d927b89b..174b31d2 100644 --- a/common/src/settings/log.rs +++ b/common/src/settings/log.rs @@ -1,5 +1,7 @@ -use dirs::home_dir; -use std::path::PathBuf; +use std::{ + env, + path::PathBuf, +}; use serde::{Deserialize, Serialize}; ///structure used for all the configurable options related to logging @@ -17,12 +19,15 @@ pub struct LogSettings { } impl Default for LogSettings { fn default() -> Self { - let mut log_path = match home_dir() { - Some(dir) => dir, - None => ".".into(), + let mut log_path = PathBuf::new(); + match env::var("XDG_DATA_HOME") { + Ok(dir) => log_path.push(dir), + Err(_e) => { + log_path.push(env::var("HOME").unwrap()); + log_path.push(".local/share"); + }, // TODO: error message? }; - log_path.push("odilia.log"); - + log_path.push("/odilia/odilia.log"); Self { level: "info".to_owned(), logger: LoggingKind::File(log_path) } } } From a2833fd8996380ce5902a2dae01a0fd996af9a9e Mon Sep 17 00:00:00 2001 From: Ellis Haker Date: Wed, 29 May 2024 09:12:07 -0700 Subject: [PATCH 3/5] changed log file to XDG_DATA --- Cargo.lock | 1 + common/Cargo.toml | 1 + common/src/settings/log.rs | 24 ++++++++++-------------- odilia/src/logging.rs | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50819897..f66fef1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1632,6 +1632,7 @@ dependencies = [ "serde_plain", "smartstring", "thiserror", + "xdg", "zbus", ] diff --git a/common/Cargo.toml b/common/Cargo.toml index 65ca163f..ffdbd648 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -21,3 +21,4 @@ thiserror = "1.0.37" zbus.workspace = true serde_plain.workspace = true figment = "0.10.15" +xdg = "2.4.1" diff --git a/common/src/settings/log.rs b/common/src/settings/log.rs index 174b31d2..59208b8f 100644 --- a/common/src/settings/log.rs +++ b/common/src/settings/log.rs @@ -1,9 +1,6 @@ -use std::{ - env, - path::PathBuf, -}; - use serde::{Deserialize, Serialize}; +use std::path::PathBuf; + ///structure used for all the configurable options related to logging #[derive(Debug, Serialize, Deserialize)] #[allow(clippy::module_name_repetitions)] @@ -19,15 +16,14 @@ pub struct LogSettings { } impl Default for LogSettings { fn default() -> Self { - let mut log_path = PathBuf::new(); - match env::var("XDG_DATA_HOME") { - Ok(dir) => log_path.push(dir), - Err(_e) => { - log_path.push(env::var("HOME").unwrap()); - log_path.push(".local/share"); - }, // TODO: error message? - }; - log_path.push("/odilia/odilia.log"); + let xdg_dirs = xdg::BaseDirectories::with_prefix("odilia").expect( + "unable to find the odilia config directory according to the xdg dirs specification", + ); + let log_path = xdg_dirs + .place_data_file("odilia.log") + .expect("unable to place log file"); + + // TODO: what if config file does not exist? Self { level: "info".to_owned(), logger: LoggingKind::File(log_path) } } } diff --git a/odilia/src/logging.rs b/odilia/src/logging.rs index 278b7387..653447f5 100644 --- a/odilia/src/logging.rs +++ b/odilia/src/logging.rs @@ -27,14 +27,14 @@ pub fn init(config: &ApplicationConfig) -> eyre::Result<()> { //this requires boxing because the types returned by this match block would be incompatible otherwise, since we return different layers depending on what we get from the configuration. It is possible to do it otherwise, hopefully, but for now this and a forced dereference at the end would do let output_layer = match &config.log.logger { LoggingKind::File(path) => { - let file = std::fs::File::options() + let file = std::fs::File::options() .create_new(true) .write(true) .open(path) .with_context(|| { format!("creating log file '{}'", path.display()) })?; - let fmt = + let fmt = tracing_subscriber::fmt::layer().with_ansi(false).with_writer(file); fmt.boxed() } From 8fd2a7f9aef4b7171043b54840fe47012b7d0e27 Mon Sep 17 00:00:00 2001 From: Ellis Haker Date: Wed, 29 May 2024 11:55:16 -0700 Subject: [PATCH 4/5] removed TODOs --- common/src/settings/log.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/common/src/settings/log.rs b/common/src/settings/log.rs index 59208b8f..f222ecf2 100644 --- a/common/src/settings/log.rs +++ b/common/src/settings/log.rs @@ -23,7 +23,6 @@ impl Default for LogSettings { .place_data_file("odilia.log") .expect("unable to place log file"); - // TODO: what if config file does not exist? Self { level: "info".to_owned(), logger: LoggingKind::File(log_path) } } } From 42a84b96c3a6cde751bedc7b55eb6cf11f0be00a Mon Sep 17 00:00:00 2001 From: Ellis Haker Date: Wed, 29 May 2024 12:31:20 -0700 Subject: [PATCH 5/5] changed log path --- common/src/settings/log.rs | 8 ++++---- odilia/src/logging.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/src/settings/log.rs b/common/src/settings/log.rs index f222ecf2..b717440f 100644 --- a/common/src/settings/log.rs +++ b/common/src/settings/log.rs @@ -16,12 +16,12 @@ pub struct LogSettings { } impl Default for LogSettings { fn default() -> Self { - let xdg_dirs = xdg::BaseDirectories::with_prefix("odilia").expect( + let xdg_dirs = xdg::BaseDirectories::with_prefix("odilia").expect( "unable to find the odilia config directory according to the xdg dirs specification", ); - let log_path = xdg_dirs - .place_data_file("odilia.log") - .expect("unable to place log file"); + let log_path = xdg_dirs + .place_state_file("odilia.log") + .expect("unable to place log file"); Self { level: "info".to_owned(), logger: LoggingKind::File(log_path) } } diff --git a/odilia/src/logging.rs b/odilia/src/logging.rs index 653447f5..278b7387 100644 --- a/odilia/src/logging.rs +++ b/odilia/src/logging.rs @@ -27,14 +27,14 @@ pub fn init(config: &ApplicationConfig) -> eyre::Result<()> { //this requires boxing because the types returned by this match block would be incompatible otherwise, since we return different layers depending on what we get from the configuration. It is possible to do it otherwise, hopefully, but for now this and a forced dereference at the end would do let output_layer = match &config.log.logger { LoggingKind::File(path) => { - let file = std::fs::File::options() + let file = std::fs::File::options() .create_new(true) .write(true) .open(path) .with_context(|| { format!("creating log file '{}'", path.display()) })?; - let fmt = + let fmt = tracing_subscriber::fmt::layer().with_ansi(false).with_writer(file); fmt.boxed() }