Skip to content

Commit

Permalink
swap prints for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
solumath committed Apr 11, 2024
1 parent e3be553 commit da36f70
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
12 changes: 8 additions & 4 deletions cogs/system/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import disnake
from disnake.ext import commands

Expand All @@ -7,6 +9,8 @@
from . import features
from .messages_cz import MessagesCZ

rubbergod_logger = logging.getLogger("rubbergod")


class View(BaseView):
def __init__(self, bot: commands.Bot, cogs: list[list[tuple[str, str]]]):
Expand Down Expand Up @@ -107,26 +111,26 @@ async def callback(self, inter: disnake.MessageInteraction) -> None:
if cog in self.unloaded_cogs():
try:
self.bot.load_extension(f"cogs.{cog}")
print(MessagesCZ.success_load(cog=cog))
rubbergod_logger.info(MessagesCZ.success_load(cog=cog))
except Exception as e:
await inter.send(f"Loading error\n`{e}`")
else:
try:
self.bot.unload_extension(f"cogs.{cog}")
print(MessagesCZ.success_unload(cog=cog))
rubbergod_logger.info(MessagesCZ.success_unload(cog=cog))
except Exception as e:
await inter.send(f"Unloading error\n`{e}`")
else:
cogs = set()
for cog in self.values:
try:
self.bot.reload_extension(f"cogs.{cog}")
print(MessagesCZ.success_reload(cog=cog))
rubbergod_logger.info(MessagesCZ.success_reload(cog=cog))
cogs.add(cog)
except Exception as e:
await inter.send(f"Reloading error\n`{e}`")
if cogs:
await inter.send(MessagesCZ.success_reload(cogs=", ".join(cogs)))
await inter.send(MessagesCZ.success_reload(cog=", ".join(cogs)))

self.options = self.create_select()
await self.message.edit(embed=features.create_embed(self.bot), view=self._view)
4 changes: 3 additions & 1 deletion cogs/warden/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# stolen from rubbergoddess
import asyncio
import logging
import time

import dhash
Expand All @@ -19,6 +20,7 @@
from .messages_cz import MessagesCZ

dhash.force_pil()
rubbegod_logger = logging.getLogger("rubbergod")


class Warden(Base, commands.Cog):
Expand Down Expand Up @@ -84,7 +86,7 @@ async def handle_reaction(self, ctx):
await orig.remove_reaction("🤷🏻", self.bot.user)
await orig.remove_reaction("🤔", self.bot.user)
except Exception as e:
print("Warden:on_raw_reaction_add", "Could not remove bot's emote", e)
rubbegod_logger.warning("Warden:handle_reaction", "Could not remove bot's emote", e)
try:
await message.delete()
except disnake.errors.NotFound:
Expand Down
11 changes: 7 additions & 4 deletions database/db_migrations.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re

from config.app_config import config
Expand All @@ -21,6 +22,8 @@
from database.verification import PermitDB, ValidPersonDB
from database.vote import VoteDB # noqa: F401

rubbergod_logger = logging.getLogger("rubbergod")


def init_db(commit: bool = True):
# database.base.metadata.drop_all(database.db)
Expand All @@ -40,11 +43,11 @@ def load_dump(filename: str):
session.query(HugsTableDB).delete()
session.commit()

print(f"Loading dump from {filename}")
rubbergod_logger.info(f"Loading dump from {filename}")

data = database.base.metadata.tables.keys()
for row in data:
print(row)
rubbergod_logger.info(row)

with open(filename, "r", encoding="utf-8") as backup_file:
data = backup_file.readlines()
Expand Down Expand Up @@ -113,6 +116,6 @@ def load_subjects():
subjects = list(set(config.subjects))

for subject in subjects:
print(f"Importing subject {subject}")
rubbergod_logger.info(f"Importing subject {subject}")
SubjectDB.add(subject)
print("Import complete")
rubbergod_logger.info("Import complete")
5 changes: 4 additions & 1 deletion features/error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import logging
import sys
import traceback
from functools import cached_property
Expand All @@ -22,6 +23,8 @@
from database.stats import ErrorEvent
from permissions import custom_errors, permission_check

rubbegod_logger = logging.getLogger("rubbergod")


class ContextMock:
"""Create event context similar to commands.Context
Expand Down Expand Up @@ -98,7 +101,7 @@ def set_image(self, embed: disnake.Embed, user: disnake.User, count: int):
embed.set_image(file=file)
except Exception as error:
output = "".join(traceback.format_exception(type(error), error, error.__traceback__))
print(output)
rubbegod_logger.warning(output)

def log_error_time(self, set=True) -> int:
"""Log details of last exception and return number of days since last exception"""
Expand Down

0 comments on commit da36f70

Please sign in to comment.