log verbosity (#81692)

Allow users to adjust verbosity to logs at same or higher level than to callback/screen

Co-authored-by: Matt Clay <matt@mystile.com>
pull/82231/head
Brian Coca 6 months ago committed by GitHub
parent dbddabce9e
commit e2d108db2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- User can now set ansible.log to record higher verbosity than what is specified for display via new configuration item LOG_VERBOSITY.

@ -385,6 +385,15 @@ LOCALHOST_WARNING:
- {key: localhost_warning, section: defaults}
type: boolean
version_added: "2.6"
LOG_VERBOSITY:
name: Default log verbosity
description:
- This will set log verbosity if higher than the normal display verbosity, otherwise it will match that.
env: [{name: ANSIBLE_LOG_VERBOSITY}]
ini:
- {key: log_verbosity, section: defaults}
type: int
version_added: "2.17"
INVENTORY_UNPARSED_WARNING:
name: Warning when no inventory files can be parsed, resulting in an implicit inventory with only localhost
default: True

@ -747,8 +747,8 @@ class Connection(ConnectionBase):
self._add_args(b_command, b_args, u'disable batch mode for sshpass')
b_command += [b'-b', b'-']
if display.verbosity > 3:
b_command.append(b'-vvv')
if display.verbosity:
b_command.append(b'-' + (b'v' * display.verbosity))
# Next, we add ssh_args
ssh_args = self.get_option('ssh_args')

@ -283,6 +283,11 @@ class Display(metaclass=Singleton):
self.columns = None
self.verbosity = verbosity
if C.LOG_VERBOSITY is None:
self.log_verbosity = verbosity
else:
self.log_verbosity = max(verbosity, C.LOG_VERBOSITY)
# list of all deprecation messages to prevent duplicate display
self._deprecations: dict[str, int] = {}
self._warns: dict[str, int] = {}
@ -412,7 +417,13 @@ class Display(metaclass=Singleton):
# raise
if logger and not screen_only:
msg2 = nocolor.lstrip('\n')
self._log(nocolor, color)
@proxy_display
def _log(self, msg: str, color: str | None = None, caplevel: int = 0):
if self.log_verbosity > caplevel:
msg2 = msg.lstrip('\n')
lvl = logging.INFO
if color:
@ -458,6 +469,11 @@ class Display(metaclass=Singleton):
self.display(msg, color=C.COLOR_VERBOSE, stderr=to_stderr)
else:
self.display("<%s> %s" % (host, msg), color=C.COLOR_VERBOSE, stderr=to_stderr)
elif self.log_verbosity > self.verbosity and self.log_verbosity > caplevel:
# we send to log if log was configured with higher verbosity
if host is not None:
msg = "<%s> %s" % (host, msg)
self._log(msg, C.COLOR_VERBOSE, caplevel)
def get_deprecation_message(
self,

Loading…
Cancel
Save