Skip to content

Commit 181d036

Browse files
committed
auto_clear logs in settings :)
1 parent 05b6bd1 commit 181d036

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ You can combine all priority but keep in mind that use `ORDER` and `POINTS_ASCEN
297297
| `file_level` | level | logging.DEBUG | Level of logs in file save - If you think the log file it's too big, use logging.INFO |
298298
| `emoji` | bool | For Windows is False else True | On Windows, we have a problem printing emoji. Set to false if you have a problem |
299299
| `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) |
300+
| `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) |
300301
| `color_palette` | ColorPalette | All messages are Fore.RESET except WIN and LOSE bet (GREEN and RED) | Create your custom color palette. Read more above. |
301302

302303
#### Color Palette

TwitchChannelPointsMiner/logger.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import os
33
import platform
4+
from datetime import datetime
45
from logging.handlers import TimedRotatingFileHandler
56
from pathlib import Path
67

@@ -104,6 +105,7 @@ def __init__(
104105
file_level: int = logging.DEBUG,
105106
emoji: bool = platform.system() != "Windows",
106107
colored: bool = False,
108+
auto_clear: bool = True,
107109
color_palette: ColorPalette = ColorPalette(),
108110
):
109111
self.save = save
@@ -112,6 +114,7 @@ def __init__(
112114
self.file_level = file_level
113115
self.emoji = emoji
114116
self.colored = colored
117+
self.auto_clear = auto_clear
115118
self.color_palette = color_palette
116119

117120

@@ -142,18 +145,26 @@ def configure_loggers(username, settings):
142145
if settings.save is True:
143146
logs_path = os.path.join(Path().absolute(), "logs")
144147
Path(logs_path).mkdir(parents=True, exist_ok=True)
145-
logs_file = os.path.join(
146-
logs_path,
147-
f"{username}.log",
148-
)
149-
file_handler = TimedRotatingFileHandler(
150-
logs_file,
151-
when="D",
152-
interval=1,
153-
backupCount=7,
154-
encoding="utf-8",
155-
delay=False,
156-
)
148+
if settings.auto_clear is True:
149+
logs_file = os.path.join(
150+
logs_path,
151+
f"{username}.log",
152+
)
153+
file_handler = TimedRotatingFileHandler(
154+
logs_file,
155+
when="D",
156+
interval=1,
157+
backupCount=7,
158+
encoding="utf-8",
159+
delay=False,
160+
)
161+
else:
162+
logs_file = os.path.join(
163+
logs_path,
164+
f"{username}.{datetime.now().strftime('%Y%m%d-%H%M%S')}.log",
165+
)
166+
file_handler = logging.FileHandler(logs_file, "w", "utf-8")
167+
157168
file_handler.setFormatter(
158169
logging.Formatter(
159170
fmt="%(asctime)s - %(levelname)s - %(name)s - [%(funcName)s]: %(message)s",

0 commit comments

Comments
 (0)