Skip to content

Commit 00c597e

Browse files
refactor(logging): make botstrap logging useful
- provide completion message - silence httpcore logger - filter out botcore's warning for patching send_typing - use short url for contributing link - only use logging.warning and up for things that need user action - use logging.fatal when exiting due to error
1 parent 4edc1cb commit 00c597e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

botstrap.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import os
23
import re
34
import sys
@@ -6,11 +7,16 @@
67
from dotenv import load_dotenv
78
from httpx import Client, HTTPStatusError, Response
89

9-
from bot.constants import Webhooks, _Categories, _Channels, _Roles
10-
from bot.log import get_logger
10+
# Filter out the send typing monkeypatch logs from bot core when we import to get constants
11+
logging.getLogger("pydis_core").setLevel(logging.WARNING)
12+
13+
from bot.constants import Webhooks, _Categories, _Channels, _Roles # noqa: E402
14+
from bot.log import get_logger # noqa: E402
1115

1216
load_dotenv()
13-
log = get_logger("Config Bootstrapper")
17+
log = get_logger("botstrap")
18+
# Silence noisy httpcore logger
19+
get_logger("httpcore").setLevel("INFO")
1420

1521
env_file_path = Path(".env.server")
1622
BOT_TOKEN = os.getenv("BOT_TOKEN", None)
@@ -51,10 +57,10 @@ def __getitem__(self, item: str):
5157
try:
5258
return super().__getitem__(item)
5359
except KeyError:
54-
log.warning(f"Couldn't find key: {item} in dict: {self.name} ")
60+
log.fatal(f"Couldn't find key: {item} in dict: {self.name}")
5561
log.warning(
56-
"Please make sure to follow our contribution guideline "
57-
"https://www.pythondiscord.com/pages/guides/pydis-guides/contributing/bot/ "
62+
"Please follow our contribution guidelines "
63+
"https://pydis.com/contributing-bot "
5864
"to guarantee a successful run of botstrap "
5965
)
6066
sys.exit(-1)
@@ -85,7 +91,7 @@ def upgrade_server_to_community_if_necessary(
8591
payload = response.json()
8692

8793
if COMMUNITY_FEATURE not in payload["features"]:
88-
log.warning("This server is currently not a community, upgrading.")
94+
log.info("This server is currently not a community, upgrading.")
8995
payload["features"].append(COMMUNITY_FEATURE)
9096
payload["rules_channel_id"] = rules_channel_id_
9197
payload["public_updates_channel_id"] = announcements_channel_id_
@@ -251,3 +257,5 @@ def create_webhook(self, name: str, channel_id_: int) -> str:
251257

252258
with env_file_path.open("wb") as file:
253259
file.write(config_str.encode("utf-8"))
260+
261+
log.info("Botstrap completed successfully. Configuration has been written to %s", env_file_path)

0 commit comments

Comments
 (0)