-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logging and try to collect errors
- Loading branch information
1 parent
180def0
commit 91d03a6
Showing
5 changed files
with
90 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
**__pycache__/ | ||
Logs/ | ||
Output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
import logging.handlers | ||
def logger_factory(name:str,level:int=logging.INFO)->logging.Logger: | ||
""" | ||
Generate a logger with file and console handler. | ||
Args: | ||
name: the name of the logger and the indicator of the log file | ||
level: the level of the logger | ||
Returns: | ||
logger: an instance of logging.Logger that has been configured | ||
""" | ||
logger = logging.getLogger(name) | ||
logger.setLevel(level) | ||
# check if the console handler exists | ||
console_handler_exists = any( | ||
isinstance(handler, logging.StreamHandler) | ||
for handler in logger.handlers | ||
) | ||
file_handler_exists = any( | ||
isinstance(handler, logging.FileHandler) | ||
for handler in logger.handlers | ||
) | ||
file_handler = logging.handlers.RotatingFileHandler( | ||
f"./Logs/{name}.log", | ||
maxBytes=2*1024*1024, | ||
backupCount=5,encoding='utf-8') | ||
file_handler.setLevel(logging.DEBUG) | ||
console_handler = logging.StreamHandler() | ||
console_handler.setLevel(logging.DEBUG) | ||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
file_handler.setFormatter(formatter) | ||
console_handler.setFormatter(formatter) | ||
if not file_handler_exists: | ||
logger.addHandler(file_handler) | ||
if not console_handler_exists: | ||
logger.addHandler(console_handler) | ||
logger.propagate = False | ||
return logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"self": {"build_script_path": "./build.ps1", "build_output_path": "./Output/JetBrainsMonoNerdFont-Regular.ttf", "version": "v1.1", "defalut_version": "v0.0"}, "JetBrainsMono": {"version": "v2.304", "user_name": "JetBrains", "repo_name": "JetBrainsMono", "defalut_version": "v0.0"}, "nerd-fonts": {"version": "v3.0.2", "user_name": "ryanoasis", "repo_name": "nerd-fonts", "defalut_version": "v0.0.0"}} | ||
{"self": {"build_script_path": "./build.ps1", "build_output_path": "./Output/JetBrainsMonoNerdFont-Regular.ttf", "version": "v1.2", "defalut_version": "v0.0"}, "JetBrainsMono": {"version": "v2.304", "user_name": "JetBrains", "repo_name": "JetBrainsMono", "defalut_version": "v0.0"}, "nerd-fonts": {"version": "v3.0.2", "user_name": "ryanoasis", "repo_name": "nerd-fonts", "defalut_version": "v0.0.0"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters