mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Suppress debug logs from uvicorn.error to avoid clutter from websockets
- If application is not in DEBUG_MODE
This commit is contained in:
parent
89b8ec3546
commit
1377a44a1a
1 changed files with 18 additions and 11 deletions
|
@ -2,14 +2,14 @@
|
|||
isort:skip_file
|
||||
"""
|
||||
|
||||
|
||||
from contextlib import redirect_stdout
|
||||
import logging
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
import locale
|
||||
|
||||
import logging
|
||||
from rich.logging import RichHandler
|
||||
import threading
|
||||
import warnings
|
||||
from importlib.metadata import version
|
||||
|
@ -26,7 +26,6 @@ import django
|
|||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from rich.logging import RichHandler
|
||||
import schedule
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
@ -36,6 +35,15 @@ from django.core.management import call_command
|
|||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "khoj.app.settings")
|
||||
django.setup()
|
||||
|
||||
# Setup Logger
|
||||
rich_handler = RichHandler(rich_tracebacks=True)
|
||||
rich_handler.setFormatter(fmt=logging.Formatter(fmt="%(name)s: %(message)s", datefmt="[%H:%M:%S.%f]"))
|
||||
logging.basicConfig(handlers=[rich_handler])
|
||||
|
||||
logging.getLogger("uvicorn.error").setLevel(logging.INFO)
|
||||
|
||||
logger = logging.getLogger("khoj")
|
||||
|
||||
# Initialize Django Database
|
||||
db_migrate_output = io.StringIO()
|
||||
with redirect_stdout(db_migrate_output):
|
||||
|
@ -82,13 +90,6 @@ from khoj.utils import state
|
|||
from khoj.utils.cli import cli
|
||||
from khoj.utils.initialization import initialization
|
||||
|
||||
# Setup Logger
|
||||
rich_handler = RichHandler(rich_tracebacks=True)
|
||||
rich_handler.setFormatter(fmt=logging.Formatter(fmt="%(message)s", datefmt="[%H:%M:%S.%f]"))
|
||||
logging.basicConfig(handlers=[rich_handler])
|
||||
|
||||
logger = logging.getLogger("khoj")
|
||||
|
||||
|
||||
def run(should_start_server=True):
|
||||
# Turn Tokenizers Parallelism Off. App does not support it.
|
||||
|
@ -161,7 +162,13 @@ def start_server(app, host=None, port=None, socket=None):
|
|||
uvicorn.run(app, proxy_headers=True, uds=socket, log_level="debug", use_colors=True, log_config=None)
|
||||
else:
|
||||
uvicorn.run(
|
||||
app, host=host, port=port, log_level="debug", use_colors=True, log_config=None, timeout_keep_alive=60
|
||||
app,
|
||||
host=host,
|
||||
port=port,
|
||||
log_level="debug" if in_debug_mode() else "info",
|
||||
use_colors=True,
|
||||
log_config=None,
|
||||
timeout_keep_alive=60,
|
||||
)
|
||||
logger.info("🌒 Stopping Khoj")
|
||||
|
||||
|
|
Loading…
Reference in a new issue