summaryrefslogtreecommitdiffstats
path: root/src/logging/config.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-11-21 14:26:02 -0600
committerToby Vincent <tobyv13@gmail.com>2022-11-21 14:26:02 -0600
commit72e9765d58b87125bdd5a2664bbc58202bdedff7 (patch)
tree656f7e2c46f8ca936439538d306f84409690946d /src/logging/config.rs
parentfe92d86fbe5f73bc2662a128b6431ec2089d05b8 (diff)
chore: split out projectr from tmuxr
Diffstat (limited to 'src/logging/config.rs')
-rw-r--r--src/logging/config.rs87
1 files changed, 0 insertions, 87 deletions
diff --git a/src/logging/config.rs b/src/logging/config.rs
deleted file mode 100644
index d9f14a6..0000000
--- a/src/logging/config.rs
+++ /dev/null
@@ -1,87 +0,0 @@
-use super::level;
-use figment::{providers::Serialized, value, Figment, Metadata, Profile, Provider};
-use serde::{Deserialize, Serialize};
-use std::path::PathBuf;
-
-pub(crate) use level::Level;
-
-#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
-#[serde(default)]
-pub struct Config {
- #[serde(with = "level")]
- pub stdout: Option<Level>,
- #[serde(with = "level")]
- pub level: Option<Level>,
- pub path: PathBuf,
-}
-
-impl Config {
- // Extract the configuration from any `Provider`
- pub fn extract<T: Provider>(provider: T) -> figment::error::Result<Config> {
- Figment::from(provider).extract()
- }
-
- // Provide a default provider, a `Figment`.
- pub fn figment() -> Figment {
- Figment::from(Config::default())
- }
-}
-
-impl Provider for Config {
- fn metadata(&self) -> Metadata {
- Metadata::named("Tmuxr path config")
- }
-
- fn data(&self) -> figment::error::Result<value::Map<Profile, value::Dict>> {
- Serialized::defaults(self).data()
- }
-}
-
-impl Default for Config {
- fn default() -> Self {
- Self {
- stdout: Some(Level::ERROR),
- level: None,
- path: dirs::cache_dir()
- .map(|p| p.join("tmuxr"))
- .unwrap_or_default()
- .join("tmuxr.log"),
- }
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use figment::providers::{Format, Serialized, Toml};
- use pretty_assertions::assert_eq;
-
- #[test]
- fn test_extract() {
- figment::Jail::expect_with(|jail| {
- jail.create_file(
- "tmuxr.toml",
- r#"
- stdout = "warn"
- level = "info"
- path = "/path/to/logfile.log"
- "#,
- )?;
-
- let config: Config = Figment::from(Serialized::defaults(Config::default()))
- .merge(Toml::file("tmuxr.toml"))
- .extract()?;
-
- assert_eq!(
- config,
- Config {
- stdout: Some(Level::WARN),
- level: Some(Level::INFO),
- path: "/path/to/logfile.log".into()
- }
- );
-
- Ok(())
- });
- }
-}