Fix level enum checking 01/601/1
authorRoni Riska <roni.riska@nokia.com>
Wed, 31 Jul 2019 11:10:16 +0000 (14:10 +0300)
committerRoni Riska <roni.riska@nokia.com>
Wed, 31 Jul 2019 11:17:54 +0000 (14:17 +0300)
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 <roni.riska@nokia.com>
mdclogpy/Logger.py

index 93e4cf2..57ab7b7 100644 (file)
@@ -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."""