From 2835e1100187038dcde18855dcaef0826c8aa0df Mon Sep 17 00:00:00 2001 From: Tom Blauwendraat Date: Wed, 3 Apr 2019 09:35:49 +0200 Subject: [PATCH] [FIX] logging_json ImportError --- logging_json/json_log.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/logging_json/json_log.py b/logging_json/json_log.py index fbac7f8f5..3eddf4e21 100644 --- a/logging_json/json_log.py +++ b/logging_json/json_log.py @@ -17,9 +17,9 @@ from openerp.netsvc import ColoredFormatter _logger = logging.getLogger(__name__) try: - from pythonjsonlogger import jsonlogger + from pythonjsonlogger.jsonlogger import JsonFormatter, RESERVED_ATTRS except ImportError: - jsonlogger = None # noqa + JsonFormatter = object _logger.debug("Cannot 'import pythonjsonlogger'.") @@ -55,7 +55,7 @@ REGEX = { } -class OdooJsonFormatter(jsonlogger.JsonFormatter): +class OdooJsonFormatter(JsonFormatter): def add_fields(self, log_record, record, message_dict): record.pid = os.getpid() @@ -80,9 +80,9 @@ class OdooJsonDevFormatter(ColoredFormatter): def format(self, record): response = super(OdooJsonDevFormatter, self).format(record) extra = {} - RESERVED_ATTRS = list(jsonlogger.RESERVED_ATTRS) + ["dbname", "pid"] + reserved_attrs = list(RESERVED_ATTRS) + ["dbname", "pid"] for key, value in record.__dict__.items(): - if (key not in RESERVED_ATTRS and not + if (key not in reserved_attrs and not (hasattr(key, "startswith") and key.startswith('_'))): extra[key] = value if extra: