index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Anton Hvornum <anton.feeds+github@gmail.com> | 2020-03-16 20:49:15 +0100 |
---|---|---|
committer | Anton Hvornum <anton.feeds+github@gmail.com> | 2020-03-16 20:49:15 +0100 |
commit | e0f1e1b5fde3f4716346378ff9f14c250f0c2bcf (patch) | |
tree | f82d94e9681b0779002efbeac2f0edf7cfa5a4f7 /archinstall.py | |
parent | 0e8bbb946d6ec3dc328d0e5c790482811e497cc1 (diff) |
-rw-r--r-- | archinstall.py | 87 |
diff --git a/archinstall.py b/archinstall.py index 559b81d0..9e2b30c1 100644 --- a/archinstall.py +++ b/archinstall.py @@ -26,45 +26,54 @@ worker_history = oDict() instructions = oDict() args = {} -import logging -from systemd.journal import JournalHandler - -# Custom adapter to pre-pend the 'origin' key. -# TODO: Should probably use filters: https://docs.python.org/3/howto/logging-cookbook.html#using-filters-to-impart-contextual-information -class CustomAdapter(logging.LoggerAdapter): - def process(self, msg, kwargs): - return '[{}] {}'.format(self.extra['origin'], msg), kwargs - -logger = logging.getLogger() # __name__ -journald_handler = JournalHandler() -journald_handler.setFormatter(logging.Formatter('[{levelname}] {message}', style='{')) -logger.addHandler(journald_handler) -logger.setLevel(logging.DEBUG) - -class LOG_LEVELS: - CRITICAL = 1 - ERROR = 2 - WARNING = 3 - INFO = 4 - DEBUG = 5 - -LOG_LEVEL = 4 - -def log(*msg, origin='UNKNOWN', level=5, **kwargs): - if level <= LOG_LEVEL: - msg = [item.decode('UTF-8', errors='backslashreplace') if type(item) == bytes else item for item in msg] - msg = [str(item) if type(item) != str else item for item in msg] - log_adapter = CustomAdapter(logger, {'origin': origin}) - if level <= 1: - log_adapter.critical(' '.join(msg)) - elif level <= 2: - log_adapter.error(' '.join(msg)) - elif level <= 3: - log_adapter.warning(' '.join(msg)) - elif level <= 4: - log_adapter.info(' '.join(msg)) - else: - log_adapter.debug(' '.join(msg)) +create_log = True + +try: + if 'log' in __builtins__.__dict__: + create_log = False +except: + if 'log' in __builtins__: + create_log = False + +if create_log: + import logging + from systemd.journal import JournalHandler + + # Custom adapter to pre-pend the 'origin' key. + # TODO: Should probably use filters: https://docs.python.org/3/howto/logging-cookbook.html#using-filters-to-impart-contextual-information + class CustomAdapter(logging.LoggerAdapter): + def process(self, msg, kwargs): + return '[{}] {}'.format(self.extra['origin'], msg), kwargs + + logger = logging.getLogger() # __name__ + journald_handler = JournalHandler() + journald_handler.setFormatter(logging.Formatter('[{levelname}] {message}', style='{')) + logger.addHandler(journald_handler) + logger.setLevel(logging.DEBUG) + + class LOG_LEVELS: + CRITICAL = 1 + ERROR = 2 + WARNING = 3 + INFO = 4 + DEBUG = 5 + + LOG_LEVEL = 4 + def log(*msg, origin='UNKNOWN', level=5, **kwargs): + if level <= LOG_LEVEL: + msg = [item.decode('UTF-8', errors='backslashreplace') if type(item) == bytes else item for item in msg] + msg = [str(item) if type(item) != str else item for item in msg] + log_adapter = CustomAdapter(logger, {'origin': origin}) + if level <= 1: + log_adapter.critical(' '.join(msg)) + elif level <= 2: + log_adapter.error(' '.join(msg)) + elif level <= 3: + log_adapter.warning(' '.join(msg)) + elif level <= 4: + log_adapter.info(' '.join(msg)) + else: + log_adapter.debug(' '.join(msg)) ## == Profiles Path can be set via --profiles-path=/path ## This just sets the default path if the parameter is omitted. |