From f38ee211f884b113fda1f0d891035c12bba7fbcf Mon Sep 17 00:00:00 2001 From: Harish Karumuthil Date: Wed, 28 Oct 2020 15:47:06 +0530 Subject: [PATCH] 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+ Signed-off-by: Harish Karumuthil --- fluent/handler.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fluent/handler.py b/fluent/handler.py index 9297550..d68d479 100644 --- a/fluent/handler.py +++ b/fluent/handler.py @@ -79,6 +79,9 @@ def __init__(self, fmt=None, datefmt=None, style='%', fill_missing_fmt_key=False self._formatter = fmt self.usesTime = fmt.usesTime else: + if type(fmt) == str: + import ast + fmt = ast.literal_eval(fmt) self._fmt_dict = fmt self._formatter = self._format_by_dict self.usesTime = self._format_by_dict_uses_time