This commit is contained in:
superobk
2024-05-16 16:09:25 +08:00
2 changed files with 10 additions and 4 deletions

View File

@ -7,19 +7,18 @@ from src.configuration import EnvConf, LogConf, singleton
@singleton
class Main():
env_conf: EnvConf
@inject
def __init__(self, log_config: LogConf, env_conf: EnvConf, log_handler: LogHandler) -> None:
self.env_conf=env_conf
logging.basicConfig(
handlers=[logging.StreamHandler()],
handlers=[log_handler],
level=log_config.level,
datefmt=log_config.time_format,
format='%(asctime)s %(message)s')
def run(self):
logger = logging.getLogger(__name__)
logger.info("jarvis-models start", extra={"version": "0.0.1"})
logger.info("jarvis-models start", "version", "0.0.1")
uvicorn.run("server:app", host="0.0.0.0", port=8000, log_level="info")
if __name__ == "__main__":

View File

@ -36,6 +36,13 @@ class Configuration():
if length == 0 or not isinstance(cfg, dict):
return None
if length == 1:
return self.get(path.split("."), cfg, default=default)
lenght = len(path)
if lenght == 0 or not isinstance(cfg, dict):
if default is None:
return None
return default
if lenght == 1:
return cfg.get(path[0])
return self.get(path[1:], cfg.get(path[0]), default=default)