feat: add proper logging
This commit is contained in:
parent
d56bac1b2f
commit
e3982c064d
@ -1,3 +1,5 @@
|
||||
from logging import error
|
||||
|
||||
import disnake
|
||||
|
||||
import utils
|
||||
@ -6,7 +8,7 @@ from state import client, players
|
||||
|
||||
def play_after_callback(e, message, once):
|
||||
if e:
|
||||
print(f"player error: {e}")
|
||||
error(f"player error: {e}")
|
||||
if not once:
|
||||
play_next(message)
|
||||
|
||||
|
8
core.py
8
core.py
@ -6,6 +6,7 @@ import io
|
||||
import textwrap
|
||||
import time
|
||||
import traceback
|
||||
from logging import debug
|
||||
|
||||
import disnake
|
||||
import disnake_paginator
|
||||
@ -60,7 +61,7 @@ async def on_message(message, edited=False):
|
||||
|
||||
end = time.time()
|
||||
if __debug__:
|
||||
print(f"reloaded {len(reloaded_modules)} in {round(end-start, 2)}s")
|
||||
debug(f"reloaded {len(reloaded_modules)} modules in {round(end-start, 2)}s")
|
||||
|
||||
await utils.add_check_reaction(message)
|
||||
case C.EXECUTE if message.author.id in constants.OWNERS:
|
||||
@ -132,12 +133,11 @@ async def on_message(message, edited=False):
|
||||
case C.FAST_FORWARD:
|
||||
await commands.voice.fast_forward(message)
|
||||
except Exception as e:
|
||||
formatted_exception = "".join(traceback.format_exception(e))
|
||||
print(formatted_exception)
|
||||
await utils.reply(
|
||||
message,
|
||||
f"exception occurred while processing command: ```\n{formatted_exception.replace("`", "\\`")}```",
|
||||
f"exception occurred while processing command: ```\n{"".join(traceback.format_exception(e)).replace("`", "\\`")}```",
|
||||
)
|
||||
raise e
|
||||
|
||||
|
||||
async def on_voice_state_update(_, before, after):
|
||||
|
@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import threading
|
||||
import time
|
||||
from logging import info
|
||||
|
||||
import commands
|
||||
import core
|
||||
@ -39,7 +40,7 @@ async def on_message_edit(before, after):
|
||||
|
||||
|
||||
async def on_ready():
|
||||
print(f"logged in as {client.user} in {round(time.time() - start_time, 1)}s")
|
||||
info(f"logged in as {client.user} in {round(time.time() - start_time, 1)}s")
|
||||
|
||||
|
||||
async def on_voice_state_update(member, before, after):
|
||||
|
11
main.py
11
main.py
@ -1,7 +1,18 @@
|
||||
import logging
|
||||
|
||||
import constants
|
||||
import events
|
||||
from state import client
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(
|
||||
format=(
|
||||
"%(asctime)s %(levelname)s %(name):%(module)s %(message)s"
|
||||
if __debug__
|
||||
else "%(asctime)s %(levelname)s %(message)s"
|
||||
),
|
||||
datefmt="%Y-%m-%d %T",
|
||||
level=logging.DEBUG if __debug__ else logging.INFO,
|
||||
)
|
||||
events.prepare()
|
||||
client.run(constants.SECRETS["TOKEN"])
|
||||
|
7
tasks.py
7
tasks.py
@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import time
|
||||
from logging import debug, error
|
||||
|
||||
import disnake
|
||||
|
||||
@ -7,6 +8,8 @@ from state import client, idle_tracker, players
|
||||
|
||||
|
||||
async def cleanup():
|
||||
debug("spawned cleanup thread")
|
||||
|
||||
while True:
|
||||
await asyncio.sleep(3600 * 12)
|
||||
|
||||
@ -17,7 +20,7 @@ async def cleanup():
|
||||
for target in targets:
|
||||
del players[target]
|
||||
if __debug__:
|
||||
print(f"cleanup removed {len(targets)} empty players")
|
||||
debug(f"cleanup removed {len(targets)} empty players")
|
||||
|
||||
if (
|
||||
not idle_tracker["is_idle"]
|
||||
@ -27,4 +30,4 @@ async def cleanup():
|
||||
await client.change_presence(status=disnake.Status.idle)
|
||||
idle_tracker["is_idle"] = True
|
||||
except Exception as e:
|
||||
print(f"failed to change status to idle: {e}")
|
||||
error(f"failed to change status to idle: {e}")
|
||||
|
7
utils.py
7
utils.py
@ -1,4 +1,5 @@
|
||||
import os
|
||||
from logging import error, info, warning
|
||||
|
||||
import disnake
|
||||
|
||||
@ -103,13 +104,13 @@ def filter_secrets(text: str) -> str:
|
||||
|
||||
|
||||
def load_opus():
|
||||
print("opus wasn't automatically loaded! trying to load manually...")
|
||||
warning("opus wasn't automatically loaded! trying to load manually...")
|
||||
for path in ["/usr/lib64/libopus.so.0", "/usr/lib/libopus.so.0"]:
|
||||
if os.path.exists(path):
|
||||
try:
|
||||
disnake.opus.load_opus(path)
|
||||
print(f"successfully loaded opus from {path}")
|
||||
info(f"successfully loaded opus from {path}")
|
||||
return
|
||||
except Exception as e:
|
||||
print(f"failed to load opus from {path}: {e}")
|
||||
error(f"failed to load opus from {path}: {e}")
|
||||
raise Exception("could not locate working opus library")
|
||||
|
Loading…
x
Reference in New Issue
Block a user