Files
git-hooks/hooks/syslog.py
Joel Brobecker 2d7ef76b2a Remove import of __future__.print_function in hooks/*
Now that Python 3.x is required, this import is no longer useful.
Note that this commit deliberately excludes the imports done
in the testsuite, so as to allow these changes to be reviewed
independently of the changes to be made in the testsuite.

Change-Id: I28e1857df2cf0b2f9e7ddeab00b456d6ef513755
TN: U530-006
2021-11-30 17:58:55 +04:00

41 lines
1.1 KiB
Python

"""Handling of syslog-ing...
"""
from os import environ
from subprocess import Popen, PIPE, STDOUT
from io_utils import safe_decode
from utils import warn
def syslog(message, tag="style_checker", priority="local0.warn"):
"""Add the given entry to the syslog file.
PARAMETERS
message: The message to file.
tag: Mark every line in the log with the specified tag.
priority: Enter the message with the specified priority.
"""
logger_exe = "logger"
if "GIT_HOOKS_LOGGER" in environ:
logger_exe = environ["GIT_HOOKS_LOGGER"]
p = Popen(
[logger_exe, "-t", tag, "-p", priority, message], stdout=PIPE, stderr=STDOUT
)
out, _ = p.communicate()
out = safe_decode(out)
if p.returncode != 0:
info = [
"Failed to file the following syslog entry:",
" - message: %s" % message,
" - tag: %s" % tag,
" - priority: %s" % priority,
"",
"logger returned with error code %d:" % p.returncode,
] + out.splitlines()
warn(*info)
elif out.rstrip():
print(out.rstrip())