Skip to content

Commit

Permalink
auto_clear logs in settings :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkd-Alex committed Oct 11, 2021
1 parent 05b6bd1 commit 181d036
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ You can combine all priority but keep in mind that use `ORDER` and `POINTS_ASCEN
| `file_level` | level | logging.DEBUG | Level of logs in file save - If you think the log file it's too big, use logging.INFO |
| `emoji` | bool | For Windows is False else True | On Windows, we have a problem printing emoji. Set to false if you have a problem |
| `colored` | bool | True | If you want to print colored text [#45](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/45) [#82](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/82) |
| `auto_clear` | bool | True | Create a file rotation handler with interval = 1D and backupCount = 7 [#215](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/215) |
| `color_palette` | ColorPalette | All messages are Fore.RESET except WIN and LOSE bet (GREEN and RED) | Create your custom color palette. Read more above. |

#### Color Palette
Expand Down
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 181d036

Please sign in to comment.