Refactor: call getfqdn() once per call of replace_placeholders()

This commit is contained in:
Gregor Kleen 2017-12-12 12:44:17 +01:00
parent 85fb38e2f3
commit 294f06b565
1 changed files with 3 additions and 2 deletions

View File

@ -180,10 +180,11 @@ def format_line(format, data):
def replace_placeholders(text): def replace_placeholders(text):
"""Replace placeholders in text with their values.""" """Replace placeholders in text with their values."""
current_time = datetime.now() current_time = datetime.now()
fqdn = socket.getfqdn()
data = { data = {
'pid': os.getpid(), 'pid': os.getpid(),
'fqdn': socket.getfqdn(), 'fqdn': fqdn,
'reverse-fqdn': '.'.join(reversed(socket.getfqdn().split('.'))), 'reverse-fqdn': '.'.join(reversed(fqdn.split('.'))),
'hostname': socket.gethostname(), 'hostname': socket.gethostname(),
'now': DatetimeWrapper(current_time.now()), 'now': DatetimeWrapper(current_time.now()),
'utcnow': DatetimeWrapper(current_time.utcnow()), 'utcnow': DatetimeWrapper(current_time.utcnow()),