Skip to content

Commit

Permalink
Merge pull request #641 from onkelandy/logging
Browse files Browse the repository at this point in the history
logging: Log issues with logging.yaml to standard shng logger
  • Loading branch information
aschwith authored Mar 5, 2024
2 parents 8ecd0ac + d8b97cc commit dba17d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,11 @@ def configure_logging(self, config_filename='logging.yaml'):
try:
logging.config.dictConfig(config_dict)
except Exception as e:
#self._logger_main.error(f"Invalid logging configuration in file 'logging.yaml' - Exception: {e}")
print()
print(f"ERROR: dictConfig: Invalid logging configuration in file '{os.path.join(self._sh.get_etcdir(), config_filename)}'")
print(f" Exception: {e}")
print()
return False
return e

#self.logger.notice(f"Logs.configure_logging: Level NOTICE = {notice_level} / root_handler_level={root_handler_level}")

Expand Down
9 changes: 6 additions & 3 deletions lib/smarthome.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def __init__(self, MODE, extern_conf_dir='', config_etc=False):

#############################################################
# setup logging
self.init_logging(self._log_conf_basename, MODE)
logsetup = self.init_logging(self._log_conf_basename, MODE)


#############################################################
Expand Down Expand Up @@ -346,6 +346,8 @@ def __init__(self, MODE, extern_conf_dir='', config_etc=False):
if lib.utils.running_virtual():
virtual_text = ' in virtual environment'
self._logger_main.notice(f"-------------------- Init SmartHomeNG {self.version} --------------------")
if logsetup is not True:
self._logger_main.warning(f"Problem with logging config: {logsetup}")
self._logger_main.notice(f"Running in Python interpreter 'v{self.PYTHON_VERSION}'{virtual_text}, from directory {self._base_dir}")
self._logger_main.notice(f" - operating system '{self.systeminfo.get_osname()}' (pid={pid})")
if self.systeminfo.get_rasppi_info() == '':
Expand Down Expand Up @@ -601,8 +603,9 @@ def init_logging(self, conf_basename='', MODE='default'):
if conf_basename == '':
conf_basename = self._log_conf_basename
# conf_dict = lib.shyaml.yaml_load(conf_basename + YAML_FILE, True)
logsetup = self.logs.configure_logging()

if not self.logs.configure_logging():
if logsetup is not True:
conf_basename = self._log_conf_basename + YAML_FILE + '.default'
print(" Trying default logging configuration from:")
print(f" {conf_basename}")
Expand All @@ -622,7 +625,7 @@ def init_logging(self, conf_basename='', MODE='default'):
logging.getLogger().setLevel(logging.DEBUG)
elif MODE == 'quiet':
logging.getLogger().setLevel(logging.WARNING)
return
return logsetup


#################################################################
Expand Down

0 comments on commit dba17d9

Please sign in to comment.