From bd0601e115629615038b8955175cce4bc39c8b2da681c8a7e958a2e1caa8f2a3 Mon Sep 17 00:00:00 2001 From: andrea Date: Sat, 26 Jul 2025 23:59:35 +0200 Subject: [PATCH] better log name --- bot_libs/special_commands.py | 2 +- utils/logs.py | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bot_libs/special_commands.py b/bot_libs/special_commands.py index d62bdc3..1a47440 100644 --- a/bot_libs/special_commands.py +++ b/bot_libs/special_commands.py @@ -43,7 +43,7 @@ async def show_logs(update, context): try: game_log= _os.path.expanduser(f'{_botsyms.BOT_PATH}/battle_royale.log') with open(game_log, 'r') as _log_file: - lines= _log_file.readlines()[-10:] + lines= _log_file.readlines()[-30:] log_content= '\n'.join(lines) await update.message.reply_text(f"Contenuto del log:\n{log_content}") except Exception as e: diff --git a/utils/logs.py b/utils/logs.py index 41c6597..574802a 100644 --- a/utils/logs.py +++ b/utils/logs.py @@ -1,7 +1,20 @@ import logging as _logging +from datetime import datetime as _dt -logger = _logging.getLogger(__name__) -_logging.basicConfig(filename= 'battle_royale.log', encoding= 'utf-8', format='%(asctime)s - %(levelname)s - %(message)s', level= _logging.INFO) +logger= _logging.getLogger(__name__) + +def get_log_name(): + now= _dt.now() + year= now.year + month= now.month + if month < 10: month= f'0{month}' + day= now.day + if day < 10: day= f'0{day}' + #fname= f'battle_royale-{now.year}{month}{day}-{now.time()}.log' + fname= f'battle_royale-{now.year}{month}{day}.log' + return fname + +_logging.basicConfig(filename= get_log_name(), encoding= 'utf-8', format='%(asctime)s - %(levelname)s - %(message)s', level= _logging.INFO) def log_debug(txt): logger.debug(txt)