summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-01-25 17:12:15 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-01-26 18:45:02 +0100
commitb677bfa945c898c4b8e1e13d22386a99ef00ffe5 (patch)
tree3cf839bdaf7305f63bc98974302301e233f99c26
parentUpdate TODO. (diff)
downloadaur-runner-b677bfa945c898c4b8e1e13d22386a99ef00ffe5.tar.gz
aur-runner-b677bfa945c898c4b8e1e13d22386a99ef00ffe5.tar.xz
Propagate some log levels from subprocesses.
-rwxr-xr-xmain.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/main.py b/main.py
index 94e55ca..122cfd9 100755
--- a/main.py
+++ b/main.py
@@ -84,6 +84,18 @@ logging.config.dictConfig(get_conf('logging'))
logger = logging.getLogger(__name__)
+log_levels = {
+ 'DEBUG': logging.DEBUG,
+ 'INFO': logging.INFO,
+ 'WARNING': logging.WARNING,
+ 'WARN': logging.WARNING,
+ 'ERROR': logging.ERROR,
+ 'ERR': logging.ERROR,
+ 'CRITICAL': logging.CRITICAL,
+ 'FATAL': logging.CRITICAL,
+ }
+
+
def subprocess_with_log(*args, capture_output=False, **kv_args):
"""
Run a process as by subprocess.run, but also log output which isn't captured by user.
@@ -112,7 +124,18 @@ def subprocess_with_log(*args, capture_output=False, **kv_args):
with get_port(process) as pipe:
for line in iter(pipe.readline, sentinel):
- logger.debug('%i: %s', process.pid, line)
+ level = logging.DEBUG
+ try:
+ if type(line) == bytes:
+ line = line.decode('UTF-8').rstrip()
+ # line guaranteed a string here
+ if m := re.match('==> ([A-Z]+): (.*)', line):
+ level = log_levels.get(m[1], logging.DEBUG)
+ line = m[2]
+ except UnicodeDecodeError:
+ pass
+
+ logging.log(level, '%i: %s', process.pid, line)
process.wait()