Refactor Docker and configuration files for improved structure and functionality
- Updated `.dockerignore` to include additional development and temporary files, enhancing build efficiency. - Modified `.gitignore` to remove unnecessary entries and streamline ignored files. - Enhanced `docker-compose.yml` with health checks, resource limits, and improved environment variable handling for better service management. - Refactored `Dockerfile.bot` to utilize a multi-stage build for optimized image size and security. - Improved `Makefile` with new commands for deployment, migration, and backup, along with enhanced help documentation. - Updated `requirements.txt` to include new dependencies for environment variable management. - Refactored metrics handling in the bot to ensure proper initialization and collection.
This commit is contained in:
@@ -1,24 +1,44 @@
|
||||
import datetime
|
||||
import os
|
||||
|
||||
import sys
|
||||
from loguru import logger
|
||||
|
||||
# Remove default handler
|
||||
logger.remove()
|
||||
|
||||
# Check if running in Docker/container
|
||||
is_container = os.path.exists('/.dockerenv') or os.getenv('DOCKER_CONTAINER') == 'true'
|
||||
|
||||
if is_container:
|
||||
# In container: log to stdout/stderr
|
||||
logger.add(
|
||||
sys.stdout,
|
||||
format="{time:YYYY-MM-DD HH:mm:ss} | {level} | {name} | {line} | {message}",
|
||||
level=os.getenv("LOG_LEVEL", "INFO"),
|
||||
colorize=True
|
||||
)
|
||||
logger.add(
|
||||
sys.stderr,
|
||||
format="{time:YYYY-MM-DD HH:mm:ss} | {level} | {name} | {line} | {message}",
|
||||
level="ERROR",
|
||||
colorize=True
|
||||
)
|
||||
else:
|
||||
# Local development: log to files
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
if not os.path.exists(current_dir):
|
||||
os.makedirs(current_dir)
|
||||
|
||||
today = datetime.date.today().strftime('%Y-%m-%d')
|
||||
filename = f'{current_dir}/helper_bot_{today}.log'
|
||||
|
||||
logger.add(
|
||||
filename,
|
||||
rotation="00:00",
|
||||
retention=f"{os.getenv('LOG_RETENTION_DAYS', '30')} days",
|
||||
format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {name} | {line} | {message}",
|
||||
level=os.getenv("LOG_LEVEL", "INFO"),
|
||||
)
|
||||
|
||||
# Bind logger name
|
||||
logger = logger.bind(name='main_log')
|
||||
|
||||
# Получение сегодняшней даты для имени файла
|
||||
today = datetime.date.today().strftime('%Y-%m-%d')
|
||||
|
||||
# Создание папки для логов
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
if not os.path.exists(current_dir):
|
||||
# Если не существует, создаем ее
|
||||
os.makedirs(current_dir)
|
||||
filename = f'{current_dir}/helper_bot_{today}.log'
|
||||
|
||||
# Настройка формата логов
|
||||
logger.add(
|
||||
filename,
|
||||
rotation="00:00",
|
||||
retention="30 days",
|
||||
format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {name} | {line} | {message}",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user