Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
feat: ✨ add logger debug setting
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Jul 2, 2022
1 parent 9ae3699 commit fbc648f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import shutil

from utils.constant import PATH
Expand All @@ -14,6 +15,10 @@ def main():
os.mkdir(PATH.DOWNLOADING_DIR_PATH)

factory = Factory()

if '--debug' in sys.argv:
factory.logger.set_debug(True)

Main(factory).main()

shutil.rmtree(PATH.DOWNLOADING_DIR_PATH)
Expand Down
13 changes: 13 additions & 0 deletions utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Logger:

def __init__(self, name: str, file_path: str):
# Logger
self.debug_mode = False
self.logger = logging.getLogger(name)
self.logger.setLevel(logging.INFO)

Expand All @@ -31,6 +32,18 @@ def __init__(self, name: str, file_path: str):
self.critical = self.logger.critical
self.exception = self.logger.exception

def set_debug(self, debug: bool = False):
if debug:
self.debug_mode = True
self.logger.setLevel(logging.DEBUG)
self.ch.setLevel(logging.DEBUG)
self.fh.setLevel(logging.DEBUG)
else:
self.debug_mode = False
self.logger.setLevel(logging.INFO)
self.ch.setLevel(logging.INFO)
self.fh.setLevel(logging.INFO)

def close(self):
self.fh.close()
self.logger.removeHandler(self.fh)

0 comments on commit fbc648f

Please sign in to comment.