mirror of
https://github.com/imartinez/privateGPT.git
synced 2025-09-08 02:30:02 +00:00
feat: Drop loguru and use builtin logging
(#1133)
* Configure simple builtin logging Changed the 2 existing `print` in the `private_gpt` code base into actual python logging, stop using loguru (dependency will be dropped in a later commit). Try to use the `key=value` logging convention in logs (to indicate what dynamic values represents, and what is dynamic vs not). Using `%s` log style, so that the string formatting is pushed inside the logger, giving the ability to the logger to determine if the string need to be formatted or not (i.e. strings from debug logs might not be formatted if the log level is not debug) The (basic) builtin log configuration have been placed in `private_gpt/__init__.py` in order to initialize the logging system even before we start to launch any python code in `private_gpt` package (ensuring we get any initialization log formatted as we want to) Disabled `uvicorn` custom logging format, resulting in having uvicorn logs being outputted in our formatted. Some more concise format could be used if we want to, especially: ``` COMPACT_LOG_FORMAT = '%(asctime)s.%(msecs)03d [%(levelname)s] %(name)s - %(message)s' ``` Python documentation and cookbook on logging for reference: * https://docs.python.org/3/library/logging.html * https://docs.python.org/3/howto/logging.html * Removing loguru from the dependencies Result of `poetry remove loguru` * PR feedback: using `logger` variable name instead of `log` --------- Co-authored-by: Louis Melchior <louis@jaris.io>
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
"""FastAPI app creation, logger configuration and main API routes."""
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
import llama_index
|
||||
from fastapi import FastAPI
|
||||
from fastapi.openapi.utils import get_openapi
|
||||
from loguru import logger
|
||||
|
||||
from private_gpt.paths import docs_path
|
||||
from private_gpt.server.chat.chat_router import chat_router
|
||||
@@ -16,21 +14,6 @@ from private_gpt.server.health.health_router import health_router
|
||||
from private_gpt.server.ingest.ingest_router import ingest_router
|
||||
from private_gpt.settings.settings import settings
|
||||
|
||||
# Remove pre-configured logging handler
|
||||
logger.remove(0)
|
||||
# Create a new logging handler same as the pre-configured one but with the extra
|
||||
# attribute `request_id`
|
||||
logger.add(
|
||||
sys.stdout,
|
||||
level="INFO",
|
||||
format=(
|
||||
"<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | "
|
||||
"<level>{level: <8}</level> | "
|
||||
"<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> | "
|
||||
"ID: {extra[request_id]} - <level>{message}</level>"
|
||||
),
|
||||
)
|
||||
|
||||
# Add LlamaIndex simple observability
|
||||
llama_index.set_global_handler("simple")
|
||||
|
||||
|
Reference in New Issue
Block a user