Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into smart_high_odds
Browse files Browse the repository at this point in the history
  • Loading branch information
1v committed Oct 22, 2021
2 parents d1b3217 + 181d036 commit 96edbb3
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions TwitchChannelPointsMiner/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import os
import platform
from datetime import datetime
from logging.handlers import TimedRotatingFileHandler
from pathlib import Path

Expand Down Expand Up @@ -104,6 +105,7 @@ def __init__(
file_level: int = logging.DEBUG,
emoji: bool = platform.system() != "Windows",
colored: bool = False,
auto_clear: bool = True,
color_palette: ColorPalette = ColorPalette(),
):
self.save = save
Expand All @@ -112,6 +114,7 @@ def __init__(
self.file_level = file_level
self.emoji = emoji
self.colored = colored
self.auto_clear = auto_clear
self.color_palette = color_palette


Expand Down Expand Up @@ -142,18 +145,26 @@ def configure_loggers(username, settings):
if settings.save is True:
logs_path = os.path.join(Path().absolute(), "logs")
Path(logs_path).mkdir(parents=True, exist_ok=True)
logs_file = os.path.join(
logs_path,
f"{username}.log",
)
file_handler = TimedRotatingFileHandler(
logs_file,
when="D",
interval=1,
backupCount=7,
encoding="utf-8",
delay=False,
)
if settings.auto_clear is True:
logs_file = os.path.join(
logs_path,
f"{username}.log",
)
file_handler = TimedRotatingFileHandler(
logs_file,
when="D",
interval=1,
backupCount=7,
encoding="utf-8",
delay=False,
)
else:
logs_file = os.path.join(
logs_path,
f"{username}.{datetime.now().strftime('%Y%m%d-%H%M%S')}.log",
)
file_handler = logging.FileHandler(logs_file, "w", "utf-8")

file_handler.setFormatter(
logging.Formatter(
fmt="%(asctime)s - %(levelname)s - %(name)s - [%(funcName)s]: %(message)s",
Expand Down

0 comments on commit 96edbb3

Please sign in to comment.