diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-09-29 16:39:51 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-09-29 16:39:51 -0400 |
commit | f19a7421dfeba7947d31d7a4e785ea50a0817feb (patch) | |
tree | 331e9dfcae38d0a588d1b73d07d31a373cca708b | |
parent | a1415bd959326a6b3a98941f28659b6e930403d5 (diff) | |
download | grokmirror-f19a7421dfeba7947d31d7a4e785ea50a0817feb.tar.gz |
Don't bomb the logs with all the errors
If the email gets too big, we won't be able to send it. Trim any errors
we get from git to 10 lines max and write the rest to the file within
the repo.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rwxr-xr-x | grokmirror/fsck.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/grokmirror/fsck.py b/grokmirror/fsck.py index 7f3cf1c..53fc9a8 100755 --- a/grokmirror/fsck.py +++ b/grokmirror/fsck.py @@ -36,6 +36,22 @@ from fcntl import lockf, LOCK_EX, LOCK_UN, LOCK_NB logger = logging.getLogger(__name__) +def log_errors(fullpath, cmdargs, lines): + logger.critical('%s reports errors:', fullpath) + with open(os.path.join(fullpath, 'grokmirror.fsck.err'), 'w') as fh: + fh.write('# Date: %s\n' % datetime.datetime.today().strftime('%F')) + fh.write('# Cmd : git %s\n' % ' '.join(cmdargs)) + count = 0 + for line in lines: + fh.write('%s\n' % line) + logger.critical('\t%s', line) + count += 1 + if count > 10: + logger.critical('\t [ %s more lines skipped ]', len(lines) - 10) + logger.critical('\t [ see %s/grokmirror.fsck.err ]', os.path.basename(fullpath)) + break + + def get_blob_set(fullpath): bset = set() size = 0 @@ -253,10 +269,8 @@ def run_git_prune(fullpath, config): if debug: logger.debug('Stderr: %s', '\n'.join(debug)) if warn: - logger.critical('Pruning %s returned critical errors:', fullpath) prune_ok = False - for entry in warn: - logger.critical("\t%s", entry) + log_errors(fullpath, args, warn) check_reclone_error(fullpath, config, warn) if isprecious: @@ -396,10 +410,8 @@ def run_git_repack(fullpath, config, level=1, prune=True): if debug: logger.debug('Stderr: %s', '\n'.join(debug)) if warn: - logger.critical('Repacking %s returned critical errors:', fullpath) repack_ok = False - for entry in warn: - logger.critical("\t%s", entry) + log_errors(fullpath, args, warn) check_reclone_error(fullpath, config, warn) if not repack_ok: @@ -440,11 +452,8 @@ def run_git_repack(fullpath, config, level=1, prune=True): if debug: logger.debug('Stderr: %s', '\n'.join(debug)) if warn: - logger.critical('Repacking refs %s returned critical errors:', fullpath) repack_ok = False - for entry in warn: - logger.critical("\t%s", entry) - + log_errors(fullpath, args, warn) check_reclone_error(fullpath, config, warn) if prune: @@ -492,9 +501,7 @@ def run_git_fsck(fullpath, config, conn_only=False): if debug: logger.debug('Stderr: %s', '\n'.join(debug)) if warn: - logger.critical('%s has critical errors:', fullpath) - for entry in warn: - logger.critical("\t%s", entry) + log_errors(fullpath, args, warn) check_reclone_error(fullpath, config, warn) |