-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add the Kedro RichHandler Signed-off-by: Nok Chan <[email protected]> * Clean up imports and comments Signed-off-by: Nok Chan <[email protected]> * Map arguments to add flexibility to customize arguments available in RichHandler Signed-off-by: Nok Chan <[email protected]> * Clean up rich_logger.py and unused imports Signed-off-by: Nok Chan <[email protected]> * Add docs - first iteration Signed-off-by: Nok Chan <[email protected]> * Fix imports and small refactoring Signed-off-by: Nok Chan <[email protected]> * Improve the doc Signed-off-by: Nok Chan <[email protected]> * Update the project's template Signed-off-by: Nok Chan <[email protected]> * format docstring Signed-off-by: Nok Chan <[email protected]> * Apply Jo's comment on the doc Signed-off-by: Nok Chan <[email protected]> * Fix the link with RichHandler Signed-off-by: Nok Chan <[email protected]> * Apply suggestions from code review Co-authored-by: Antony Milne <[email protected]> * Fix broken doc Signed-off-by: Nok Chan <[email protected]> * update template defaults Signed-off-by: Nok Chan <[email protected]> * refactoring RichHandler and improve doc Signed-off-by: Nok Chan <[email protected]> * Fix broken test due to new default RichHandler Signed-off-by: Nok Chan <[email protected]> * Fix doc Signed-off-by: Nok Chan <[email protected]> * Move kedro.extras.logging.RichHandler -> kedro.logging.RichHandler Signed-off-by: Nok Chan <[email protected]> * add kedro/logging.py and remove the unnecessary import that cause namespace collision Signed-off-by: Nok Chan <[email protected]> * Refactor test Signed-off-by: Nok Chan <[email protected]> * Add more tests Signed-off-by: Nok Chan <[email protected]> * Fix lots of import, docstring Signed-off-by: Nok Chan <[email protected]> * Reorder docstring Signed-off-by: Nok Chan <[email protected]> * Fix tests Signed-off-by: Nok Chan <[email protected]> * Link options to doc Signed-off-by: Nok Chan <[email protected]> * Clean up doc and unused logger Signed-off-by: Nok Chan <[email protected]> * Fix spelling `customise` Signed-off-by: Nok Chan <[email protected]> * Refactor test with fixture Signed-off-by: Nok Chan <[email protected]> * Remove unnecessary copy() because it is now a fixture Signed-off-by: Nok Chan <[email protected]> * Split up test_rich_traceback_configuration() to smaller tests Signed-off-by: Nok Chan <[email protected]> * Add RELEASE.md Signed-off-by: Nok Chan <[email protected]> * Update doc Signed-off-by: Nok Chan <[email protected]> * Fix template logging
- Loading branch information
Showing
12 changed files
with
225 additions
and
54 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,6 @@ | ||
kedro.logging.RichHandler | ||
========================= | ||
|
||
.. currentmodule:: kedro.logging | ||
|
||
.. autoclass:: RichHandler |
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,20 @@ | ||
kedro.logging | ||
============= | ||
|
||
.. rubric:: Description | ||
|
||
.. automodule:: kedro.logging | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
.. rubric:: Classes | ||
|
||
.. autosummary:: | ||
:toctree: | ||
:template: autosummary/class.rst | ||
|
||
RichHandler |
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 |
---|---|---|
|
@@ -4,8 +4,3 @@ | |
""" | ||
|
||
__version__ = "0.18.8" | ||
|
||
|
||
import logging | ||
|
||
logging.getLogger(__name__).addHandler(logging.NullHandler()) |
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,58 @@ | ||
""" | ||
This module contains a logging handler class which produces coloured logs and tracebacks. | ||
""" | ||
|
||
import logging | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
import click | ||
import rich.logging | ||
import rich.pretty | ||
import rich.traceback | ||
|
||
|
||
class RichHandler(rich.logging.RichHandler): | ||
"""Identical to rich's logging handler but with a few extra behaviours: | ||
* warnings issued by the `warnings` module are redirected to logging | ||
* pretty printing is enabled on the Python REPL (including IPython and Jupyter) | ||
* all tracebacks are handled by rich when rich_tracebacks=True | ||
* constructor's arguments are mapped and passed to `rich.traceback.install` | ||
The list of available options of ``RichHandler`` can be found here: | ||
https://rich.readthedocs.io/en/stable/reference/logging.html#rich.logging.RichHandler | ||
The list of available options of `rich.traceback.install` can be found here: | ||
https://rich.readthedocs.io/en/stable/reference/traceback.html#rich.traceback.install | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
logging.captureWarnings(True) | ||
rich.pretty.install() | ||
|
||
# We suppress click here to hide tracebacks related to it conversely, | ||
# kedro is not suppressed to show its tracebacks for easier debugging. | ||
# sys.executable is used to get the kedro executable path to hide the | ||
# top level traceback. | ||
|
||
traceback_install_kwargs = { | ||
"suppress": [click, str(Path(sys.executable).parent)] | ||
} | ||
|
||
# Mapping arguments from RichHandler's Constructor to rich.traceback.install | ||
prefix = "tracebacks_" | ||
for key, value in kwargs.items(): | ||
if key.startswith(prefix): | ||
key_prefix_removed = key[len(prefix) :] | ||
if key_prefix_removed == "suppress": | ||
traceback_install_kwargs[key_prefix_removed].extend(value) | ||
else: | ||
traceback_install_kwargs[key_prefix_removed] = value | ||
|
||
if self.rich_tracebacks and "DATABRICKS_RUNTIME_VERSION" not in os.environ: | ||
# Rich traceback handling does not work on databricks. Hopefully this will be | ||
# fixed on their side at some point, but until then we disable it. | ||
# See https://github.com/Textualize/rich/issues/2455 | ||
rich.traceback.install(**traceback_install_kwargs) |
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
Oops, something went wrong.