diff --git a/README.rst b/README.rst index 377ea46..1fec561 100644 --- a/README.rst +++ b/README.rst @@ -31,6 +31,8 @@ Usage -q, --quiet Suppress all command output --version show program's version number and exit --report-all Report to Sentry even if the task has succeeded + --output-all Send all stderr/stdout output regardless of max + message length The Sentry server address can also be specified through the SENTRY_DSN environment variable (and the --dsn option can be omitted). diff --git a/cron_sentry/runner.py b/cron_sentry/runner.py index 161efe6..36eadba 100644 --- a/cron_sentry/runner.py +++ b/cron_sentry/runner.py @@ -23,7 +23,7 @@ epilog=('The Sentry server address can also be specified through ' + 'the SENTRY_DSN environment variable ' + '(and the --dsn option can be omitted).'), - usage='cron-sentry [-h] [--dsn SENTRY_DSN] [-M STRING_MAX_LENGTH] [--quiet] [--report-all] [--version] cmd [arg ...]', + usage='cron-sentry [-h] [--dsn SENTRY_DSN] [-M STRING_MAX_LENGTH] [--quiet] [--report-all] [--output-all] [--version] cmd [arg ...]', ) parser.add_argument( '--dsn', @@ -54,6 +54,12 @@ default=False, help='Report to Sentry even if the task has succeeded', ) +parser.add_argument( + '--output-all', + action='store_true', + default=False, + help='Send all stderr/stdout output regardless of max message length', +) parser.add_argument( 'cmd', nargs=REMAINDER, @@ -125,7 +131,8 @@ def run(args=argv[1:]): string_max_length=opts.string_max_length, quiet=opts.quiet, extra=_extra_from_env(environ), - report_all=opts.report_all + report_all=opts.report_all, + output_all=opts.output_all ) sys.exit(runner.run()) else: @@ -135,13 +142,14 @@ def run(args=argv[1:]): class CommandReporter(object): - def __init__(self, cmd, dsn, string_max_length, quiet=False, extra=None, report_all=False): + def __init__(self, cmd, dsn, string_max_length, quiet=False, extra=None, report_all=False, output_all=False): self.dsn = dsn self.command = cmd self.string_max_length = string_max_length self.quiet = quiet self.extra = {} self.report_all = report_all + self.output_all = output_all if extra is not None: self.extra = extra @@ -165,8 +173,12 @@ def run(self): self.report(exit_status, last_lines_stdout, last_lines_stderr, elapsed) if not self.quiet: - sys.stdout.write(last_lines_stdout) - sys.stderr.write(last_lines_stderr) + if self.output_all: + sys.stdout.write(self._get_all_lines(stdout)) + sys.stderr.write(self._get_all_lines(stderr)) + else: + sys.stdout.write(last_lines_stdout) + sys.stderr.write(last_lines_stderr) return exit_status @@ -210,3 +222,7 @@ def _get_last_lines(self, buf): buf.seek(-(self.string_max_length - 3), SEEK_END) last_lines = '...' + buf.read().decode('utf-8') return last_lines + + def _get_all_lines(self, buf): + buf.seek(0) + return buf.read().decode('utf-8')