mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-23 18:04:34 +00:00
fix: dependencies and deprecated code (#390)
This commit is contained in:
co-authored by
GitHub
parent
14cab08024
commit
dddd130e79
+10
-11
@@ -6,7 +6,7 @@ import os
|
||||
import threading
|
||||
import uuid
|
||||
|
||||
from distutils.util import strtobool
|
||||
from .strtobool import strtobool
|
||||
|
||||
from odoo import http
|
||||
|
||||
@@ -20,30 +20,29 @@ except ImportError:
|
||||
|
||||
|
||||
def is_true(strval):
|
||||
return bool(strtobool(strval or '0'.lower()))
|
||||
return bool(strtobool(strval or "0".lower()))
|
||||
|
||||
|
||||
class OdooJsonFormatter(jsonlogger.JsonFormatter):
|
||||
|
||||
def add_fields(self, log_record, record, message_dict):
|
||||
record.pid = os.getpid()
|
||||
record.dbname = getattr(threading.currentThread(), 'dbname', '?')
|
||||
record.request_id = getattr(threading.current_thread(), 'request_uuid', None)
|
||||
record.uid = getattr(threading.current_thread(), 'uid', None)
|
||||
record.dbname = getattr(threading.currentThread(), "dbname", "?")
|
||||
record.request_id = getattr(threading.current_thread(), "request_uuid", None)
|
||||
record.uid = getattr(threading.current_thread(), "uid", None)
|
||||
_super = super(OdooJsonFormatter, self)
|
||||
return _super.add_fields(log_record, record, message_dict)
|
||||
|
||||
|
||||
if is_true(os.environ.get('ODOO_LOGGING_JSON')):
|
||||
if is_true(os.environ.get("ODOO_LOGGING_JSON")):
|
||||
formatted_message = (
|
||||
'%(asctime)s %(pid)s %(levelname)s %(dbname)s %(name)s: %(message)s'
|
||||
"%(asctime)s %(pid)s %(levelname)s %(dbname)s %(name)s: %(message)s"
|
||||
)
|
||||
formatter = OdooJsonFormatter(formatted_message)
|
||||
logging.getLogger().handlers[0].formatter = formatter
|
||||
|
||||
|
||||
# monkey patch WebRequest constructor to store request_uuid
|
||||
org_init = http.WebRequest.__init__
|
||||
# monkey patch Request constructor to store request_uuid
|
||||
org_init = http.Request.__init__
|
||||
|
||||
|
||||
def new_init(self, httprequest):
|
||||
@@ -51,4 +50,4 @@ def new_init(self, httprequest):
|
||||
threading.current_thread().request_uuid = uuid.uuid4()
|
||||
|
||||
|
||||
http.WebRequest.__init__ = new_init
|
||||
http.Request.__init__ = new_init
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
_MAP = {
|
||||
'y': True,
|
||||
'yes': True,
|
||||
't': True,
|
||||
'true': True,
|
||||
'on': True,
|
||||
'1': True,
|
||||
'n': False,
|
||||
'no': False,
|
||||
'f': False,
|
||||
'false': False,
|
||||
'off': False,
|
||||
'0': False
|
||||
}
|
||||
|
||||
|
||||
def strtobool(value):
|
||||
try:
|
||||
return _MAP[str(value).lower()]
|
||||
except KeyError:
|
||||
raise ValueError('"{}" is not a valid bool value'.format(value))
|
||||
Reference in New Issue
Block a user