Skip to content

Commit

Permalink
Merge pull request smarthomeNG#636 from AAPohl/logging-fix
Browse files Browse the repository at this point in the history
mutable etc_dir not persited in lib/log.py
  • Loading branch information
Morg42 authored Mar 3, 2024
2 parents fbb623a + 736eaac commit 6cb8d90
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def __init__(self, sh):
else:
self.logger.error(f"Another instance of Logs class already exists: {logs_instance}")

self._sh = sh
self.etc_dir = self._sh.get_etcdir()
self._sh = sh
return


Expand All @@ -73,7 +72,7 @@ def configure_logging(self, config_filename='logging.yaml'):

if config_dict == None:
print()
print(f"ERROR: Invalid logging configuration in file '{os.path.join(self.etc_dir, config_filename)}'")
print(f"ERROR: Invalid logging configuration in file '{os.path.join(self._sh.get_etcdir(), config_filename)}'")
print()
exit(1)

Expand Down Expand Up @@ -141,7 +140,7 @@ def configure_logging(self, config_filename='logging.yaml'):
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.etc_dir, config_filename)}'")
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
Expand Down Expand Up @@ -244,7 +243,7 @@ def load_logging_config(self, filename='logging', ignore_notfound=False):
If logging.yaml does not contain a 'shng_version' key, a backup is created
"""
conf_filename = os.path.join(self.etc_dir, filename)
conf_filename = os.path.join(self._sh.get_etcdir(), filename)
if not conf_filename.endswith('.yaml') and not conf_filename.endswith('.default'):
conf_filename += '.yaml'
result = shyaml.yaml_load(conf_filename, ignore_notfound)
Expand All @@ -258,7 +257,7 @@ def save_logging_config(self, logging_config, create_backup=False):
"""
if logging_config is not None:
logging_config['shng_version'] = self._sh.version.split('-')[0][1:]
conf_filename = os.path.join(self.etc_dir, 'logging')
conf_filename = os.path.join(self._sh.get_etcdir(), 'logging')
shyaml.yaml_save_roundtrip(conf_filename, logging_config, create_backup=create_backup)
return

Expand All @@ -270,7 +269,7 @@ def load_logging_config_for_edit(self):
If logging.yaml does not contain a 'shng_version' key, a backup is created
"""
#self.etc_dir = self._sh.get_etcdir()
conf_filename = os.path.join(self.etc_dir, 'logging')
conf_filename = os.path.join(self._sh.get_etcdir(), 'logging')
logging_config = shyaml.yaml_load_roundtrip(conf_filename)
self.logger.info("load_logging_config_for_edit: shng_version={}".format(logging_config.get('shng_version', None)))

Expand Down

0 comments on commit 6cb8d90

Please sign in to comment.