Hey guys! I have a project where I have a require...
# questions
e
Hey guys! I have a project where I have a requirement to link to Azure App Insights, so I'm trying to set up a hook to modify the default behavior of logs in kedro. Does anyone have experience with this?
Copy code
class LoggingHooks:
    @hook_impl
    def on_pipeline_start(self, pipeline, catalog, run_params, **kwargs):

        logger = logging.getLogger("kedro")

        credentials = CONFIG_LOADER_CLASS.get('credentials', {})
        if not (app_insights := credentials.get('app_insights')):
            logger.warning('Could not configure App Insights!')
            return

        azure_handler = AzureLogHandler(
            connection_string=app_insights.get('conn_string')
        )
        logger.addHandler(azure_handler)

        console_handler = logging.StreamHandler()
        console_handler.setFormatter(
            logging.Formatter("%(asctime)s [%(levelname)s] - %(name)s: %(message)s")
        )
        logger.addHandler(console_handler)

        logger.propagate = False
h
Someone will reply to you shortly. In the meantime, this might help:
d
This isn't the way to configure logging in Kedro https://docs.kedro.org/en/stable/logging/index.html
👍 1
You should be able to do the configuration through this YAML interface to
logging.DictConfig
I'm not 100% sure how to pass the credentials in, I think you may need to use some sort of omegaconf resolver
I hook may be able to work too, was it not for you?