Hi everyone! Has anyone implemented a customer log handler and successfully configured it in logging.yml? I'm getting a "No module named 'myproject.handlers'" error. I guess the logging is instantiated at a point where the project hasn't been loaded yet. Any idea how to get a custom logger running?
version: 1
disable_existing_loggers: False
formatters:
simple:
format: "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
handlers:
console:
class: logging.StreamHandler
level: INFO
formatter: simple
stream: ext://sys.stdout
custom_handler:
class: myproject.handlers.MyCustomHandler
level: INFO
rich:
class: kedro.logging.RichHandler
rich_tracebacks: True
level: INFO
loggers:
kedro:
level: INFO
myproject:
level: INFO
root:
handlers: [rich, custom_handler]
level: INFO
class MyCustomHandler(logging.Handler):
def __init__(self):
super().__init__()
def emit(self, record):
log_line = self.format(record)
print(log_line)
I tried it, and it works well on my side after adding the src
folder to PYTHONPATH
to enable the import:
export PYTHONPATH="${PYTHONPATH}:$(pwd)/src"