File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -405,6 +405,15 @@ class LogLevel(Enum):
405405 INFO = "INFO"
406406 DEBUG = "DEBUG"
407407
408+ @classmethod
409+ def _missing_ (cls , value : object ) -> "LogLevel" :
410+ if not isinstance (value , str ):
411+ raise ValueError (f"{ value } is not a valid log level" )
412+ for member in cls :
413+ if member .value == value .upper ():
414+ return member
415+ raise ValueError (f"{ value } is not a valid log level" )
416+
408417
409418class LogFileHandlerConfig (ConfigModel ):
410419 """
Original file line number Diff line number Diff line change 77from cognite .extractorutils .unstable .configuration .loaders import ConfigFormat , load_io
88from cognite .extractorutils .unstable .configuration .models import (
99 ConnectionConfig ,
10+ LogLevel ,
1011 TimeIntervalConfig ,
1112 _ClientCredentialsConfig ,
1213)
@@ -212,3 +213,14 @@ def test_from_env() -> None:
212213
213214 # Check that the produces cogniteclient object is valid
214215 assert len (client .assets .list (limit = 1 )) == 1
216+
217+
218+ def test_setting_log_level_from_any_case () -> None :
219+ log_level = LogLevel ("DEBUG" )
220+ assert log_level == LogLevel .DEBUG
221+
222+ log_level = LogLevel ("debug" )
223+ assert log_level == LogLevel .DEBUG
224+
225+ with pytest .raises (ValueError ):
226+ LogLevel ("not-a-log-level" )
You can’t perform that action at this time.
0 commit comments