Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to control output of verbose messages #52948

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/verbose_stderr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- allow user to force verbose messages to stderr
11 changes: 11 additions & 0 deletions lib/ansible/config/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1719,4 +1719,15 @@ STRING_CONVERSION_ACTION:
- section: defaults
key: string_conversion_action
type: string
VERBOSE_TO_STDERR:
version_added: '2.8'
description:
- Force 'verbose' option to use stderr instead of stdout
default: False
env:
- name: ANSIBLE_VERBOSE_TO_STDERR
ini:
- section: defaults
key: verbose_to_stderr
type: bool
...
6 changes: 4 additions & 2 deletions lib/ansible/utils/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,13 @@ def debug(self, msg, host=None):
self.display("%6d %0.5f [%s]: %s" % (os.getpid(), time.time(), host, msg), color=C.COLOR_DEBUG)

def verbose(self, msg, host=None, caplevel=2):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be useful to allow verbose to accept stderr in the function signature too? We would also have to update v, vv, etc to support it also.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, but thought that would be huge undertaking while this was a 'blanket' requriement


to_stderr = C.VERBOSE_TO_STDERR
if self.verbosity > caplevel:
if host is None:
self.display(msg, color=C.COLOR_VERBOSE)
self.display(msg, color=C.COLOR_VERBOSE, stderr=to_stderr)
else:
self.display("<%s> %s" % (host, msg), color=C.COLOR_VERBOSE)
self.display("<%s> %s" % (host, msg), color=C.COLOR_VERBOSE, stderr=to_stderr)

def deprecated(self, msg, version=None, removed=False):
''' used to print out a deprecation message.'''
Expand Down