Adds support for 'log_file' in hook config

Specify a filename on a per hook basis and
pre-commit will write the STDOUT and STDERR
of that hook into the file. Useful for CI.

Resolves #499.
This commit is contained in:
Alex Hutton
2017-05-04 15:45:05 +10:00
committed by Alex Hutton
parent 5d43b05bd3
commit f2644a4f2e
6 changed files with 59 additions and 6 deletions

View File

@@ -71,8 +71,17 @@ def write(s, stream=stdout_byte_stream):
stream.flush()
def write_line(s=None, stream=stdout_byte_stream):
if s is not None:
stream.write(five.to_bytes(s))
stream.write(b'\n')
stream.flush()
def write_line(s=None, stream=stdout_byte_stream, logfile_name=None):
def output_streams():
yield stream
try:
with open(logfile_name, 'ab') as logfile:
yield logfile
except (TypeError, IOError):
pass
for output_stream in output_streams():
if s is not None:
output_stream.write(five.to_bytes(s))
output_stream.write(b'\n')
output_stream.flush()