Skip to content

Commit

Permalink
Add log_only to debug messages (ansible#25545)
Browse files Browse the repository at this point in the history
Fixes ansible#25544
When `debug` is enabled the debug messages triggered
from `bin/ansible-connection` should be logged only to file
and not on stdout.
  • Loading branch information
ganeshrn authored Jun 13, 2017
1 parent 343a709 commit 9e8cc26
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/ansible-connection
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def main():
sys.stderr.write(traceback.format_exc())
sys.exit("FAIL: %s" % e)

ssh = connection_loader.get('ssh', class_only=True)
ssh = connection_loader.get('ssh', class_only=True, log_only=True)
cp = ssh._create_control_path(pc.remote_addr, pc.connection, pc.remote_user)

# create the persistent connection dir if need be and create the paths
Expand Down
7 changes: 4 additions & 3 deletions lib/ansible/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def get(self, name, *args, **kwargs):

found_in_cache = True
class_only = kwargs.pop('class_only', False)
log_only = kwargs.pop('log_only', False)
if name in self.aliases:
name = self.aliases[name]
path = self.find_plugin(name)
Expand All @@ -367,7 +368,7 @@ def get(self, name, *args, **kwargs):
return None

self._display_plugin_load(self.class_name, name, self._searched_paths, path,
found_in_cache=found_in_cache, class_only=class_only)
found_in_cache=found_in_cache, class_only=class_only, log_only=log_only)
if not class_only:
try:
obj = obj(*args, **kwargs)
Expand All @@ -383,7 +384,7 @@ def get(self, name, *args, **kwargs):
setattr(obj, '_load_name', name)
return obj

def _display_plugin_load(self, class_name, name, searched_paths, path, found_in_cache=None, class_only=None):
def _display_plugin_load(self, class_name, name, searched_paths, path, found_in_cache=None, class_only=None, log_only=False):
msg = 'Loading %s \'%s\' from %s' % (class_name, os.path.basename(name), path)

if len(searched_paths) > 1:
Expand All @@ -392,7 +393,7 @@ def _display_plugin_load(self, class_name, name, searched_paths, path, found_in_
if found_in_cache or class_only:
msg = '%s (found_in_cache=%s, class_only=%s)' % (msg, found_in_cache, class_only)

display.debug(msg)
display.debug(msg, log_only)

def all(self, *args, **kwargs):
''' instantiates all plugins with the same arguments '''
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/utils/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ def vvvvv(self, msg, host=None):
def vvvvvv(self, msg, host=None):
return self.verbose(msg, host=host, caplevel=5)

def debug(self, msg):
def debug(self, msg, log_only=False):
if C.DEFAULT_DEBUG:
self.display("%6d %0.5f: %s" % (os.getpid(), time.time(), msg), color=C.COLOR_DEBUG)
self.display("%6d %0.5f: %s" % (os.getpid(), time.time(), msg), color=C.COLOR_DEBUG, log_only=log_only)

def verbose(self, msg, host=None, caplevel=2):
if self.verbosity > caplevel:
Expand Down

0 comments on commit 9e8cc26

Please sign in to comment.