Skip to content

Fix the log levels mapping#597

Merged
Jakuje merged 6 commits intoansible:develfrom
Jakuje:patch-1
Feb 26, 2026
Merged

Fix the log levels mapping#597
Jakuje merged 6 commits intoansible:develfrom
Jakuje:patch-1

Conversation

@Jakuje
Copy link
Copy Markdown
Collaborator

@Jakuje Jakuje commented May 23, 2024

SUMMARY

The libssh provides the most verbose logging with SSH_LOG_TRACE, which was mapped to logging.CRITICAL, causing the users being unable to get full debug logs. These are critical for libssh developers to be able to investigate issues.

ISSUE TYPE
  • Bugfix Pull Request

Jakuje added a commit to Jakuje/ansible.netcommon that referenced this pull request May 23, 2024
The `INFO` log level is usually not enough to get useful information from the libssh regarding the low-level issues that we would like to be able to resolve. This can be made even more fine grained, but I do not think less verbose logs would be much useful anyway.

Related is the issue in pylibssh, which maps the DEBUG verbosity to something that is not debug in libssh itself:

ansible/pylibssh#597
Comment thread src/pylibsshext/session.pyx
@webknjaz
Copy link
Copy Markdown
Member

It'd be useful to have tests in such PRs. I'm unable to verify what this patch affects without them.

@packit-as-a-service
Copy link
Copy Markdown

Congratulations! One of the builds has completed. 🍾

You can install the built RPMs by following these steps:

  • sudo yum install -y dnf-plugins-core on RHEL 8
  • sudo dnf install -y dnf-plugins-core on Fedora
  • dnf copr enable packit/ansible-pylibssh-597
  • And now you can install the packages.

Please note that the RPMs should be used only in a testing environment.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Jun 21, 2024
Comment thread docs/changelog-fragments/597.bugfix.rst Outdated
Comment thread tests/unit/session_test.py Outdated
@Jakuje
Copy link
Copy Markdown
Collaborator Author

Jakuje commented Aug 29, 2024

@webknjaz the current version should be working version with tests of what, I hope, you were trying to describe. I think it will need some polishing so I would be happy for your inputs.

@sonarqubecloud
Copy link
Copy Markdown

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

I wrote most of the review months ago. Submitting just now. This might need a few more iterations. Hopefully, a few things are actionable immediately.

Comment thread src/pylibsshext/logging.pxd
Comment thread src/pylibsshext/logging.pyx Outdated
Comment thread src/pylibsshext/logging.pyx Outdated
Comment thread src/pylibsshext/logging.pyx Outdated
Comment thread src/pylibsshext/logging.pyx Outdated
Comment thread src/pylibsshext/logging.pxd Outdated
Comment thread src/pylibsshext/logging.pyx Outdated
Comment thread src/pylibsshext/logging.pyx Outdated
Comment thread src/pylibsshext/logging.pyx Outdated
Comment thread src/pylibsshext/session.pyx Outdated
@Jakuje
Copy link
Copy Markdown
Collaborator Author

Jakuje commented Apr 11, 2025

Turns out that also the logging.NOTSET is misplaced. In python it means "ask above"/"log everything" but in libssh the currently mapped value libssh.SSH_LOG_NONE means do not log anything, which is quite the opposite so my suggestion would be to move this to logging.WARNING which is probably the closest ...

@Jakuje Jakuje force-pushed the patch-1 branch 3 times, most recently from 808a4aa to 2c034b8 Compare April 11, 2025 09:13
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 11, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@webknjaz
Copy link
Copy Markdown
Member

webknjaz commented Apr 24, 2025

Turns out that also the logging.NOTSET is misplaced. In python it means "ask above"/"log everything" but in libssh the currently mapped value libssh.SSH_LOG_NONE means do not log anything, which is quite the opposite so my suggestion would be to move this to logging.WARNING which is probably the closest ...

If you want a "log nothing", I'd probably set the threshold high in the mapping. Something like 55 or 60, or even 99:

$ python
Python 3.13.2 (main, Feb 28 2025, 20:34:46) [GCC 14.2.1 20241221] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.getLevelNamesMapping()
{'CRITICAL': 50, 'FATAL': 50, 'ERROR': 40, 'WARN': 30, 'WARNING': 30, 'INFO': 20, 'DEBUG': 10, 'NOTSET': 0}
>>> logging.fatal
<function fatal at 0x7fa77ea62fc0>
>>> logging.CRITICAL
50
>>> logging.FATAL
50
>>> logging.ERROR
40

P.S. I wonder if float('inf') would be allowed since infinity is semantically what you're after...

Comment thread src/pylibsshext/logging.pyx Outdated
Comment thread docs/user_guide.rst Outdated
Comment thread src/pylibsshext/session.pyx Outdated
Comment thread tests/integration/logging_test.py Outdated
Comment thread tests/integration/logging_test.py Outdated
Comment thread tests/integration/logging_test.py Outdated
@webknjaz
Copy link
Copy Markdown
Member

My final review pass gives a few grammar hints but the main concern is the configuration mismatch between the fixture and the tests (provided that the docs edits are cosmetic/secondary).

@Jakuje
Copy link
Copy Markdown
Collaborator Author

Jakuje commented Feb 23, 2026

I hope I addressed all your comments now. Please have a look

Comment thread docs/changelog-fragments/597.bugfix.rst
Comment thread docs/changelog-fragments/597.bugfix.rst Outdated
Comment thread docs/user_guide.rst Outdated
Comment thread tests/conftest.py Outdated
@webknjaz
Copy link
Copy Markdown
Member

FTR, the last failure is flaky #756 (comment)

@Jakuje
Copy link
Copy Markdown
Collaborator Author

Jakuje commented Feb 25, 2026

FTR, the last failure is flaky #756 (comment)

Saw that, but did not bother with that as it looks like its not the last version as we needed to clarify the testing in the last comment.

@webknjaz webknjaz moved this from 🧐 @webknjaz's review queue 📋 to ⏰ Merge reminder needed 🔀 in 📅 Procrastinating in public 😵‍💫 Feb 25, 2026
Jakuje and others added 6 commits February 25, 2026 19:17
The libssh provides the most verbose logging with SSH_LOG_TRACE, which
was not mapped to any of the standard values so the users are unable
to get full debug logs. These are critical for libssh developers to be
able to investigate issues.

This also creates callback for libssh to feed the logs into the python
logging system to be able to process the logs the python way.

The conftest no longer needs setting log level as it is set to the
highest level by default and filtered only on the python side.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
@Jakuje Jakuje merged commit 4aafdd4 into ansible:devel Feb 26, 2026
64 checks passed
@webknjaz webknjaz moved this from ⏰ Merge reminder needed 🔀 to 🌈 Done 🦄 in 📅 Procrastinating in public 😵‍💫 Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants