mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-23 18:04:34 +00:00
Log request uuid
This commit is contained in:
committed by
Guewen Baconnier
co-authored by
Guewen Baconnier
parent
11c90c5a17
commit
9cf4bf2171
@@ -4,9 +4,12 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
|
import uuid
|
||||||
|
|
||||||
from distutils.util import strtobool
|
from distutils.util import strtobool
|
||||||
|
|
||||||
|
from odoo import http
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -25,6 +28,7 @@ class OdooJsonFormatter(jsonlogger.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.currentThread(), 'dbname', '?')
|
record.dbname = getattr(threading.currentThread(), 'dbname', '?')
|
||||||
|
record.request_id = getattr(threading.current_thread(), 'request_uuid', None)
|
||||||
_super = super(OdooJsonFormatter, self)
|
_super = super(OdooJsonFormatter, self)
|
||||||
return _super.add_fields(log_record, record, message_dict)
|
return _super.add_fields(log_record, record, message_dict)
|
||||||
|
|
||||||
@@ -34,3 +38,15 @@ if is_true(os.environ.get('ODOO_LOGGING_JSON')):
|
|||||||
'%(dbname)s %(name)s: %(message)s')
|
'%(dbname)s %(name)s: %(message)s')
|
||||||
formatter = OdooJsonFormatter(format)
|
formatter = OdooJsonFormatter(format)
|
||||||
logging.getLogger().handlers[0].formatter = formatter
|
logging.getLogger().handlers[0].formatter = formatter
|
||||||
|
|
||||||
|
|
||||||
|
# monkey patch WebRequest constructor to store request_uuid
|
||||||
|
org_init = http.WebRequest.__init__
|
||||||
|
|
||||||
|
|
||||||
|
def new_init(self, httprequest):
|
||||||
|
org_init(self, httprequest)
|
||||||
|
threading.current_thread().request_uuid = uuid.uuid4()
|
||||||
|
|
||||||
|
|
||||||
|
http.WebRequest.__init__ = new_init
|
||||||
|
|||||||
Reference in New Issue
Block a user