Repository: attzonko/mmpy_bot (language: python)

Issue:
Disable httpx logging?
The logs for my bot are most filled with `INFO` level messages like
```
[03/08/2024 14:32:48][httpx][INFO] HTTP Request: GET https://mattermost.example/api/v4/channels/hdjdsjkjsyhyhiiid932ls7jcz/posts "HTTP/1.1 200 OK"
```

Is there a way to log only errors?



Discussion / hints:
Did you try configuring [`httpx` logging](https://www.python-httpx.org/logging/)?

If this by itself doesn't produce the desired output, you can initialize the bot class with `Bot(enable_logging=False)` (documented [here](https://github.com/attzonko/mmpy_bot/blob/fc75cf452f334a58f91555fa48d61f47286b40dd/mmpy_bot/bot.py#L32)) and then [register your own logging handlers](https://github.com/attzonko/mmpy_bot/blob/fc75cf452f334a58f91555fa48d61f47286b40dd/mmpy_bot/bot.py#L78).

Fix patch:
diff --git a/mmpy_bot/bot.py b/mmpy_bot/bot.py
index 6a5b5f69..e9d917bf 100644
--- a/mmpy_bot/bot.py
+++ b/mmpy_bot/bot.py
@@ -80,7 +80,9 @@ def _register_logger(self):
             **{
                 "format": self.settings.LOG_FORMAT,
                 "datefmt": self.settings.LOG_DATE_FORMAT,
-                "level": logging.DEBUG if self.settings.DEBUG else logging.INFO,
+                "level": (
+                    logging.DEBUG if self.settings.DEBUG else self.settings.LOG_LEVEL
+                ),
                 "filename": self.settings.LOG_FILE,
                 "filemode": "w",
             }
diff --git a/mmpy_bot/settings.py b/mmpy_bot/settings.py
index 7ce9aa24..4b2753cf 100644
--- a/mmpy_bot/settings.py
+++ b/mmpy_bot/settings.py
@@ -1,4 +1,5 @@
 import collections
+import logging
 import os
 import warnings
 from dataclasses import dataclass, field, fields
@@ -59,6 +60,7 @@ class Settings:
     DEBUG: bool = False
     # Respond to channel message "!help" (without @bot)
     RESPOND_CHANNEL_HELP: bool = False
+    LOG_LEVEL: int = logging.INFO
     LOG_FILE: Optional[str] = None
     LOG_FORMAT: str = "[%(asctime)s][%(name)s][%(levelname)s] %(message)s"
     LOG_DATE_FORMAT: str = "%m/%d/%Y %H:%M:%S"
@@ -91,6 +93,13 @@ def __post_init__(self):
             )
             self.MATTERMOST_API_PATH = self.MATTERMOST_API_PATH[: -len(api_url)]
 
+        if self.DEBUG:
+            warnings.warn(
+                "DEBUG has been deprecated and will be removed in a future release. "
+                "Set LOG_LEVEL to logging.DEBUG to increase verbosity.",
+                DeprecationWarning,
+            )
+
     def _check_environment_variables(self):
         for f in fields(self):
             if f.name in os.environ:


Test patch:
diff --git a/tests/unit_tests/bot_test.py b/tests/unit_tests/bot_test.py
index 7d2f076f..97a1d59d 100644
--- a/tests/unit_tests/bot_test.py
+++ b/tests/unit_tests/bot_test.py
@@ -1,3 +1,4 @@
+import logging
 from unittest import mock
 
 import pytest
@@ -12,7 +13,7 @@
 def bot():
     # Patch login to avoid sending requests to the internet
     with mock.patch("mmpy_bot.driver.Driver.login") as login:
-        bot = Bot(plugins=[ExamplePlugin()], settings=Settings(DEBUG=True))
+        bot = Bot(plugins=[ExamplePlugin()], settings=Settings(LOG_LEVEL=logging.DEBUG))
         login.assert_called_once()
         yield bot
         bot.stop()  # if the bot was started, stop it