From 5087c86263c39bb13585c326c14f1f890900f42f Mon Sep 17 00:00:00 2001 From: Daniel Girtler Date: Thu, 8 Jun 2023 19:00:21 +1000 Subject: Fix 1830 (#1831) Co-authored-by: Daniel Girtler --- archinstall/lib/output.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py index 0395e2e7..b406d624 100644 --- a/archinstall/lib/output.py +++ b/archinstall/lib/output.py @@ -137,26 +137,28 @@ class Journald: def check_log_permissions(): filename = storage.get('LOG_FILE', None) + log_dir = storage.get('LOG_PATH', Path('./')) if not filename: - return + raise ValueError('No log file name defined') - log_dir = storage.get('LOG_PATH', Path('./')) - absolute_logfile = log_dir / filename + log_file = log_dir / filename try: log_dir.mkdir(exist_ok=True, parents=True) - with absolute_logfile.open('a') as fp: + log_file.touch(exist_ok=True) + + with log_file.open('a') as fp: fp.write('') except PermissionError: # Fallback to creating the log file in the current folder - fallback_log_file = Path('./').absolute() / filename - absolute_logfile = fallback_log_file - absolute_logfile.mkdir(exist_ok=True, parents=True) - storage['LOG_PATH'] = Path('./').absolute() + fallback_dir = Path('./').absolute() + fallback_log_file = fallback_dir / filename - err_string = f"Not enough permission to place log file at {absolute_logfile}, creating it in {fallback_log_file} instead." - warn(err_string) + fallback_log_file.touch(exist_ok=True) + + storage['LOG_PATH'] = fallback_dir + warn(f'Not enough permission to place log file at {log_file}, creating it in {fallback_log_file} instead') def _supports_color() -> bool: @@ -248,6 +250,7 @@ def info( ): log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font) + def debug( *msgs: str, level: int = logging.DEBUG, @@ -258,6 +261,7 @@ def debug( ): log(*msgs, level=level, fg=fg, bg=bg, reset=reset, font=font) + def error( *msgs: str, level: int = logging.ERROR, @@ -295,14 +299,10 @@ def log( if _supports_color(): text = _stylize_output(text, fg, bg, reset, font) - # If a logfile is defined in storage, - # we use that one to output everything - if filename := storage.get('LOG_FILE', None): - log_dir = storage.get('LOG_PATH', Path('./')) - absolute_logfile = log_dir / filename + log_file: Path = storage['LOG_PATH'] / storage['LOG_FILE'] - with open(absolute_logfile, 'a') as fp: - fp.write(f"{orig_string}\n") + with log_file.open('a') as fp: + fp.write(f"{orig_string}\n") Journald.log(text, level=level) -- cgit v1.2.3-54-g00ecf