Skip to content

Commit 7392531

Browse files
add logging
1 parent 34442dd commit 7392531

8 files changed

+35
-12
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ __pycache__/
66
# C extensions
77
*.so
88

9+
# vsc
10+
.vscode/
11+
912
# Distribution / packaging
1013
.Python
1114
build/

.pre-commit-config.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ repos:
2929
rev: 21.12b0
3030
hooks:
3131
- id: black
32-
name: Running black in all files.
32+
name: Running black in all files.
33+
additional_dependencies: ["click==8.0.4"]

dev-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ isort~=5.10.1
33
pre-commit~=2.17.0
44

55
# Flake8 plugins
6-
flake8-docstrings~=1.6.0
6+
flake8-docstrings~=1.6.0

main.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
from src import Glykon
32

43
if __name__ == "__main__":

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
disnake
2-
python-dotenv
2+
python-dotenv

src/bot.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1+
import logging
12
import os
3+
24
from disnake import Intents
35
from disnake.ext.commands import Bot
4-
56
from dotenv import load_dotenv
67

78
load_dotenv(dotenv_path="./.env")
89
TOKEN = os.getenv("TOKEN")
910

11+
# Logger config
12+
logger = logging.getLogger("disnake")
13+
logger.setLevel(logging.DEBUG)
14+
15+
# Handler config
16+
handler = logging.FileHandler(filename="bot.log", encoding="utf-8", mode="w")
17+
handler.setFormatter(
18+
logging.Formatter(
19+
"%(asctime)s || %(levelname)s || %(name)s || %(message)s",
20+
"%b %d %Y %I:%M:%S %p",
21+
)
22+
)
23+
logger.addHandler(handler)
24+
1025

1126
class Glykon(Bot):
1227
"""Bots class"""
@@ -20,6 +35,7 @@ def __init__(self):
2035
)
2136

2237
def load_cogs(self) -> None:
38+
"""Load cogs from the src/cogs directory"""
2339
for file in os.listdir("./src/cogs"):
2440
if file.startswith("_"):
2541
continue
@@ -28,19 +44,20 @@ def load_cogs(self) -> None:
2844
self.load_extension(f"src.cogs.{file[:-3]}")
2945

3046
async def on_ready(self) -> None:
31-
print(
47+
"""On bot ready"""
48+
logger.info(
3249
f"""
3350
───── ⋆⋅☆⋅⋆ ─────
3451
WELCOME TO {self.user.display_name}
35-
⤷ Servers 💿: {len(self.guilds)}
36-
⤷ Users 👥: {len(self.users)}
37-
⤷ Cogs ⚙️: {len(self.cogs)}
52+
⤷ Servers 💿: {len(self.guilds)}
53+
⤷ Users 👥: {len(self.users)}
54+
⤷ Cogs ⚙️: {len(self.cogs)}
3855
───── ⋆⋅☆⋅⋆ ─────
39-
🟢 Ready 🟢
56+
Status: Ready 🟢
4057
"""
4158
)
4259

4360
def run(self) -> None:
61+
"""Run the bot"""
4462
self.load_cogs()
4563
super().run(TOKEN, reconnect=True)
46-

src/src.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### SRC
2+
3+
bot's core files are found here.

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ ignore=
1515
E266
1616

1717
[isort]
18-
multi_line_output=5
18+
multi_line_output=5

0 commit comments

Comments
 (0)