diff --git a/LogosLinuxInstaller.py b/LogosLinuxInstaller.py index 9cb482d7..6d6b7c5f 100755 --- a/LogosLinuxInstaller.py +++ b/LogosLinuxInstaller.py @@ -15,6 +15,7 @@ from msg import cli_msg from msg import initialize_logging from msg import logos_error +from msg import update_log_level from utils import checkDependencies from utils import curses_menu from utils import die_if_root @@ -121,7 +122,7 @@ def main(): cli_args = parse_command_line() # Initialize logging. - initialize_logging(logging.WARNING) + initialize_logging(config.LOG_LEVEL) die_if_running() die_if_root() @@ -140,13 +141,12 @@ def main(): # Parse CLI args and update affected config vars. parse_args(cli_args) - # Update logging level from config. - logger = logging.getLogger() - logger.setLevel(config.LOG_LEVEL) - if config.DELETE_INSTALL_LOG and os.path.isfile(config.LOGOS_LOG): os.remove(config.LOGOS_LOG) - + + # Set terminal log level based on current config. + update_log_level(config.LOG_LEVEL) + # If Logos app is installed, run the desired Logos action. if config.LOGOS_EXE is not None and os.access(config.LOGOS_EXE, os.X_OK): if config.ACTION == 'control': diff --git a/msg.py b/msg.py index c8531155..2ae50de2 100644 --- a/msg.py +++ b/msg.py @@ -6,6 +6,21 @@ import config +def get_log_level_name(level): + name = None + levels = { + "CRITICAL": logging.CRITICAL, + "ERROR": logging.ERROR, + "WARNING": logging.WARNING, + "INFO": logging.INFO, + "DEBUG": logging.DEBUG, + } + for k, v in levels.items(): + if level == v: + name = k + break + return name + def initialize_logging(stderr_log_level): ''' Log levels: @@ -40,6 +55,13 @@ def initialize_logging(stderr_log_level): ) cli_msg(f"Installer log file: {config.LOGOS_LOG}") +def update_log_level(new_level): + # Update logging level from config. + for h in logging.getLogger().handlers: + if type(h) == logging.StreamHandler: + h.setLevel(new_level) + logging.info(f"Terminal log level set to {get_log_level_name(new_level)}") + def cli_msg(message, end='\n'): ''' Used for messages that should be printed to stdout regardless of log level. ''' print(message, end=end)