refactor: log-to-syslog in debug_flags will log internal trace msgs to syslog [citest_skip]#867
Merged
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideExtends the network_connections logging behavior so that when the __debug_flags parameter contains 'log-to-syslog', all internal trace messages are sent to syslog instead of only treating ERROR-level logs as failures. Sequence diagram for updated logging with log-to-syslog debug flagsequenceDiagram
actor Operator
participant AnsibleTask as Ansible_task
participant NetworkModule as Network_connections_module
participant Syslog as Syslog_daemon
Operator->>AnsibleTask: Run task with __network_debug_flags=log-to-syslog
AnsibleTask->>NetworkModule: call log(severity, msg, idx, force_fail, ignore_errors)
NetworkModule->>NetworkModule: append (severity, msg, _log_idx) to run_results[idx].log
alt log-to-syslog enabled
NetworkModule->>Syslog: module.log(LogLevel.fmt(severity) + idx + msg)
Note over NetworkModule,Syslog: Internal trace messages are now emitted to syslog
else log-to-syslog disabled and severity is ERROR
NetworkModule->>NetworkModule: fail_json(connections, ...)
end
Class diagram for updated log method behavior with log-to-syslogclassDiagram
class NetworkConnectionsModule {
- module
- run_results
- _log_idx
+ log(severity, msg, idx, force_fail, ignore_errors)
}
class ModuleParams {
+ __debug_flags
}
class AnsibleModuleWrapper {
+ params
+ log(message)
+ fail_json(connections, msg)
}
class LogLevel {
+ ERROR
+ fmt(severity)
}
NetworkConnectionsModule --> AnsibleModuleWrapper : uses
AnsibleModuleWrapper --> ModuleParams : has
NetworkConnectionsModule --> LogLevel : uses
%% Updated logic inside log:
%% 1. Increment _log_idx and append to run_results[idx].log
%% 2. If "log-to-syslog" in module.params.__debug_flags, call module.log(...)
%% 3. Else if severity == LogLevel.ERROR and (force_fail or not ignore_errors), call fail_json(...)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The new
if "log-to-syslog" in self.module.params["__debug_flags"]:branch preventsLogLevel.ERRORfrom reaching thefail_jsonlogic because it is now in anelif; this should be changed so that logging to syslog happens in addition to, not instead of, the existing error-handling behavior. - Accessing
self.module.params["__debug_flags"]directly assumes the key is always present; consider using.get("__debug_flags", [])or similar to avoid potentialKeyErrorwhen the debug flag is unset.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `if "log-to-syslog" in self.module.params["__debug_flags"]:` branch prevents `LogLevel.ERROR` from reaching the `fail_json` logic because it is now in an `elif`; this should be changed so that logging to syslog happens in addition to, not instead of, the existing error-handling behavior.
- Accessing `self.module.params["__debug_flags"]` directly assumes the key is always present; consider using `.get("__debug_flags", [])` or similar to avoid potential `KeyError` when the debug flag is unset.
## Individual Comments
### Comment 1
<location path="library/network_connections.py" line_range="1825-1827" />
<code_context>
self._log_idx += 1
self.run_results[idx]["log"].append((severity, msg, self._log_idx))
- if severity == LogLevel.ERROR:
+ if "log-to-syslog" in self.module.params["__debug_flags"]:
+ self.module.log("%s: %s: %s" % (LogLevel.fmt(severity), idx, msg))
+ elif severity == LogLevel.ERROR:
if force_fail or not ignore_errors:
self.fail_json(
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `elif` changes error handling behavior when `log-to-syslog` is enabled.
With this `elif`, ERROR logs with `log-to-syslog` enabled will skip `fail_json` and no longer trigger failure handling. If the goal is to add syslog logging without changing failure semantics, use a separate `if` for syslog (or restore the original `if severity == LogLevel.ERROR` block) so ERROR still goes through `fail_json` as before.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
8df97c8 to
ea0c3ce
Compare
Contributor
Author
|
[citest] |
2 similar comments
Contributor
Author
|
[citest] |
Contributor
Author
|
[citest] |
…o syslog [citest_skip] If you set __network_debug_flags=log-to-syslog then the internal trace messages which are returned by the module will also be logged to syslog. This is useful for when the network role hangs and times out and is killed before those messages can be returned. The trace messages printed to syslog can help debug problems. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
c1cddd1 to
a1ad5ab
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If you set __network_debug_flags=log-to-syslog then the internal trace messages which
are returned by the module will also be logged to syslog. This is useful for when
the network role hangs and times out and is killed before those messages can
be returned. The trace messages printed to syslog can help debug problems.
Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
New Features:
log-to-syslogdebug flag is set.