From: Roni Riska Date: Wed, 31 Jul 2019 11:10:16 +0000 (+0300) Subject: Fix level enum checking X-Git-Tag: 1.1.1~3 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=644e53733c9f9c79a9da381f2248c60642db8be1;p=com%2Fpylog.git Fix level enum checking In Python 3.8 checks with non-Enum causes TypeError exception. https://docs.python.org/3/whatsnew/3.7.html#enum So, if the library user would call mdclog.set_level(123) it would crash the process with Python 3.8. With 3.7 it would just cause an error print and with older nothing would happen. Now we try to convert the set_level argument to a Level object and if it does not succeed then ignore the setting, like it has worked with older Python versions. Change-Id: Ib99d5feb8eea919ffc9cd12405aac6da892f6d14 Signed-off-by: Roni Riska --- diff --git a/mdclogpy/Logger.py b/mdclogpy/Logger.py index 93e4cf2..57ab7b7 100644 --- a/mdclogpy/Logger.py +++ b/mdclogpy/Logger.py @@ -111,8 +111,10 @@ class Logger(): level -- logging level. Log messages with lower severity will be filtered. """ - if level in Level: - self.current_level = level + try: + self.current_level = Level(level) + except ValueError: + pass def get_level(self) -> Level: """Return the current logging level."""