aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-16 16:48:51 +0000
committerFuwn <[email protected]>2021-05-16 16:48:51 +0000
commitbc883d8450dcba4e8738023bae722696e7b7d6f3 (patch)
treef2a8986e848fdeb8b21b7fe2f29b86da4cd1be85
parentfix(cli/clean): formatting (diff)
downloadwhirl-bc883d8450dcba4e8738023bae722696e7b7d6f3.tar.xz
whirl-bc883d8450dcba4e8738023bae722696e7b7d6f3.zip
feat(config): optional log to file
Gives you the option to disable logging to a file, environment variable takes precedence over configuration key. BREAKING CHANGE: `whirlsplash.log.file` configuration key created.
-rw-r--r--Whirl.example.toml1
-rw-r--r--src/config/Whirl.default.toml1
-rw-r--r--src/config/mod.rs2
-rw-r--r--src/main.rs19
4 files changed, 17 insertions, 6 deletions
diff --git a/Whirl.example.toml b/Whirl.example.toml
index 0edb0b2..aa2d684 100644
--- a/Whirl.example.toml
+++ b/Whirl.example.toml
@@ -14,6 +14,7 @@ enable = true
level = 1
everything = false
test = false
+file = true
[distributor]
worldsmaster_greeting = "Welcome to Whirlsplash!"
diff --git a/src/config/Whirl.default.toml b/src/config/Whirl.default.toml
index 0edb0b2..aa2d684 100644
--- a/src/config/Whirl.default.toml
+++ b/src/config/Whirl.default.toml
@@ -14,6 +14,7 @@ enable = true
level = 1
everything = false
test = false
+file = true
[distributor]
worldsmaster_greeting = "Welcome to Whirlsplash!"
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 8e6e053..bc350ea 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -26,6 +26,7 @@ pub struct WhirlsplashLogConfig {
pub level: i64,
pub everything: bool,
pub test: bool,
+ pub file: bool,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct DistributorConfig {
@@ -83,6 +84,7 @@ impl Default for Config {
level: 1,
everything: false,
test: false,
+ file: true,
},
},
distributor: DistributorConfig {
diff --git a/src/main.rs b/src/main.rs
index 8182fff..0ec0796 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,7 +3,7 @@
use std::error::Error;
-use whirl::{cli::Cli, utils::log::calculate_log_level};
+use whirl::{cli::Cli, config::Config, utils::log::calculate_log_level};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
@@ -12,11 +12,18 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Logging
dotenv::dotenv().ok();
- flexi_logger::Logger::with_str(calculate_log_level())
- .log_to_file()
- .directory("log")
- .print_message()
- .start()?;
+ let logger = flexi_logger::Logger::with_str(calculate_log_level());
+ if std::env::var("LOG_FILE").unwrap_or_else(|_| "true".to_string()) == "false"
+ || !Config::get().whirlsplash.log.file
+ {
+ logger.start()?;
+ } else {
+ logger
+ .print_message()
+ .log_to_file()
+ .directory("log")
+ .start()?;
+ }
// Execution
Cli::execute(matches).await.unwrap();