Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging : exception is raised when level is unknown #6087

Open
tpennors opened this issue Jan 4, 2025 · 1 comment
Open

logging : exception is raised when level is unknown #6087

tpennors opened this issue Jan 4, 2025 · 1 comment
Labels

Comments

@tpennors
Copy link

tpennors commented Jan 4, 2025

Describe the bug
Following exception can occur if unknown level (eg. 'TRACE'):

future: <Task finished name='Task-2' coro=<Runner._update_status() done, defined at /home/gitlab-runner/venv/lib/python3.12/site-packages/avocado/plugins/runner_nrunner.py:248> exception=ValueError("Unknown level: 'Level Level 5'")>
Traceback (most recent call last):
  File "/home/gitlab-runner/venv/lib/python3.12/site-packages/avocado/plugins/runner_nrunner.py", line 260, in _update_status
    message_handler.process_message(message, task, job)
  File "/home/gitlab-runner/venv/lib/python3.12/site-packages/avocado/core/messages.py", line 71, in process_message
    handler.process_message(message, task, job)
  File "/home/gitlab-runner/venv/lib/python3.12/site-packages/avocado/core/messages.py", line 89, in process_message
    handler.process_message(message, task, job)
  File "/home/gitlab-runner/venv/lib/python3.12/site-packages/avocado/core/messages.py", line 56, in process_message
    self.handle(message, task, job)
  File "/home/gitlab-runner/venv/lib/python3.12/site-packages/avocado/core/messages.py", line 374, in handle
    logger.setLevel(level)
  File "/usr/lib/python3.12/logging/__init__.py", line 1514, in setLevel
    self.level = _checkLevel(level)
                 ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/logging/__init__.py", line 213, in _checkLevel
    raise ValueError("Unknown level: %r" % level)
ValueError: Unknown level: 'Level Level 5'

Steps to reproduce
When using avocado with module "requests" and exchanging file of more than 512 bytes, this log can happen in "charset_normalizer" api.py:l107 (https://github.com/jawah/charset_normalizer)

Workaround
I found the following workaround but it should really be seen as only a workaround and I hope a real fix could be deployed

diff --git a/avocado/core/messages.py b/avocado/core/messages.py
index ce77df8f..1ff40bdb 100644
--- a/avocado/core/messages.py
+++ b/avocado/core/messages.py
@@ -367,6 +367,7 @@ class LogMessageHandler(BaseRunningMessageHandler):
         # the Avocado job logging configuration
         log_name = message.get("log_name")
         if log_name is not None and log_name != "avocado.app":
+            logging.addLevelName(5, 'TRACE')
             logger = logging.getLogger(log_name)
             level = logging.getLevelName(message.get("log_levelname"))
             log_message = f"{task.identifier}: {message.get('log').decode(message.get('encoding'))}"

Current behavior
What you are getting?

System information (please complete the following information):

  • OS: Ubuntu 24.04.1 LTS
  • Avocado version: Avocado 108.0
  • Avocado installation method: pip
@tpennors tpennors added the bug label Jan 4, 2025
@mr-avocado mr-avocado bot moved this to Triage in Default project Jan 4, 2025
@richtja
Copy link
Contributor

richtja commented Jan 6, 2025

Hi @tpennors, thank you for reporting this. I was able to reproduce it with this reproducer:

import logging
from avocado import Test


class Test(Test):

    def test(self):
        TRACE = 5
        logger = logging.getLogger("new_logger")
        logger.setLevel(TRACE)
        logger.log(
            TRACE,
            "Test",
        )

output:

Traceback (most recent call last):
  File "/home/janrichter/Avocado/avocado/avocado/plugins/runner_nrunner.py", line 260, in _update_status
    message_handler.process_message(message, task, job)
  File "/home/janrichter/Avocado/avocado/avocado/core/messages.py", line 71, in process_message
    handler.process_message(message, task, job)
  File "/home/janrichter/Avocado/avocado/avocado/core/messages.py", line 89, in process_message
    handler.process_message(message, task, job)
  File "/home/janrichter/Avocado/avocado/avocado/core/messages.py", line 56, in process_message
    self.handle(message, task, job)
  File "/home/janrichter/Avocado/avocado/avocado/core/messages.py", line 374, in handle
    logger.setLevel(level)
  File "/home/janrichter/.pyenv/versions/3.12.0/lib/python3.12/logging/__init__.py", line 1514, in setLevel
    self.level = _checkLevel(level)
                 ^^^^^^^^^^^^^^^^^^
  File "/home/janrichter/.pyenv/versions/3.12.0/lib/python3.12/logging/__init__.py", line 213, in _checkLevel
    raise ValueError("Unknown level: %r" % level)
ValueError: Unknown level: 'Level Level 5'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Triage
Development

No branches or pull requests

2 participants