Skip to content

Commit

Permalink
Make urls pop out from the sea of purple/cyan in the logs (#2894)
Browse files Browse the repository at this point in the history
* Make urls pop out from the sea of purple/cyan in the logs

* Readded deleted file
  • Loading branch information
AlexejPenner authored Aug 5, 2024
1 parent 5491024 commit 2bae282
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/zenml/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CustomFormatter(logging.Formatter):
cyan: str = "\x1b[1;36m"
bold_red: str = "\x1b[31;1m"
purple: str = "\x1b[1;35m"
blue: str = "\x1b[34m"
reset: str = "\x1b[0m"

format_template: str = (
Expand Down Expand Up @@ -94,6 +95,18 @@ def format(self, record: logging.LogRecord) -> str:
+ quoted
+ self.COLORS.get(LoggingLevels(record.levelno)),
)

# Format URLs
url_pattern = r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
urls = re.findall(url_pattern, formatted_message)
for url in urls:
formatted_message = formatted_message.replace(
url,
self.reset
+ self.blue
+ url
+ self.COLORS.get(LoggingLevels(record.levelno)),
)
return formatted_message


Expand Down

0 comments on commit 2bae282

Please sign in to comment.