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 4aa0db9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 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 All @@ -283,7 +289,7 @@ pub async fn watch_config_changes<S>(reload_handle: reload::Handle<LevelFilter,

while let Some(Ok(_)) = events.next().await {
// This currently only supports reloading log-levels
if let Ok(config) = load("config.json") {
if let Ok(config) = load(config_path) {
let _ = reload_handle.modify(|filter| {
*filter = LevelFilter::from_str(&config.log_level).unwrap_or(LevelFilter::INFO);
});
Expand Down

0 comments on commit 4aa0db9

Please sign in to comment.