mirror of
https://github.com/rangermix/TwitchDropsMiner.git
synced 2026-05-26 07:08:04 +00:00
feat:
- add date to console log - add timezone to logger - use python-alpine to make image size less than 1/10
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3
|
FROM python:3-alpine
|
||||||
|
|
||||||
# Build arguments for metadata
|
# Build arguments for metadata
|
||||||
ARG BUILD_DATE
|
ARG BUILD_DATE
|
||||||
@@ -25,11 +25,6 @@ ENV PYTHONUNBUFFERED=1 \
|
|||||||
# Set working directory
|
# Set working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install system dependencies
|
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
--no-install-recommends \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Copy project metadata and install dependencies
|
# Copy project metadata and install dependencies
|
||||||
COPY pyproject.toml .
|
COPY pyproject.toml .
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
# Mount data directory for persistent storage
|
# Mount data directory for persistent storage
|
||||||
- ./data:/app/data
|
- ./data:/app/data
|
||||||
|
- ./logs:/app/logs
|
||||||
environment:
|
environment:
|
||||||
# Set timezone (optional, defaults to UTC)
|
# Set timezone (optional, defaults to UTC)
|
||||||
- TZ=UTC
|
- TZ=Australia/Sydney
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ name = "twitch-drops-miner"
|
|||||||
version = "1.1.2" # Update from src/version.py as needed
|
version = "1.1.2" # Update from src/version.py as needed
|
||||||
description = "Automatically mine Twitch drops without downloading stream data"
|
description = "Automatically mine Twitch drops without downloading stream data"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aiohttp>=3.9",
|
"aiohttp>=3.9",
|
||||||
"truststore",
|
"truststore",
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
@@ -8,6 +7,7 @@ import sys
|
|||||||
import traceback
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
from logging.handlers import TimedRotatingFileHandler
|
from logging.handlers import TimedRotatingFileHandler
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import truststore
|
import truststore
|
||||||
|
|
||||||
@@ -23,21 +23,27 @@ if __name__ == "__main__":
|
|||||||
from src.version import __version__
|
from src.version import __version__
|
||||||
|
|
||||||
logger = logging.getLogger("TwitchDrops")
|
logger = logging.getLogger("TwitchDrops")
|
||||||
# Force INFO level logging by default for better visibility
|
|
||||||
logger.setLevel(logging.INFO)
|
|
||||||
if logger.level < logging.INFO:
|
if logger.level < logging.INFO:
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
# Always add console handler
|
# Always add console handler
|
||||||
console_handler = logging.StreamHandler(sys.stdout)
|
console_handler = logging.StreamHandler(sys.stdout)
|
||||||
console_handler.setFormatter(FILE_FORMATTER)
|
console_handler.setFormatter(FILE_FORMATTER)
|
||||||
logger.addHandler(console_handler)
|
logger.addHandler(console_handler)
|
||||||
|
|
||||||
|
# Create logs directory if it doesn't exist
|
||||||
|
logs_dir = Path("logs")
|
||||||
|
logs_dir.mkdir(exist_ok=True)
|
||||||
|
log_file = logs_dir / "TDM.log"
|
||||||
|
|
||||||
|
# Add file handler for timestamped log
|
||||||
|
file_handler = TimedRotatingFileHandler(log_file, when="midnight", backupCount=5)
|
||||||
|
file_handler.setFormatter(FILE_FORMATTER)
|
||||||
|
logger.addHandler(file_handler)
|
||||||
|
|
||||||
logger.info("Logger initialized")
|
logger.info("Logger initialized")
|
||||||
|
|
||||||
warnings.simplefilter("default", ResourceWarning)
|
warnings.simplefilter("default", ResourceWarning)
|
||||||
|
|
||||||
if sys.version_info < (3, 10):
|
|
||||||
raise RuntimeError("Python 3.10 or higher is required")
|
|
||||||
|
|
||||||
class ParsedArgs(argparse.Namespace):
|
class ParsedArgs(argparse.Namespace):
|
||||||
_verbose: int
|
_verbose: int
|
||||||
_debug_ws: bool
|
_debug_ws: bool
|
||||||
@@ -101,22 +107,8 @@ if __name__ == "__main__":
|
|||||||
if settings.language:
|
if settings.language:
|
||||||
_.set_language(settings.language)
|
_.set_language(settings.language)
|
||||||
|
|
||||||
# Always log to file with timestamped filename in ./logs/ directory
|
# logging.getLogger("TwitchDrops.gql").setLevel(settings.debug_gql)
|
||||||
from pathlib import Path
|
# logging.getLogger("TwitchDrops.websocket").setLevel(settings.debug_ws)
|
||||||
|
|
||||||
# Create logs directory if it doesn't exist
|
|
||||||
logs_dir = Path("logs")
|
|
||||||
logs_dir.mkdir(exist_ok=True)
|
|
||||||
log_file = logs_dir / "TDM.log"
|
|
||||||
|
|
||||||
# Add file handler for timestamped log
|
|
||||||
file_handler = TimedRotatingFileHandler(log_file, when="midnight", backupCount=5)
|
|
||||||
file_handler.setFormatter(FILE_FORMATTER)
|
|
||||||
logger.addHandler(file_handler)
|
|
||||||
logger.info(f"Logging to file: {log_file}")
|
|
||||||
|
|
||||||
logging.getLogger("TwitchDrops.gql").setLevel(settings.debug_gql)
|
|
||||||
logging.getLogger("TwitchDrops.websocket").setLevel(settings.debug_ws)
|
|
||||||
|
|
||||||
logger.info("=== TwitchDropsMiner Starting ===")
|
logger.info("=== TwitchDropsMiner Starting ===")
|
||||||
logger.info(f"Version: {__version__}")
|
logger.info(f"Version: {__version__}")
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ from .constants import (
|
|||||||
MAX_TOPICS,
|
MAX_TOPICS,
|
||||||
MAX_WEBSOCKETS,
|
MAX_WEBSOCKETS,
|
||||||
ONLINE_DELAY,
|
ONLINE_DELAY,
|
||||||
OUTPUT_FORMATTER,
|
|
||||||
PING_INTERVAL,
|
PING_INTERVAL,
|
||||||
PING_TIMEOUT,
|
PING_TIMEOUT,
|
||||||
TOPICS_PER_CHANNEL,
|
TOPICS_PER_CHANNEL,
|
||||||
@@ -45,7 +44,6 @@ __all__ = [
|
|||||||
# constants.py
|
# constants.py
|
||||||
"CALL",
|
"CALL",
|
||||||
"FILE_FORMATTER",
|
"FILE_FORMATTER",
|
||||||
"OUTPUT_FORMATTER",
|
|
||||||
"LOGGING_LEVELS",
|
"LOGGING_LEVELS",
|
||||||
"State",
|
"State",
|
||||||
"WebsocketTopic",
|
"WebsocketTopic",
|
||||||
|
|||||||
@@ -27,11 +27,10 @@ LOGGING_LEVELS = {
|
|||||||
4: logging.DEBUG,
|
4: logging.DEBUG,
|
||||||
}
|
}
|
||||||
FILE_FORMATTER = logging.Formatter(
|
FILE_FORMATTER = logging.Formatter(
|
||||||
"{asctime}.{msecs:03.0f}:\t{levelname:>7}:\t{filename}:{lineno}:\t{message}",
|
"{asctime}:\t{levelname:>7}:\t{filename}:{lineno}:\t{message}",
|
||||||
style="{",
|
style="{",
|
||||||
datefmt="%Y-%m-%d %H:%M:%S",
|
datefmt="%Y-%m-%dT%H:%M:%S%z",
|
||||||
)
|
)
|
||||||
OUTPUT_FORMATTER = logging.Formatter("{levelname}: {message}", style="{", datefmt="%H:%M:%S")
|
|
||||||
|
|
||||||
# Type aliases
|
# Type aliases
|
||||||
JsonType = dict[str, Any]
|
JsonType = dict[str, Any]
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ class ConsoleOutputManager:
|
|||||||
Args:
|
Args:
|
||||||
message: The message to display
|
message: The message to display
|
||||||
"""
|
"""
|
||||||
timestamp = datetime.now().strftime("%H:%M:%S")
|
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
line = f"[{timestamp}] {message}"
|
line = f"[{timestamp}] | {message}"
|
||||||
self._buffer.append(line)
|
self._buffer.append(line)
|
||||||
asyncio.create_task(self._broadcaster.emit("console_output", {"message": line}))
|
asyncio.create_task(self._broadcaster.emit("console_output", {"message": line}))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user