Skip to content

Commit

Permalink
Add customizing config path
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-ni committed Jul 14, 2024
1 parent a7c2427 commit 6493438
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ pub fn load(path: &str) -> Result<Config, Error> {
}

pub static CONFIG: LazyLock<Config> = LazyLock::new(|| {
match load("config.json") {
let config_path = var("CONFIG");
let config_path = config_path.as_deref().unwrap_or("config.json");

match load(config_path) {
Ok(config) => config,
Err(err) => {
// Avoid panicking
Expand All @@ -266,9 +269,12 @@ pub async fn watch_config_changes<S>(reload_handle: reload::Handle<LevelFilter,
return;
};

let config_path = var("CONFIG");
let config_path = config_path.as_deref().unwrap_or("config.json");

if inotify
.watches()
.add("config.json", WatchMask::MODIFY)
.add(config_path, WatchMask::MODIFY)
.is_err()
{
tracing::error!("Failed to add inotify watch, log-levels cannot be reloaded on the fly");
Expand Down

0 comments on commit 6493438

Please sign in to comment.