-
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.
Merge pull request #35 from probabl-ai/feat/logger
Add the mandr logger to give the user full control over logging
- Loading branch information
Showing
3 changed files
with
34 additions
and
9 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,5 +1,33 @@ | ||
"""Povide the InfoMander class for managing information in a data science project.""" | ||
"""Provide the InfoMander class for managing information in a data science project.""" | ||
|
||
import logging | ||
|
||
import rich.logging | ||
|
||
from .infomander import InfoMander | ||
|
||
__all__ = ["InfoMander"] | ||
|
||
|
||
class Handler(rich.logging.RichHandler): | ||
"""A logging handler that renders output with Rich.""" | ||
|
||
def get_level_text(self, record: rich.logging.LogRecord) -> rich.logging.Text: | ||
"""Get the logger name and levelname from the record.""" | ||
levelname = record.levelname | ||
name = record.name | ||
txt = f"<Logger {name} ({levelname})>" | ||
|
||
return rich.logging.Text.styled( | ||
txt.ljust(8), | ||
f"logging.level.{levelname.lower()}", | ||
) | ||
|
||
|
||
formatter = logging.Formatter("%(message)s") | ||
handler = Handler(markup=True) | ||
handler.setFormatter(formatter) | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.addHandler(handler) | ||
logger.setLevel(logging.INFO) |
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