refactor(core): logging setup and session path

This commit is contained in:
2026-07-29 19:23:52 +05:00
parent 3d5b2a65ce
commit 94eb082692
4 changed files with 17 additions and 13 deletions
+1 -3
View File
@@ -188,8 +188,6 @@ pyvenv.cfg
.venv .venv
pip-selfcheck.json pip-selfcheck.json
*/processed.txt *.txt
processed.txt
*.log *.log
*.session *.session
*/*.session
View File
+14 -8
View File
@@ -1,3 +1,4 @@
import os
import asyncio import asyncio
import logging import logging
@@ -7,6 +8,17 @@ from modules.telegram import TelegramStarsBot
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def setup_logging():
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
handlers=[
logging.FileHandler("logs/bot.log", encoding="utf-8"),
logging.StreamHandler(),
],
)
async def main(): async def main():
try: try:
config = Config() config = Config()
@@ -21,14 +33,8 @@ async def main():
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig( os.makedirs("logs", exist_ok=True)
level=logging.INFO, setup_logging()
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
handlers=[
logging.FileHandler("logs/bot.log", encoding="utf-8"),
logging.StreamHandler(),
],
)
try: try:
asyncio.run(main()) asyncio.run(main())
+2 -2
View File
@@ -46,7 +46,7 @@ class TelegramLinkExtractor:
class TelegramStarsBot: class TelegramStarsBot:
SESSION_NAME = "stars_bot" SESSION_NAME = "storage/stars_bot"
def __init__(self, config: Config): def __init__(self, config: Config):
self.config = config self.config = config
@@ -237,7 +237,7 @@ class TelegramStarsBot:
await asyncio.sleep(self.config.check_interval) await asyncio.sleep(self.config.check_interval)
async def start(self): async def start(self):
is_first_login = not os.path.exists(f"storage/{self.SESSION_NAME}.session") is_first_login = not os.path.exists(f"{self.SESSION_NAME}.session")
if is_first_login: if is_first_login:
logger.info("Сессия Telegram не найдена. Запускаю процесс входа...") logger.info("Сессия Telegram не найдена. Запускаю процесс входа...")