mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 08:47:40 +00:00
Merge pull request #514 from camptocamp/17.0-fix-logging_json-attriute-error
[17.0][FIX] logging_json: no attribute 'JsonFormatter'
This commit is contained in:
@@ -6,8 +6,6 @@ import os
|
|||||||
import threading
|
import threading
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import pythonjsonlogger
|
|
||||||
|
|
||||||
from odoo import http
|
from odoo import http
|
||||||
|
|
||||||
from .strtobool import strtobool
|
from .strtobool import strtobool
|
||||||
@@ -16,20 +14,21 @@ _logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
# Module ``jsonlogger`` of package ``python-json-logger`` is deprecated since version
|
# Module ``jsonlogger`` of package ``python-json-logger`` is deprecated since version
|
||||||
# 3.1.0, keep it for backward compatibility
|
# 3.1.0, keep it for backward compatibility
|
||||||
if hasattr(pythonjsonlogger, "json"):
|
try:
|
||||||
jsonlogger = pythonjsonlogger.json
|
# python-json-logger>=3.1.0
|
||||||
elif hasattr(pythonjsonlogger, "jsonlogger"):
|
from pythonjsonlogger.json import JsonFormatter as _JsonFormatter
|
||||||
jsonlogger = pythonjsonlogger.jsonlogger
|
except ImportError:
|
||||||
else:
|
# python-json-logger<3.1.0
|
||||||
jsonlogger = None # noqa
|
from pythonjsonlogger.jsonlogger import (
|
||||||
_logger.debug("Cannot import 'json' or 'jsonlogger' from 'pythonjsonlogger'.")
|
JsonFormatter as _JsonFormatter,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def is_true(strval):
|
def is_true(strval):
|
||||||
return bool(strtobool(strval or "0".lower()))
|
return bool(strtobool(strval or "0".lower()))
|
||||||
|
|
||||||
|
|
||||||
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()
|
||||||
record.dbname = getattr(threading.current_thread(), "dbname", "?")
|
record.dbname = getattr(threading.current_thread(), "dbname", "?")
|
||||||
|
|||||||
Reference in New Issue
Block a user