11"""Utility functions for basic-memory."""
2-
2+ import logging
33import os
44import re
55import sys
1010from unidecode import unidecode
1111
1212import basic_memory
13- from basic_memory .config import config
1413
1514import logfire
1615
@@ -65,8 +64,8 @@ def generate_permalink(file_path: Union[Path, str]) -> str:
6564
6665
6766def setup_logging (
68- home_dir : Path = config . home , log_file : Optional [str ] = None , console : bool = True
69- ) -> None : # pragma: no cover
67+ env : str , home_dir : Path , log_file : Optional [str ] = None , log_level : str = "INFO" , console : bool = True
68+ , ) -> None : # pragma: no cover
7069 """
7170 Configure logging for the application.
7271 :param home_dir: the root directory for the application
@@ -79,15 +78,14 @@ def setup_logging(
7978 logger .remove ()
8079
8180 # Add file handler if we are not running tests
82- if log_file and config . env != "test" :
81+ if log_file and env != "test" :
8382 # enable pydantic logfire
8483 logfire .configure (
8584 code_source = logfire .CodeSource (
8685 repository = "https://github.com/basicmachines-co/basic-memory" ,
8786 revision = basic_memory .__version__ ,
88- root_path = "/src/basic_memory" ,
8987 ),
90- environment = config . env ,
88+ environment = env ,
9189 console = False ,
9290 )
9391 logger .configure (handlers = [logfire .loguru_handler ()])
@@ -100,7 +98,7 @@ def setup_logging(
10098 log_path = home_dir / log_file
10199 logger .add (
102100 str (log_path ),
103- level = config . log_level ,
101+ level = log_level ,
104102 rotation = "100 MB" ,
105103 retention = "10 days" ,
106104 backtrace = True ,
@@ -109,7 +107,13 @@ def setup_logging(
109107 colorize = False ,
110108 )
111109
112- # Add stderr handler
113- logger .add (sys .stderr , level = config .log_level , backtrace = True , diagnose = True , colorize = True )
110+ if env == "test" or console :
111+ # Add stderr handler
112+ logger .add (sys .stderr , level = log_level , backtrace = True , diagnose = True , colorize = True )
113+
114+ logger .info (f"ENV: '{ env } ' Log level: '{ log_level } ' Logging to { log_file } " )
114115
115- logger .info (f"ENV: '{ config .env } ' Log level: '{ config .log_level } ' Logging to { log_file } " )
116+ # Get the logger for 'httpx'
117+ httpx_logger = logging .getLogger ("httpx" )
118+ # Set the logging level to WARNING to ignore INFO and DEBUG logs
119+ httpx_logger .setLevel (logging .WARNING )
0 commit comments