Skip to content

Commit

Permalink
ssh: don't use a separate logger
Browse files Browse the repository at this point in the history
The logger setup was confusing when using --log-file-level=DEBUG,
showing this debug-level output inside default --log-cli-level=INFO output,
but without the debug context that only went into the logfile, and without
any hint of what kind of output it was.

This makes it use the same logger as all other debug output, preventing it
from appearing in the wrong place, and adds a marker to hint it is output
data - at the same time fixing a potential formatting issue, where
arbitrary ssh output lines were interpreted as *format strings*.

Signed-off-by: Yann Dirson <yann.dirson@vates.tech>
  • Loading branch information
ydirson committed Jun 19, 2024
1 parent 83ff609 commit ebe6700
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions lib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ def _ellide_log_lines(log):
reduced_message.append("(...)")
return "\n{}".format("\n".join(reduced_message))

OUPUT_LOGGER = logging.getLogger('output')
OUPUT_LOGGER.propagate = False
OUTPUT_HANDLER = logging.StreamHandler()
OUPUT_LOGGER.addHandler(OUTPUT_HANDLER)
OUTPUT_HANDLER.setFormatter(logging.Formatter('%(message)s'))

def _ssh(hostname_or_ip, cmd, check, simple_output, suppress_fingerprint_warnings,
background, target_os, decode, options):
opts = list(options)
Expand Down Expand Up @@ -111,7 +105,7 @@ def _ssh(hostname_or_ip, cmd, check, simple_output, suppress_fingerprint_warning
for line in iter(process.stdout.readline, b''):
readable_line = line.decode(errors='replace').strip()
stdout.append(line)
OUPUT_LOGGER.debug(readable_line)
logging.debug("> %s", readable_line)
_, stderr = process.communicate()
res = subprocess.CompletedProcess(ssh_cmd, process.returncode, b''.join(stdout), stderr)

Expand Down

0 comments on commit ebe6700

Please sign in to comment.