mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #2462 from sfromm/issue2461
Make logging to journal match what goes to syslog on non-systemd hosts
This commit is contained in:
commit
fe2f506514
1 changed files with 13 additions and 9 deletions
|
@ -664,20 +664,24 @@ class AnsibleModule(object):
|
||||||
else:
|
else:
|
||||||
log_args[param] = self.params[param]
|
log_args[param] = self.params[param]
|
||||||
|
|
||||||
|
module = 'ansible-%s' % os.path.basename(__file__)
|
||||||
|
msg = ''
|
||||||
|
for arg in log_args:
|
||||||
|
msg = msg + arg + '=' + str(log_args[arg]) + ' '
|
||||||
|
if msg:
|
||||||
|
msg = 'Invoked with %s' % msg
|
||||||
|
else:
|
||||||
|
msg = 'Invoked'
|
||||||
|
|
||||||
if (has_journal):
|
if (has_journal):
|
||||||
journal_args = ["MESSAGE=Ansible module invoked", "MODULE=%s" % os.path.basename(__file__)]
|
journal_args = ["MESSAGE=%s %s" % (module, msg)]
|
||||||
|
journal_args.append("MODULE=%s" % os.path.basename(__file__))
|
||||||
for arg in log_args:
|
for arg in log_args:
|
||||||
journal_args.append(arg.upper() + "=" + str(log_args[arg]))
|
journal_args.append(arg.upper() + "=" + str(log_args[arg]))
|
||||||
journal.sendv(*journal_args)
|
journal.sendv(*journal_args)
|
||||||
else:
|
else:
|
||||||
msg = ''
|
syslog.openlog(module, 0, syslog.LOG_USER)
|
||||||
syslog.openlog('ansible-%s' % str(os.path.basename(__file__)), 0, syslog.LOG_USER)
|
syslog.syslog(syslog.LOG_NOTICE, msg)
|
||||||
for arg in log_args:
|
|
||||||
msg = msg + arg + '=' + str(log_args[arg]) + ' '
|
|
||||||
if msg:
|
|
||||||
syslog.syslog(syslog.LOG_NOTICE, 'Invoked with %s' % msg)
|
|
||||||
else:
|
|
||||||
syslog.syslog(syslog.LOG_NOTICE, 'Invoked')
|
|
||||||
|
|
||||||
def get_bin_path(self, arg, required=False, opt_dirs=[]):
|
def get_bin_path(self, arg, required=False, opt_dirs=[]):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Add table
Reference in a new issue