3636logger = logging .getLogger (__name__ )
3737
3838
39+ def _disable_http_logs (path : str ):
40+ logging .getLogger ("uvicorn.access" ).addFilter (
41+ # Add a space to the path to make sure that we
42+ # only filter out this entrypoints HTTP logs.
43+ lambda record : f"{ path } "
44+ not in record .getMessage ()
45+ )
46+
47+
3948class _Service :
4049 def __init__ (self ):
4150 self .app = FastAPI (
@@ -180,12 +189,7 @@ async def wrapper(_request: Request, *args, **kwargs):
180189 )
181190
182191 if disable_http_logs :
183- logging .getLogger ("uvicorn.access" ).addFilter (
184- # Add a space to the path to make sure that we
185- # only filter out this entrypoints HTTP logs.
186- lambda record : f"{ path } "
187- not in record .getMessage ()
188- )
192+ _disable_http_logs (path )
189193
190194 # Wrap the original func in a pydantic validation wrapper and return that
191195 return validate_arguments (deco_func )
@@ -319,6 +323,7 @@ def add_parameter(
319323 value : Any ,
320324 expose : bool = True ,
321325 monitor : bool = False ,
326+ disable_http_logs : bool = False ,
322327 ):
323328 """Adds a parameter to the parameter endpoints.
324329
@@ -329,8 +334,12 @@ def add_parameter(
329334 Defaults to True.
330335 monitor (bool): Stores updates to this parameter in the monitoring
331336 database if True. Will try to coerce non-numeric types to
332- string Defaults to False.
337+ string. Defaults to False.
338+ disable_http_logs (bool): Disable logs when getting and
339+ setting paramter with API. Defaults to False
333340 """
341+ path = f"/~parameters/{ parameter } "
342+
334343 if isinstance (value , Number ):
335344 value = float (value )
336345
@@ -342,6 +351,9 @@ def update_parameter(value: value.__class__) -> Any:
342351 self .store (** {parameter : value })
343352 return value
344353
354+ if disable_http_logs :
355+ _disable_http_logs (path )
356+
345357 # Set initial value
346358 self .parameters [parameter ] = {
347359 "value" : None ,
@@ -353,7 +365,6 @@ def update_parameter(value: value.__class__) -> Any:
353365 def get_parameter ():
354366 return self .parameters [parameter ]["value" ]
355367
356- path = f"/~parameters/{ parameter } "
357368 self .app .get (path , tags = ["Parameters" ])(get_parameter )
358369
359370 # Register POST endpoint for the new parameter
0 commit comments