mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[IMP] runbot: log user beside ip
This commit is contained in:
parent
ab194610b0
commit
d09b9961cd
@ -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())
|
||||
|
@ -77,6 +77,6 @@
|
||||
'/web/static/lib/bootstrap/js/dist/collapse.js',
|
||||
'/runbot/static/src/js/runbot.js',
|
||||
],
|
||||
}
|
||||
|
||||
},
|
||||
'post_load': 'runbot_post_load',
|
||||
}
|
||||
|
@ -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
14
runbot/models/ir_http.py
Normal 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
|
Loading…
Reference in New Issue
Block a user