[IMP] runbot: log user beside ip

This commit is contained in:
Xavier-Do 2023-07-03 13:38:36 +02:00 committed by Christophe Monniez
parent ab194610b0
commit d09b9961cd
4 changed files with 37 additions and 2 deletions

View File

@ -5,3 +5,23 @@ from . import models
from . import common
from . import container
from . import wizards
import logging
import threading
from odoo.http import request
class UserFilter(logging.Filter):
def filter(self, record): # noqa: A003
message_parts = record.msg.split(' ', 2)
if message_parts[1] == '-':
uid = getattr(threading.current_thread(), 'uid', None)
if uid is None:
return True
user_name = getattr(threading.current_thread(), 'user_name', 'user')
message_parts[1] = f'({user_name}:{uid})'
record.msg = ' '.join(message_parts)
return True
def runbot_post_load():
logging.getLogger('werkzeug').addFilter(UserFilter())

View File

@ -77,6 +77,6 @@
'/web/static/lib/bootstrap/js/dist/collapse.js',
'/runbot/static/src/js/runbot.js',
],
}
},
'post_load': 'runbot_post_load',
}

View File

@ -15,6 +15,7 @@ from . import dockerfile
from . import event
from . import host
from . import ir_cron
from . import ir_http
from . import ir_qweb
from . import project
from . import repo

14
runbot/models/ir_http.py Normal file
View File

@ -0,0 +1,14 @@
from odoo import models
from odoo.http import request
import threading
class IrHttp(models.AbstractModel):
_inherit = ["ir.http"]
@classmethod
def _dispatch(cls, endpoint):
result = super()._dispatch(endpoint)
if request:
threading.current_thread().user_name = request.env.user.name
return result