Browse Source

Merge pull request #1542 from sunflowerit/8.0-logging_json-dont-bork-on-missing-package

[FIX] logging_json ImportError
pull/1547/head
Pedro M. Baeza 6 years ago
committed by GitHub
parent
commit
4e22ed02f6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      logging_json/json_log.py

10
logging_json/json_log.py

@ -17,9 +17,9 @@ from openerp.netsvc import ColoredFormatter
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try: try:
from pythonjsonlogger import jsonlogger
from pythonjsonlogger.jsonlogger import JsonFormatter, RESERVED_ATTRS
except ImportError: except ImportError:
jsonlogger = None # noqa
JsonFormatter = object
_logger.debug("Cannot 'import pythonjsonlogger'.") _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): def add_fields(self, log_record, record, message_dict):
record.pid = os.getpid() record.pid = os.getpid()
@ -80,9 +80,9 @@ class OdooJsonDevFormatter(ColoredFormatter):
def format(self, record): def format(self, record):
response = super(OdooJsonDevFormatter, self).format(record) response = super(OdooJsonDevFormatter, self).format(record)
extra = {} extra = {}
RESERVED_ATTRS = list(jsonlogger.RESERVED_ATTRS) + ["dbname", "pid"]
reserved_attrs = list(RESERVED_ATTRS) + ["dbname", "pid"]
for key, value in record.__dict__.items(): 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('_'))): (hasattr(key, "startswith") and key.startswith('_'))):
extra[key] = value extra[key] = value
if extra: if extra:

Loading…
Cancel
Save