From b93ba338b39fd61aa0d300261bcfca30c0fcfc94 Mon Sep 17 00:00:00 2001 From: Jordan Halterman Date: Fri, 21 Apr 2023 14:40:08 -0700 Subject: [PATCH] Add LOGGING_CONFIG environment variable for explicitly setting the path to the logging configuration file --- config.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config.go b/config.go index b40f5dd..4d60a14 100644 --- a/config.go +++ b/config.go @@ -12,6 +12,7 @@ import ( ) const configFile = "logging.yaml" +const configEnv = "LOGGING_CONFIG" type loggingConfig struct { Encoders encodersConfig `json:"encoders" yaml:"encoders"` @@ -34,6 +35,16 @@ func (c *loggingConfig) getLogger(name string) (loggerConfig, bool) { // load the dazl configuration func load(config *loggingConfig) error { + configPath := os.Getenv(configEnv) + if configPath != "" { + bytes, err := os.ReadFile(configPath) + if err == nil { + return yaml.Unmarshal(bytes, config) + } else if !os.IsNotExist(err) { + return err + } + } + bytes, err := os.ReadFile(configFile) if err == nil { return yaml.Unmarshal(bytes, config)