-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fe-art
committed
Sep 11, 2024
1 parent
1f23d9e
commit e0d3efe
Showing
4 changed files
with
82 additions
and
33 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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os | ||
import sys | ||
|
||
from loguru import logger | ||
import yaml | ||
|
||
from clashroyalebuildabot.constants import DEBUG_DIR | ||
from clashroyalebuildabot.constants import SRC_DIR | ||
|
||
COLORS = dict(context_info="#118aa2", time="#459028") | ||
|
||
|
||
def setup_logger(main_window): | ||
config_path = os.path.join(SRC_DIR, "config.yaml") | ||
with open(config_path, encoding="utf-8") as file: | ||
config = yaml.safe_load(file) | ||
log_level = config.get("bot", {}).get("log_level", "INFO").upper() | ||
logger.remove() | ||
logger.add(sys.stdout, level=log_level) | ||
logger.add( | ||
os.path.join(DEBUG_DIR, "bot.log"), | ||
rotation="500 MB", | ||
level=log_level, | ||
) | ||
logger.add( | ||
main_window.log_handler_function, | ||
format="{time} {level} {module}:{function}:{line} - {message}", | ||
level=log_level, | ||
) | ||
|
||
|
||
def colorize_log(message): | ||
log_record = message.record | ||
level = log_record["level"].name | ||
time = log_record["time"].strftime("%Y-%m-%d %H:%M:%S") | ||
module = log_record["module"] | ||
function = log_record["function"] | ||
line = log_record["line"] | ||
log_message = log_record["message"] | ||
|
||
if level == "DEBUG": | ||
color = "#147eb8" | ||
elif level == "INFO": | ||
color = "white" | ||
level = "INFO " | ||
elif level == "WARNING": | ||
color = "orange" | ||
elif level == "ERROR": | ||
color = "red" | ||
else: | ||
color = "black" | ||
|
||
return f"""<span style="color:{COLORS['time']}">[{time}]</span> <span style="color:{color}">{level}</span> | <span style="color:{COLORS['context_info']}">{module}:{function}:{line}</span> - <span style="color:{color}">{log_message}</span></span>""" |
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