summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-01-28 08:01:21 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-01-28 08:01:21 +0100
commit8c1b5677857e0b09e958d3deff3700dacaf6a2ba (patch)
tree0de94a88fcfc5635f76900b7af007e3dfc49343b
parentAdd final output about which packages failed. (diff)
downloadaur-runner-8c1b5677857e0b09e958d3deff3700dacaf6a2ba.tar.gz
aur-runner-8c1b5677857e0b09e958d3deff3700dacaf6a2ba.tar.xz
Add extra information to logger.
-rwxr-xr-xmain.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/main.py b/main.py
index 9adcee4..b88132f 100755
--- a/main.py
+++ b/main.py
@@ -9,6 +9,17 @@ import logging
import logging.config
+class PackageFilter(logging.Filter):
+
+ def __init__(self):
+ self.package = False
+
+ def filter(self, record):
+ if self.package:
+ record.package = self.package
+ return True
+
+
def get_config_files():
subpath = ['aur-runner', 'config.yaml']
conf_files = []
@@ -82,6 +93,8 @@ def get_conf(key, default=None):
logging.config.dictConfig(get_conf('logging'))
logger = logging.getLogger(__name__)
+filter = PackageFilter()
+logger.addFilter(filter)
log_levels = {
@@ -96,7 +109,7 @@ log_levels = {
}
-def subprocess_with_log(*args, capture_output=False, **kv_args):
+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.
@@ -114,7 +127,15 @@ def subprocess_with_log(*args, capture_output=False, **kv_args):
kv_args['stderr'] = subprocess.PIPE
get_port = lambda process: process.stderr
- process = subprocess.Popen(*args, **kv_args,)
+ if type(args) == list:
+ process_name = args[0]
+ elif type(args) == str:
+ process_name = args.split(' ')[0]
+ else:
+ process_name = 'Unknown'
+
+
+ process = subprocess.Popen(args, **kv_args,)
logger.info('pid = %i, exec(%s)', process.pid, process.args)
if kv_args.get('text'):
@@ -135,7 +156,10 @@ def subprocess_with_log(*args, capture_output=False, **kv_args):
except UnicodeDecodeError:
pass
- logging.log(level, '%i: %s', process.pid, line)
+ logger.log(level, '%s', line, extra={
+ 'pid':process.pid,
+ 'process_name': process_name,
+ })
process.wait()
@@ -246,6 +270,7 @@ def main():
failed_packages = []
for package in aur_pkgs:
+ filter.package = package
cmd = subprocess_with_log(['auracle', *auracle_args, '--chdir', cachedir, 'clone', package],
capture_output=True, text=True)
m = re.match('[^:]*: (.*)', cmd.stdout)
@@ -262,6 +287,8 @@ def main():
if cmd.returncode != 0:
failed_packages.append(package)
+ filter.package = False
+
if failed_packages:
logger.warning('The following packages failed: %s',
failed_packages)