@@ -91,7 +91,9 @@ class Logger(logging.Logger): # lgtm [py/missing-call-to-init]
9191 service : str, optional
9292 service name to be appended in logs, by default "service_undefined"
9393 level : str, int optional
94- logging.level, by default "INFO"
94+ The level to set. Can be a string representing the level name: 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'
95+ or an integer representing the level value: 10 for 'DEBUG', 20 for 'INFO', 30 for 'WARNING', 40 for 'ERROR', 50 for 'CRITICAL'. # noqa: E501
96+ by default "INFO"
9597 child: bool, optional
9698 create a child Logger named <service>.<caller_file_name>, False by default
9799 sample_rate: float, optional
@@ -327,7 +329,7 @@ def _configure_sampling(self):
327329 try :
328330 if self .sampling_rate and random .random () <= float (self .sampling_rate ):
329331 logger .debug ("Setting log level to Debug due to sampling rate" )
330- self .log_level = logging .DEBUG
332+ self .setLevel ( logging .DEBUG )
331333 except ValueError :
332334 raise InvalidLoggerSamplingRateError (
333335 f"Expected a float value ranging 0 to 1, but received { self .sampling_rate } instead."
@@ -443,6 +445,19 @@ def decorate(event, context, *args, **kwargs):
443445
444446 return decorate
445447
448+ def setLevel (self , level : Union [str , int ]):
449+ """
450+ Set the logging level for the logger.
451+
452+ Parameters:
453+ -----------
454+ level str | int
455+ The level to set. Can be a string representing the level name: 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'
456+ or an integer representing the level value: 10 for 'DEBUG', 20 for 'INFO', 30 for 'WARNING', 40 for 'ERROR', 50 for 'CRITICAL'. # noqa: E501
457+ """
458+ self .log_level = level
459+ self ._logger .setLevel (level )
460+
446461 def info (
447462 self ,
448463 msg : object ,
0 commit comments