Skip to content

Splitted logs from paramiko.transport #2059

@shtoltz

Description

@shtoltz

Original issue from 2014 - #405

when transport catches exceptions it splits tb into multiple strings:

paramiko/paramiko/transport.py

Lines 1633 to 1634 in 1af8db2

self._log(ERROR, 'Exception: ' + str(e))
self._log(ERROR, util.tb_strings())

which are then logged separately:

paramiko/paramiko/transport.py

Lines 1423 to 1428 in 1af8db2

def _log(self, level, msg, *args):
if issubclass(type(msg), list):
for m in msg:
self.logger.log(level, m)
else:
self.logger.log(level, msg, *args)

making it hard to e.g. filter a specific "error" in server mode.

would it make sense to just pass along whatever exc_info is being handled to logging and let it do formatting as a single msg?

This issue is closed although the linked PR was not merged.
Issue is still actual, especially with custom logging handlers or Sentry.

Examples:

  1. Logging in json format
{"timestamp": "2022-05-17T18:50:23.269787Z", "level": "ERROR", "name": "paramiko.transport", "message": "Exception: Error reading SSH protocol banner"}
{"timestamp": "2022-05-17T18:50:23.272036Z", "level": "ERROR", "name": "paramiko.transport", "message": "Traceback (most recent call last):"}
{"timestamp": "2022-05-17T18:50:23.272207Z", "level": "ERROR", "name": "paramiko.transport", "message": "  File \"/home/shtoltz/work/paramiko_test/venv/lib/python3.9/site-packages/paramiko/transport.py\", line 2046, in run"}
{"timestamp": "2022-05-17T18:50:23.272354Z", "level": "ERROR", "name": "paramiko.transport", "message": "    self._check_banner()"}
{"timestamp": "2022-05-17T18:50:23.272497Z", "level": "ERROR", "name": "paramiko.transport", "message": "  File \"/home/shtoltz/work/paramiko_test/venv/lib/python3.9/site-packages/paramiko/transport.py\", line 2211, in _check_banner"}
{"timestamp": "2022-05-17T18:50:23.272676Z", "level": "ERROR", "name": "paramiko.transport", "message": "    raise SSHException("}
{"timestamp": "2022-05-17T18:50:23.272833Z", "level": "ERROR", "name": "paramiko.transport", "message": "paramiko.ssh_exception.SSHException: Error reading SSH protocol banner"}
{"timestamp": "2022-05-17T18:50:23.273012Z", "level": "ERROR", "name": "paramiko.transport", "message": ""}

should be:

{"timestamp": "2022-05-17T18:50:23.269787Z", "level": "ERROR", "name": "paramiko.transport", "message": "Exception: Error reading SSH protocol banner", "exc_info": "Traceback (most recent call last):\n  File \"/home/shtoltz/work/paramiko_test/venv/lib/python3.9/site-packages/paramiko/transport.py\", line 2046, in run\n    self._check_banner()\n  File \"/home/shtoltz/work/paramiko_test/venv/lib/python3.9/site-packages/paramiko/transport.py\", line 2211, in _check_banner\n    raise SSHException(\nparamiko.ssh_exception.SSHException: Error reading SSH protocol banner"}
  1. Sentry
    2022-05-17_22-39

There are several PRs for this issue:

Last PR (#1970) looks fine and AFAICS must work with supported python versions (2.7 and 3)
Can you please merge it or tell what needs to be fix?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions