Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds+github@gmail.com>2020-03-16 20:49:15 +0100
committerAnton Hvornum <anton.feeds+github@gmail.com>2020-03-16 20:49:15 +0100
commite0f1e1b5fde3f4716346378ff9f14c250f0c2bcf (patch)
treef82d94e9681b0779002efbeac2f0edf7cfa5a4f7 /archinstall.py
parent0e8bbb946d6ec3dc328d0e5c790482811e497cc1 (diff)
Trying to weed out dual logging.
Diffstat (limited to 'archinstall.py')
-rw-r--r--archinstall.py87
1 files changed, 48 insertions, 39 deletions
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.