@@ -91,7 +91,9 @@ class Logger(logging.Logger): # lgtm [py/missing-call-to-init]
91
91
service : str, optional
92
92
service name to be appended in logs, by default "service_undefined"
93
93
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"
95
97
child: bool, optional
96
98
create a child Logger named <service>.<caller_file_name>, False by default
97
99
sample_rate: float, optional
@@ -327,7 +329,7 @@ def _configure_sampling(self):
327
329
try :
328
330
if self .sampling_rate and random .random () <= float (self .sampling_rate ):
329
331
logger .debug ("Setting log level to Debug due to sampling rate" )
330
- self .log_level = logging .DEBUG
332
+ self .setLevel ( logging .DEBUG )
331
333
except ValueError :
332
334
raise InvalidLoggerSamplingRateError (
333
335
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):
443
445
444
446
return decorate
445
447
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
+
446
461
def info (
447
462
self ,
448
463
msg : object ,
0 commit comments