From d8d3a49f28ed5419e3dae64a3794294e061ec129 Mon Sep 17 00:00:00 2001 From: Weidong Feng Date: Fri, 22 Apr 2022 13:20:47 +0800 Subject: [PATCH] chore(config): add log for environment config loading --- sea/config.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sea/config.py b/sea/config.py index 6f6d458..9864868 100644 --- a/sea/config.py +++ b/sea/config.py @@ -1,9 +1,12 @@ +import logging import numbers import os from sea.datatypes import ConstantsObject from sea.utils import strtobool +log = logging.getLogger("sea.config") + class ConfigAttribute: """Makes an attribute forward to the config""" @@ -52,6 +55,7 @@ def get_namespace(self, namespace, lowercase=True, trim_namespace=True): def load_config_from_env(self): """ read environment variables and overwrite same name key's values. + only bool/str/numbers.Number could be overwritten `True` will be converted to python's bool `True`. `1` will be converted to python's int `1`. """ @@ -61,11 +65,16 @@ def load_config_from_env(self): env_value = os.getenv(k) if not env_value: continue + log.info("config item {} overwriting by env {}={}", + k.upper(), k.upper(), env_value) value_type = type(self[k]) if value_type is bool: self[k] = strtobool(env_value) elif isinstance(env_value, (str, numbers.Number)): self[k] = value_type(env_value) + else: + log.debug("{} type config item {} can't cast from env", + value_type, k.upper()) def __repr__(self): return '<%s %s>' % (self.__class__.__name__, dict.__repr__(self))