proper path constants, logging level constant, file & stream logging

This commit is contained in:
Xevion
2021-01-24 14:22:09 -06:00
parent bc1a6c5d7e
commit bf09c13d6c
6 changed files with 34 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ import discord
from discord.ext.tasks import loop
logger = logging.getLogger(__file__)
logger.setLevel(logging.DEBUG)
logger.setLevel(constants.LOGGING_LEVEL)
class UnbelievaClient(discord.Client):

View File

@@ -1,3 +1,16 @@
import logging
import os
from collections import namedtuple
# Path Constants
BASE_DIR = os.path.dirname(os.path.abspath(os.path.join(__file__, '..')))
STATIC_DIR = os.path.join(BASE_DIR, 'bot', 'static')
TOKEN = os.path.join(BASE_DIR, 'token.dat')
DATABASE = os.path.join(BASE_DIR, 'database.db')
# Other constants
LOGGING_LEVEL = logging.DEBUG
# NamedTuple Classes
PlayOptions = namedtuple('PlayOptions', ['hit', 'stand', 'double', 'split'])

View File

@@ -3,7 +3,7 @@ from pprint import pprint
import discord
def print(embed: discord.Embed) -> None:
def print_embed(embed: discord.Embed) -> None:
pprint((
embed.title,
embed.description,

View File

@@ -4,8 +4,10 @@ from abc import ABC
import discord
from bot import constants
logger = logging.getLogger(__file__)
logger.setLevel(logging.DEBUG)
logger.setLevel(constants.LOGGING_LEVEL)
class BaseMessage(object):

View File

@@ -1,7 +1,11 @@
import logging
import time
from typing import Union, Optional
from bot import exceptions
from bot import exceptions, constants
logger = logging.getLogger(__file__)
logger.setLevel(constants.LOGGING_LEVEL)
class Cooldown(object):

14
main.py
View File

@@ -1,11 +1,9 @@
import argparse
import logging
from bot import constants
from bot.client import UnbelievaClient
logging.basicConfig(format='[%(asctime)s] [%(levelname)s] [%(funcName)s] %(message)s')
logger = logging.getLogger(__file__)
logger.setLevel(logging.DEBUG)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Start the discord bot.')
@@ -14,6 +12,16 @@ if __name__ == "__main__":
parser.add_argument('bot', metavar='BOT', type=int, help='The ID of the UnbelievaBoat bot to target.')
parsed = parser.parse_args()
logger = logging.getLogger(__file__)
# noinspection PyArgumentList
logging.basicConfig(format='[%(asctime)s] [%(levelname)s] [%(funcName)s] %(message)s',
handlers=[
logging.FileHandler(f"bot-{parsed.channel}.log"),
logging.StreamHandler()
])
logger.setLevel(constants.LOGGING_LEVEL)
client = UnbelievaClient(parsed.bot, parsed.channel)
logger.info('Starting bot.')