Using LoggingConfig with custom loggers? #3482
-
Thank you for this wonderful project! Really like it. 👍 I have some difficulties with logging, in particular the I've read the Logging section in the documentation. Apart from a little warning with the Maybe it's a misunderstanding on my side, but I try to configure additional loggers and would like to define them with logging_config = LoggingConfig(
# configure_root_logger=False,
# disable_existing_loggers=True,
handlers={
'foo': {
'class': 'logging.StreamHandler', # 'litestar.logging.standard.QueueListenerHandler',
'level': 'DEBUG',
'formatter': 'foo'
},
formatters={
'foo':
{'format': '[%(levelname)s] - %(asctime)s - %(name)s - %(module)s - %(message)s'},
# Disabling the "standard" formatter crashes with an exception (see below):
'standard':
{'format': '%(levelname)s - %(asctime)s - %(name)s - %(module)s - %(message)s'},
},
loggers={
'foo': {'level': 'DEBUG',
'handlers': ['foo'],
'propagate': False}
},
) What's a bit strange is that I have to provide a "standard" formatter otherwise I get a KeyError: KeyError when omitting the "standard" formatter
But that's a minor issue. When I trigger the
My questions to this:
Hope that makes sense. Thanks for your ideas and suggestions. Much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Sorry for not directly answering your questions just yet, but this may be of interest to you: #2858 |
Beta Was this translation helpful? Give feedback.
-
My advice would be to stick with the current config, just re-use or override what you need. In your case you could just redefine the I haven't tested it, but I guess something like that would work:
This is passed to logging.config.dictConfig().
I guess the prefered way is to use |
Beta Was this translation helpful? Give feedback.
-
I've defined a simple logging configuration class so that Litestar will use a preconfigured Python logger. First use
|
Beta Was this translation helpful? Give feedback.
-
In fact, and in order to log exceptions, I needed:
|
Beta Was this translation helpful? Give feedback.
Sorry for not directly answering your questions just yet, but this may be of interest to you: #2858