Skip to content

Commit

Permalink
feat: change log handler to RotatingFileHandler (#111)
Browse files Browse the repository at this point in the history
* change logger to `RotatingFIleHandler`

* changed log filename
  • Loading branch information
s-Sizz authored Feb 10, 2023
1 parent bab4542 commit 97a8682
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/Logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import logging.config
from datetime import datetime
from logging.handlers import RotatingFileHandler

FILE_SIZE = 1024 * 1024 * 100 # 100 MB
BACKUP_COUNT = 5 # keep up to 5 files


class Logger:
Expand All @@ -11,10 +13,18 @@ def createLogger(debug: bool):
else:
level = logging.WARNING

logging.basicConfig(filename=f'./logs/capsulefarmer-{datetime.now().strftime("%Y-%m-%d")}.log',
filemode="a+",
format='%(asctime)s %(levelname)s: %(message)s',
level=level)
fileHandler = RotatingFileHandler(
"./logs/capsulefarmer.log",
mode="a+",
maxBytes=FILE_SIZE,
backupCount=BACKUP_COUNT,
)

logging.basicConfig(
format="%(asctime)s %(levelname)s: %(message)s",
level=level,
handlers=[fileHandler],
)
log = logging.getLogger("League of Poro")
log.info("-------------------------------------------------")
log.info("---------------- Program started ----------------")
Expand Down

0 comments on commit 97a8682

Please sign in to comment.