mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-28 21:40:43 +00:00
library: allow logging of general messages, not tied to a connection
Mainly for printf debugging of the module, where we don't have a connection index handy.
This commit is contained in:
parent
71102f9253
commit
ab21a41748
1 changed files with 15 additions and 6 deletions
|
|
@ -1693,7 +1693,7 @@ class _AnsibleUtil:
|
|||
c = self._run_results
|
||||
if c is None:
|
||||
c = []
|
||||
for cc in self.connections:
|
||||
for cc in range(0, len(self.connections) + 1):
|
||||
c.append({
|
||||
'changed': False,
|
||||
'log': [],
|
||||
|
|
@ -1703,11 +1703,13 @@ class _AnsibleUtil:
|
|||
return c
|
||||
|
||||
def run_results_changed(self, idx, changed = None):
|
||||
assert(idx >= 0 and idx < len(self.run_results) - 1)
|
||||
if changed is None:
|
||||
changed = True
|
||||
self.run_results[idx]['changed'] = bool(changed)
|
||||
|
||||
def run_results_rc(self, idx, rc, msg):
|
||||
assert(idx >= 0 and idx < len(self.run_results) - 1)
|
||||
self.run_results[idx]['rc'].append((rc, msg))
|
||||
self.log(idx, LogLevel.INFO, 'command: %s (rc=%s)' % (msg, rc))
|
||||
|
||||
|
|
@ -1728,6 +1730,10 @@ class _AnsibleUtil:
|
|||
|
||||
def log(self, idx, severity, msg, warn_traceback = False, force_fail = False):
|
||||
self._log_idx += 1
|
||||
if idx == -1:
|
||||
idx = len(self.run_results) - 1
|
||||
else:
|
||||
assert(idx >= 0 and idx < len(self.run_results) - 1)
|
||||
self.run_results[idx]['log'].append((severity, msg, self._log_idx))
|
||||
if severity == LogLevel.ERROR:
|
||||
# ignore_errors can be specified per profile. In absense of a
|
||||
|
|
@ -1745,12 +1751,15 @@ class _AnsibleUtil:
|
|||
self.fail_json('error: %s' % (msg), warn_traceback = warn_traceback)
|
||||
|
||||
def _complete_kwargs_loglines(self, rr, idx):
|
||||
c = self.connections[idx]
|
||||
prefix = 'state:%s' % (c['state'])
|
||||
if c['state'] != 'wait':
|
||||
prefix = prefix + (', "%s"' % (c['name']))
|
||||
if idx == len(self.connections):
|
||||
prefix = '#'
|
||||
else:
|
||||
c = self.connections[idx]
|
||||
prefix = '#%s, state:%s' % (idx, c['state'])
|
||||
if c['state'] != 'wait':
|
||||
prefix = prefix + (', "%s"' % (c['name']))
|
||||
for r in rr['log']:
|
||||
yield (r[2], '[%03d] %s #%s, %s: %s' % (r[2], LogLevel.fmt(r[0]), idx, prefix, r[1]))
|
||||
yield (r[2], '[%03d] %s %s: %s' % (r[2], LogLevel.fmt(r[0]), prefix, r[1]))
|
||||
|
||||
def _complete_kwargs(self, kwargs, traceback_msg = None):
|
||||
if 'warnings' in kwargs:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue