chainlit
chainlit copied to clipboard
Chainlit sets logging format before application code
trafficstars
Describe the bug chainlit sets up the logging for the application it is in. A library should not do this.
To Reproduce If you import chainlit first:
>>> import chainlit
>>> import logging
>>>
>>> logging_args = {
... "format": "%(asctime)s %(levelname)s %(name)s %(filename)s %(funcName)s %(lineno)d %(message)s",
... "level": logging.INFO,
... "datefmt": "%Y-%m-%d %H:%M:%S",
... "encoding": "utf-8",
... }
>>> logging.basicConfig(**logging_args)
>>> logger = logging.getLogger(__name__)
>>>
>>> logger.info("sadasd")
2025-01-10 15:14:09 - sadasd
>>> def x():
... logger.info("asasd")
...
>>> x()
2025-01-10 15:14:48 - asasd
Expected behavior The logging format should be what the application sets.
f you import and setup logging first then import chainlit:
>>> import logging
>>>
>>> logging_args = {
... "format": "%(asctime)s %(levelname)s %(name)s %(filename)s %(funcName)s %(lineno)d %(message)s",
... "level": logging.INFO,
... "datefmt": "%Y-%m-%d %H:%M:%S",
... "encoding": "utf-8",
... }
>>> logging.basicConfig(**logging_args)
>>> logger = logging.getLogger(__name__)
>>>
>>> logger.info("foo!")
2025-01-10 15:12:32 INFO __main__ <stdin> <module> 1 foo!
>>> def x():
... logger.info("bar!")
...
>>> x()
2025-01-10 15:12:54 INFO __main__ <stdin> x 2 bar!
>>> import chainlit as cl
>>> x()
2025-01-10 15:13:13 INFO __main__ <stdin> x 2 bar!
>>> import openai
>>> x()
2025-01-10 15:13:22 INFO __main__ <stdin> x 2 bar!
Additional context When running chainlit as a module, there is currently nothing you can do to stop chainlit from setting the logging format before the application code is called.