Guest (Inger)
02/01/2024, 1:08 PMNok Lam Chan
02/01/2024, 1:10 PMKEDRO_LOGIGNG_CONFIG
.
This migration guide would help you for the upgrade: https://github.com/kedro-org/kedro/blob/main/RELEASE.md#migration-guide-from-kedro-018-to-019Nok Lam Chan
02/01/2024, 1:11 PMNok Lam Chan
02/01/2024, 1:15 PMGuest (Inger)
02/01/2024, 1:15 PMimport logging
from copy import deepcopy
from pathlib import Path
from typing import Any, Optional, Union
from kedro.framework.project import LOGGING, configure_project
from kedro.framework.session import KedroSession
logger = logging.getLogger(__name__)
KedroOutput = dict[str, Any]
class PipelineRunner:
"""Create and run Kedro pipelines."""
def __init__(
self,
env: Union[EnvType, Path],
pipeline_type: str,
conf_source: Path = settings.CONF_SOURCE,
runtime_params: Optional[dict] = None,
):
"""Class to start the kedro pipeline.
Parameters
----------
env: Union[str, Path]
Specify the environment to run the pipeline in.
conf_source: Path
Specify the path to the configuration file
pipeline_type: str
Name of the pipeline type. This is the pipeline name minus auto
or manual naming.
runtime_params: Optional[dict]
Pass extra parameters to the kedro pipeline
"""
self.env = env if isinstance(env, str) else env.as_posix()
self.conf_source = conf_source.as_posix()
self.pipeline_base_name = pipeline_type
self.runtime_params = deepcopy(runtime_params) or {}
self._has_run = False
self.kedro_output: Optional[KedroOutput] = None
def run_pipeline(self, pipeline_name: str) -> None:
"""Run the kedro pipeline.
The run_pipeline function is a wrapper around Kedro's `run` method.
It allows you to run the pipeline from within Python, e.g.:
Parameters
----------
pipeline_name: str
The name of the pipeline to be run.
Raises
------
RuntimeError
Raises a runtime error if any errors were logged during the
pipeline. This allows the data to still be sent, but for us to
be aware that an error occurred.
Returns
-------
None
"""
if self._has_run:
raise RuntimeError("Create a new pipeline for each run.")
self._has_run = True
package_name = Path(__file__).parent.name
configure_project(package_name)
with KedroSession.create(
env=self.env,
conf_source=self.conf_source,
extra_params=self.runtime_params,
) as session:
self.kedro_output = session.run(pipeline_name=pipeline_name)
error_logs = get_root_error_logs(LOGGING_ERROR_LIST_HANDLER)
if error_logs is not None:
raise RuntimeError(
f"Pipeline encountered errors during the run: {error_logs}"
)
return None
Sajid Alam
02/01/2024, 1:20 PMlogging.yml
file in the conf/base
.Sajid Alam
02/01/2024, 1:27 PMNok Lam Chan
02/01/2024, 1:29 PMimport os
and os.environ["KEDRO_LOGGING_CONFIG"]
= <your_path> instead? before you start loading any Kedro thingsSajid Alam
02/01/2024, 1:39 PMrich
with console
in the logging.yml
load the yml file in your code and use logging.config.dictConfig
https://docs.python.org/3/library/logging.config.html#logging.config.dictConfigGuest (Inger)
02/01/2024, 1:41 PMGuest (Inger)
02/01/2024, 1:42 PMNok Lam Chan
02/01/2024, 1:42 PMlogging.config.dictConfig
, instead you can call LOGGING.configure(<dictionary_of_config>)Nok Lam Chan
02/01/2024, 1:43 PMGuest (Inger)
02/01/2024, 1:44 PMdef set_up_runtime_logger() -> None:
"""Set up the runtime logger.
Need to remove Kedro's rich logging as DB is not happy with it.
"""
root_logger = logging.getLogger()
for handler in root_logger.handlers.copy():
if isinstance(handler, RichHandler):
root_logger.removeHandler(handler)
basicConfig(level=INFO, handlers=[HANDLER])
Nok Lam Chan
02/01/2024, 1:47 PMrich
, it should be fine.Juan Luis
02/02/2024, 9:20 AMBut seems a bit finicky. Because you are dependent on the order of which things are run. Because if the init file of the project is run before the os environment is set it does not work.ugh, that's painful. help me understand, is this because of how stdlib
logging
works? that it somehow cannot be changed after Kedro has configured it?
would be happy to continue this conversation on a GitHub issue.Guest (Inger)
02/06/2024, 9:51 AMNok Lam Chan
02/06/2024, 11:49 AMugh, that's painful. help me understand, is this because of how stdlibworks? that it somehow cannot be changed after Kedro has configured it?logging
would be happy to continue this conversation on a GitHub issue.@Juan Luis that's not the issue here I believe,
KEDRO_LOGGING_CONFIG
is set before anything run, and it get configured at soon as kedro.framework.project
get imported.
I don't find using LOGGING.configure
to reconfigure logging settings wrong. Having LOGGING.configure
before Kedro run should be sufficient. @Guest (Inger), could you share where did you place it and why it need to be placed serval times?Guest (Inger)
02/12/2024, 8:47 AM