From be3d28d981ecf51d8fef96a256d9c0ef74d5d8c4 Mon Sep 17 00:00:00 2001 From: Nok Date: Tue, 27 Feb 2024 09:39:56 +0000 Subject: [PATCH 1/3] Read logging.yml automatically Signed-off-by: Nok --- kedro/framework/project/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/kedro/framework/project/__init__.py b/kedro/framework/project/__init__.py index ea56f5d668..4a7af8f86e 100644 --- a/kedro/framework/project/__init__.py +++ b/kedro/framework/project/__init__.py @@ -217,9 +217,14 @@ class _ProjectLogging(UserDict): def __init__(self) -> None: """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" - ) + user_logging_path = os.environ.get("KEDRO_LOGGING_CONFIG") + if not user_logging_path and Path("conf/logging.yml").exists(): + user_logging_path = Path("conf/logging.yml") + + default_logging_path = Path(__file__).parent / "default_logging.yml" + path = user_logging_path if user_logging_path else default_logging_path + print(f"DEBUG: {path=}") + logging_config = Path(path).read_text(encoding="utf-8") self.configure(yaml.safe_load(logging_config)) From 65cf2a0b82afdf18a4f9e1f56af061b6a80f25ee Mon Sep 17 00:00:00 2001 From: Nok Date: Tue, 27 Feb 2024 10:07:18 +0000 Subject: [PATCH 2/3] change logging.yml default Signed-off-by: Nok --- kedro/framework/project/__init__.py | 4 ++-- .../{{ cookiecutter.repo_name }}/conf/logging.yml | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/kedro/framework/project/__init__.py b/kedro/framework/project/__init__.py index 4a7af8f86e..8650ef40a6 100644 --- a/kedro/framework/project/__init__.py +++ b/kedro/framework/project/__init__.py @@ -270,8 +270,8 @@ def configure_project(package_name: str) -> None: global PACKAGE_NAME # noqa: PLW0603 PACKAGE_NAME = package_name - if PACKAGE_NAME: - LOGGING.set_project_logging(PACKAGE_NAME) + # if PACKAGE_NAME: + # LOGGING.set_project_logging(PACKAGE_NAME) def configure_logging(logging_config: dict[str, Any]) -> None: diff --git a/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml b/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml index 1cf75396ab..30cda11750 100644 --- a/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml +++ b/kedro/templates/project/{{ cookiecutter.repo_name }}/conf/logging.yml @@ -11,7 +11,6 @@ formatters: handlers: console: class: logging.StreamHandler - level: INFO formatter: simple stream: ext://sys.stdout @@ -32,12 +31,13 @@ handlers: # See https://docs.kedro.org/en/stable/logging/logging.html#project-side-logging-configuration # tracebacks_show_locals: False -loggers: - kedro: - level: INFO +# loggers: +# kedro: +# level: INFO - {{ cookiecutter.python_package }}: - level: INFO +# {{ cookiecutter.python_package }}: +# level: INFO root: handlers: [rich, info_file_handler] + level: INFO From 2ec8bc1b218b608f094f1c81d2b1a37c44cceda8 Mon Sep 17 00:00:00 2001 From: Nok Date: Tue, 27 Feb 2024 10:25:20 +0000 Subject: [PATCH 3/3] Quick hack for `kedro run -v` Signed-off-by: Nok --- kedro/framework/cli/project.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kedro/framework/cli/project.py b/kedro/framework/cli/project.py index cd9a072184..c7a61bea74 100644 --- a/kedro/framework/cli/project.py +++ b/kedro/framework/cli/project.py @@ -196,6 +196,13 @@ def package(metadata: ProjectMetadata) -> None: help=PARAMS_ARG_HELP, callback=_split_params, ) +@click.option( + "-v", + "verbose", + type=click.UNPROCESSED, + is_flag=True, + default="", +) def run( # noqa: PLR0913 tags: str, env: str, @@ -212,8 +219,13 @@ def run( # noqa: PLR0913 conf_source: str, params: dict[str, Any], namespace: str, + verbose: bool, ) -> None: """Run the pipeline.""" + if verbose: + from kedro.framework.project import LOGGING + LOGGING.data["root"]["level"] = "DEBUG" + LOGGING.configure(LOGGING.data) runner_obj = load_obj(runner or "SequentialRunner", "kedro.runner") tuple_tags = tuple(tags)