diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-01-25 17:12:15 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-01-26 18:45:02 +0100 |
commit | b677bfa945c898c4b8e1e13d22386a99ef00ffe5 (patch) | |
tree | 3cf839bdaf7305f63bc98974302301e233f99c26 /main.py | |
parent | Update TODO. (diff) | |
download | aur-runner-b677bfa945c898c4b8e1e13d22386a99ef00ffe5.tar.gz aur-runner-b677bfa945c898c4b8e1e13d22386a99ef00ffe5.tar.xz |
Propagate some log levels from subprocesses.
Diffstat (limited to '')
-rwxr-xr-x | main.py | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -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() |