Cleaned up some logic. How the LOG_LEVEL is fetched from the storage.

This commit is contained in:
Anton Hvornum 2020-11-04 23:45:45 +00:00
parent d85c485b3a
commit ab69cb7525
1 changed files with 8 additions and 16 deletions

View File

@ -2,6 +2,7 @@ import abc
import os import os
import sys import sys
import logging import logging
from .storage import storage
class LOG_LEVELS: class LOG_LEVELS:
Critical = 0b001 Critical = 0b001
@ -72,25 +73,16 @@ def stylize_output(text :str, *opts, **kwargs):
text = '%s\x1b[%sm' % (text or '', RESET) text = '%s\x1b[%sm' % (text or '', RESET)
return '%s%s' % (('\x1b[%sm' % ';'.join(code_list)), text or '') return '%s%s' % (('\x1b[%sm' % ';'.join(code_list)), text or '')
GLOB_IMP_ERR_NOTIFIED = False
def log(*args, **kwargs): def log(*args, **kwargs):
if 'level' in kwargs: if 'level' in kwargs:
try: if 'LOG_LEVEL' not in storage:
import archinstall storage['LOG_LEVEL'] = LOG_LEVELS.Info
if 'LOG_LEVEL' not in archinstall.storage:
archinstall.storage['LOG_LEVEL'] = LOG_LEVELS.Info
if kwargs['level'] >= archinstall.storage['LOG_LEVEL']: if kwargs['level'] >= storage['LOG_LEVEL']:
# Level on log message was Debug, but output level is set to Info. print(f"Level {kwargs['level']} is higher than storage log level {storage['LOG_LEVEL']}.")
# In that case, we'll drop it. # Level on log message was Debug, but output level is set to Info.
return None # In that case, we'll drop it.
except ModuleNotFoundError: return None
global GLOB_IMP_ERR_NOTIFIED
if GLOB_IMP_ERR_NOTIFIED is False:
print('[Error] Archinstall not found in global import path. Can not determain log level for log messages.')
GLOB_IMP_ERR_NOTIFIED = True
string = orig_string = ' '.join([str(x) for x in args]) string = orig_string = ' '.join([str(x) for x in args])