You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note. Non-breaking, goes in 0.18.x. Easiest to complete after #2206.
We want people to be able to e.g. turn rich tracebacks on/off from logging.yml. However, we don't want to start adding our own custom keys to logging.yml (the format is specified already by Python).
The way to do this is to write our own rich console logging handler. It will be very simple, just a thin wrapper for rich.logging.RichHandler. We need to move all the custom behaviour out of _ProjectLogging and into the init method of the new logging handler. Let's call it kedro.logging.RichHandler (tbc exactly where it should live - we don't have extras/logging in develop so don't just put it there).
Since we're piggybacking off RichHandler's rich_tracebacks argument, which defaults to False, we'll need to change the logging config everywhere (default_logging.yml + all starters) to set this to True:
Add docs to describe how you can set rich_tracebacks: False if you'd like to disable them.
The new handler should look something like this:
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
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
logging.captureWarnings(True)
rich.pretty.install()
if self.rich_tracebacks:
# 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.
# 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
if "DATABRICKS_RUNTIME_VERSION" not in os.environ:
rich.traceback.install(
suppress=[click, str(Path(sys.executable).parent)])
### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
### NOTE YOU MAY WELL NEED TO CHANGE THIS PATH DEPENDING ON WHERE
### THIS FILE ENDS UP SO THAT IT POINTS TO THE RIGHT PLACE
Following #2206, _ProjectLogging would be left looking something like this:
class _ProjectLogging(UserDict):
# pylint: disable=super-init-not-called
def __init__(self):
"""Initialise project logging. The path to logging configuration is given in
environment variable KEDRO_LOGGING_CONFIG (defaults to default_logging.yml)."""
path = os.environ.get("KEDRO_LOGGING_CONFIG", Path(__file__).parent / "default_logging.yml")
logging_config = Path(path).read_text(encoding="utf-8")
self.configure(yaml.safe_load(logging_config))
The text was updated successfully, but these errors were encountered:
We want people to be able to e.g. turn rich tracebacks on/off from logging.yml. However, we don't want to start adding our own custom keys to logging.yml (the format is specified already by Python).
The way to do this is to write our own rich console logging handler. It will be very simple, just a thin wrapper for
rich.logging.RichHandler
. We need to move all the custom behaviour out of_ProjectLogging
and into the init method of the new logging handler. Let's call itkedro.logging.RichHandler
(tbc exactly where it should live - we don't haveextras/logging
indevelop
so don't just put it there).Since we're piggybacking off
RichHandler
'srich_tracebacks
argument, which defaults toFalse
, we'll need to change the logging config everywhere (default_logging.yml + all starters) to set this toTrue
:Add docs to describe how you can set
rich_tracebacks: False
if you'd like to disable them.The new handler should look something like this:
Following #2206,
_ProjectLogging
would be left looking something like this:The text was updated successfully, but these errors were encountered: