Skip to content

Commit ce36dff

Browse files
authored
convert argument fmt into dict if argument is a string
FluentRecordFormatter is expecting fmt to be either a callable or a dict. But there is no strict type checking is done to check whether the variable is dict or not. There are many situations in which `fmt` can have a string value. For eg: if logger is loading configuration from a config file using [ConfigParser](https://docs.python.org/2/library/configparser.html) , then there is no way to specify a dict inside the config file. This change is backward compatible from Python2.7 to Python3.8 since `ast.literal_eval` will work in same way since python 2.6+
1 parent d1b81ba commit ce36dff

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Diff for: fluent/handler.py

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def __init__(self, fmt=None, datefmt=None, style='%', fill_missing_fmt_key=False
7979
self._formatter = fmt
8080
self.usesTime = fmt.usesTime
8181
else:
82+
if type(fmt) == str:
83+
import ast
84+
fmt = ast.literal_eval(fmt)
8285
self._fmt_dict = fmt
8386
self._formatter = self._format_by_dict
8487
self.usesTime = self._format_by_dict_uses_time

0 commit comments

Comments
 (0)