feat(bot.py): 修改 logger 格式

修改 logger 格式

Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
Ching 2023-09-17 16:35:11 +08:00
parent f8e954910b
commit df9e629cdb
3 changed files with 11 additions and 5 deletions

View File

@ -6,8 +6,14 @@ import dota
import utils import utils
logging.basicConfig(filename='/root/develop/log/dotabot.log', level=logging.INFO) formatter = logging.Formatter('%(levelname)s %(name)s %(asctime)s %(message)s', '%Y-%m-%d %H:%M:%S')
log_handler = logging.FileHandler(utils.logger_file)
log_handler.setFormatter(formatter)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.addHandler(log_handler)
logger.propagate = False
logger.info('start bot')
# bot = discord.Bot(proxy='http://127.0.0.1:1235') # bot = discord.Bot(proxy='http://127.0.0.1:1235')
bot = discord.Bot() bot = discord.Bot()
@ -31,7 +37,7 @@ async def send_message(channel):
return return
for match_ in matches: for match_ in matches:
data = dota.serialize_match_for_discord(match_) data = dota.serialize_match_for_discord(match_)
logger.info(f'sending match {match_.match_id}, {data}') logger.info(f"sending match {match_['match_id']}, {data}")
await channel.send(content=data['content'], embeds=[discord.Embed.from_dict(embed) for embed in data['embeds']]) await channel.send(content=data['content'], embeds=[discord.Embed.from_dict(embed) for embed in data['embeds']])
@tasks.loop(minutes=1) @tasks.loop(minutes=1)

View File

@ -6,8 +6,6 @@ import logging
import players import players
import utils import utils
logging.basicConfig(filename='/root/develop/log/dotabot.log', level=logging.INFO)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -2,8 +2,10 @@ import datetime
import requests import requests
import logging import logging
# logger_file = '/root/develop/log/dotabot.log'
logger_file = 'dotabot.log'
logging.basicConfig(filename='/root/develop/log/dotabot.log', level=logging.INFO) logging.basicConfig(filename=logger_file, level=logging.INFO)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def convert_seconds_to_hms(total_seconds): def convert_seconds_to_hms(total_seconds):