Hi everyone! Has anyone implemented a customer log...
# questions
p
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?
d
Hi Paul, could you share your
logging.yml
and
handlers.py
files?
p
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)
Hi Dmitry, above is the content of logging.yml and handlers.py
d
I tried it, and it works well on my side after adding the
src
folder to
PYTHONPATH
to enable the import:
Copy code
export PYTHONPATH="${PYTHONPATH}:$(pwd)/src"
p
then I will try that, thanks so much
👍 1