Spaces:
Running
Running
Reorganize loggers and move them to the global config module
Browse files- global_config.py +27 -0
- helpers/llm_helper.py +2 -36
global_config.py
CHANGED
|
@@ -198,12 +198,39 @@ class GlobalConfig:
|
|
| 198 |
)
|
| 199 |
|
| 200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
logging.basicConfig(
|
| 202 |
level=GlobalConfig.LOG_LEVEL,
|
| 203 |
format='%(asctime)s - %(levelname)s - %(name)s - %(message)s',
|
| 204 |
datefmt='%Y-%m-%d %H:%M:%S'
|
| 205 |
)
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
def get_max_output_tokens(llm_name: str) -> int:
|
| 209 |
"""
|
|
|
|
| 198 |
)
|
| 199 |
|
| 200 |
|
| 201 |
+
# Centralized logging configuration (early):
|
| 202 |
+
# - Ensure noisy third-party loggers (httpx, httpcore, urllib3, LiteLLM, etc.) are set to WARNING
|
| 203 |
+
# - Disable propagation so they don't bubble up to the root logger
|
| 204 |
+
# - Capture warnings from the warnings module into logging
|
| 205 |
+
# The log suppression must run before the noisy library is imported/initialised!
|
| 206 |
+
LOGGERS_TO_SUPPRESS = [
|
| 207 |
+
'asyncio',
|
| 208 |
+
'httpx',
|
| 209 |
+
'httpcore',
|
| 210 |
+
'langfuse',
|
| 211 |
+
'LiteLLM',
|
| 212 |
+
'litellm',
|
| 213 |
+
'openai',
|
| 214 |
+
'urllib3',
|
| 215 |
+
'urllib3.connectionpool',
|
| 216 |
+
]
|
| 217 |
+
|
| 218 |
logging.basicConfig(
|
| 219 |
level=GlobalConfig.LOG_LEVEL,
|
| 220 |
format='%(asctime)s - %(levelname)s - %(name)s - %(message)s',
|
| 221 |
datefmt='%Y-%m-%d %H:%M:%S'
|
| 222 |
)
|
| 223 |
|
| 224 |
+
for _lg in LOGGERS_TO_SUPPRESS:
|
| 225 |
+
logger_obj = logging.getLogger(_lg)
|
| 226 |
+
logger_obj.setLevel(logging.WARNING)
|
| 227 |
+
# Prevent these logs from propagating to the root logger
|
| 228 |
+
logger_obj.propagate = False
|
| 229 |
+
|
| 230 |
+
# Capture warnings from the warnings module (optional, helps centralize output)
|
| 231 |
+
if hasattr(logging, 'captureWarnings'):
|
| 232 |
+
logging.captureWarnings(True)
|
| 233 |
+
|
| 234 |
|
| 235 |
def get_max_output_tokens(llm_name: str) -> int:
|
| 236 |
"""
|
helpers/llm_helper.py
CHANGED
|
@@ -7,37 +7,6 @@ import sys
|
|
| 7 |
import urllib3
|
| 8 |
from typing import Tuple, Union, Iterator, Optional
|
| 9 |
|
| 10 |
-
# Centralized logging configuration (early):
|
| 11 |
-
# - Ensure noisy third-party loggers (httpx, httpcore, urllib3, LiteLLM, etc.) are set to WARNING
|
| 12 |
-
# - Disable propagation so they don't bubble up to the root logger
|
| 13 |
-
# - Capture warnings from the warnings module into logging
|
| 14 |
-
# The suppression must run before the noisy library is imported/initialised!
|
| 15 |
-
LOGGERS_TO_SUPPRESS = [
|
| 16 |
-
'asyncio',
|
| 17 |
-
'httpx',
|
| 18 |
-
'httpcore',
|
| 19 |
-
'langfuse',
|
| 20 |
-
'LiteLLM',
|
| 21 |
-
'litellm',
|
| 22 |
-
'openai',
|
| 23 |
-
'urllib3',
|
| 24 |
-
'urllib3.connectionpool',
|
| 25 |
-
]
|
| 26 |
-
|
| 27 |
-
# Basic config at module import time; use WARNING to avoid DEBUG noise
|
| 28 |
-
logging.basicConfig(
|
| 29 |
-
level=logging.WARNING,
|
| 30 |
-
format='%(asctime)s - %(levelname)s - %(name)s - %(message)s'
|
| 31 |
-
)
|
| 32 |
-
for _lg in LOGGERS_TO_SUPPRESS:
|
| 33 |
-
logger_obj = logging.getLogger(_lg)
|
| 34 |
-
logger_obj.setLevel(logging.WARNING)
|
| 35 |
-
# Prevent these logs from propagating to the root logger
|
| 36 |
-
logger_obj.propagate = False
|
| 37 |
-
|
| 38 |
-
# Capture warnings from the warnings module (optional, helps centralize output)
|
| 39 |
-
if hasattr(logging, 'captureWarnings'):
|
| 40 |
-
logging.captureWarnings(True)
|
| 41 |
|
| 42 |
sys.path.append('..')
|
| 43 |
|
|
@@ -50,8 +19,8 @@ try:
|
|
| 50 |
# Ask LiteLLM to suppress debug information if possible
|
| 51 |
try:
|
| 52 |
litellm.suppress_debug_info = True
|
| 53 |
-
except
|
| 54 |
-
#
|
| 55 |
pass
|
| 56 |
|
| 57 |
except ImportError:
|
|
@@ -66,9 +35,6 @@ API_KEY_REGEX = re.compile(r'^[a-zA-Z0-9_-]{6,94}$')
|
|
| 66 |
|
| 67 |
|
| 68 |
logger = logging.getLogger(__name__)
|
| 69 |
-
logging.getLogger('httpx').setLevel(logging.WARNING)
|
| 70 |
-
logging.getLogger('httpcore').setLevel(logging.WARNING)
|
| 71 |
-
logging.getLogger('openai').setLevel(logging.ERROR)
|
| 72 |
|
| 73 |
|
| 74 |
def get_provider_model(provider_model: str, use_ollama: bool) -> Tuple[str, str]:
|
|
|
|
| 7 |
import urllib3
|
| 8 |
from typing import Tuple, Union, Iterator, Optional
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
sys.path.append('..')
|
| 12 |
|
|
|
|
| 19 |
# Ask LiteLLM to suppress debug information if possible
|
| 20 |
try:
|
| 21 |
litellm.suppress_debug_info = True
|
| 22 |
+
except AttributeError:
|
| 23 |
+
# Attribute not available in this version of LiteLLM
|
| 24 |
pass
|
| 25 |
|
| 26 |
except ImportError:
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
def get_provider_model(provider_model: str, use_ollama: bool) -> Tuple[str, str]:
|