updating with latest changes to CONFIG

This commit is contained in:
dtomlinson
2019-12-04 11:50:55 +00:00
parent e2f07a0d9f
commit 3af8d00661
4 changed files with 61 additions and 19 deletions

View File

@@ -1,8 +1,12 @@
from __future__ import annotations
import sys
from typing import Any, TypeVar, Type
from typing import Any, TypeVar, Type, TYPE_CHECKING
if TYPE_CHECKING:
import logging
config_inst_t = TypeVar('config_inst_t', bound='config.config.Config')
config_inst_t = TypeVar('config_inst_t', bound='module.config.config.Config')
def export(fn: callable) -> callable:
@@ -35,3 +39,22 @@ def set_config(
"""
config_var = key.lower().replace('.', '_')
setattr(config_inst, config_var, config_inst.get(key, default, cast))
# Create function to print cached logged messages and reset
def process_cached_logs(
config_inst: Type[config_inst_t],
logger: logging.Logger
):
"""Prints the cached messages from the CONFIG class and resets the cache.
Parameters
----------
config_inst : Type[config_inst_t]
Instance of the CONFIG class.
logger : logging.Logger
Instance of the active logger.
"""
for msg in config_inst.deferred_messages:
logger.info(msg)
config_inst.reset_log()