Commit cdb7f8ec by Stephen Fromm

Make logging to journal match what goes to syslog on non-systemd hosts

This makes the log message the same, whether it is sent to systemd's
journal or to syslog.  It retains the extra fields that are passed to
journal, such as MOUDLE=<name> and additional arguments.  Since journal
will reflect messages to syslog, this keeps what goes to syslog
informative instead of the terse 'Ansible module invoked'.

See issue #2461.
parent 92997ec7
...@@ -664,20 +664,24 @@ class AnsibleModule(object): ...@@ -664,20 +664,24 @@ class AnsibleModule(object):
else: else:
log_args[param] = self.params[param] log_args[param] = self.params[param]
if (has_journal): module = 'ansible-%s' % os.path.basename(__file__)
journal_args = ["MESSAGE=Ansible module invoked", "MODULE=%s" % os.path.basename(__file__)]
for arg in log_args:
journal_args.append(arg.upper() + "=" + str(log_args[arg]))
journal.sendv(*journal_args)
else:
msg = '' msg = ''
syslog.openlog('ansible-%s' % str(os.path.basename(__file__)), 0, syslog.LOG_USER)
for arg in log_args: for arg in log_args:
msg = msg + arg + '=' + str(log_args[arg]) + ' ' msg = msg + arg + '=' + str(log_args[arg]) + ' '
if msg: if msg:
syslog.syslog(syslog.LOG_NOTICE, 'Invoked with %s' % msg) msg = 'Invoked with %s' % msg
else:
msg = 'Invoked'
if (has_journal):
journal_args = ["MESSAGE=%s %s" % (module, msg)]
journal_args.append("MODULE=%s" % os.path.basename(__file__))
for arg in log_args:
journal_args.append(arg.upper() + "=" + str(log_args[arg]))
journal.sendv(*journal_args)
else: else:
syslog.syslog(syslog.LOG_NOTICE, 'Invoked') syslog.openlog(module, 0, syslog.LOG_USER)
syslog.syslog(syslog.LOG_NOTICE, msg)
def get_bin_path(self, arg, required=False, opt_dirs=[]): def get_bin_path(self, arg, required=False, opt_dirs=[]):
''' '''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment