##// END OF EJS Templates
request-wrapper: expose usernames for better auditing capabilities.
marcink -
r4347:6b62737b default
parent child Browse files
Show More
@@ -1541,8 +1541,7 b' class AuthUser(object):'
1541 return notice_messages, notice_level
1541 return notice_messages, notice_level
1542
1542
1543 def __repr__(self):
1543 def __repr__(self):
1544 return "<AuthUser('id:%s[%s] ip:%s auth:%s')>"\
1544 return self.repr_user(self.user_id, self.username, self.ip_addr, self.is_authenticated)
1545 % (self.user_id, self.username, self.ip_addr, self.is_authenticated)
1546
1545
1547 def set_authenticated(self, authenticated=True):
1546 def set_authenticated(self, authenticated=True):
1548 if self.user_id != self.anonymous_user.user_id:
1547 if self.user_id != self.anonymous_user.user_id:
@@ -1557,6 +1556,11 b' class AuthUser(object):'
1557 }
1556 }
1558
1557
1559 @classmethod
1558 @classmethod
1559 def repr_user(cls, user_id=0, username='ANONYMOUS', ip='0.0.0.0', is_authenticated=False):
1560 tmpl = "<AuthUser('id:{}[{}] ip:{} auth:{}')>"
1561 return tmpl.format(user_id, username, ip, is_authenticated)
1562
1563 @classmethod
1560 def from_cookie_store(cls, cookie_store):
1564 def from_cookie_store(cls, cookie_store):
1561 """
1565 """
1562 Creates AuthUser from a cookie store
1566 Creates AuthUser from a cookie store
@@ -22,8 +22,9 b' import time'
22 import logging
22 import logging
23
23
24 import rhodecode
24 import rhodecode
25 from rhodecode.lib.auth import AuthUser
25 from rhodecode.lib.base import get_ip_addr, get_access_path, get_user_agent
26 from rhodecode.lib.base import get_ip_addr, get_access_path, get_user_agent
26 from rhodecode.lib.utils2 import safe_str
27 from rhodecode.lib.utils2 import safe_str, get_current_rhodecode_user
27
28
28
29
29 log = logging.getLogger(__name__)
30 log = logging.getLogger(__name__)
@@ -46,9 +47,11 b' class RequestWrapperTween(object):'
46 total = end - start
47 total = end - start
47 count = request.request_count()
48 count = request.request_count()
48 _ver_ = rhodecode.__version__
49 _ver_ = rhodecode.__version__
50 default_user_info = AuthUser.repr_user(ip=get_ip_addr(request.environ))
51 user_info = get_current_rhodecode_user(request) or default_user_info
49 log.info(
52 log.info(
50 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s], RhodeCode %s',
53 'Req[%4s] %s %s Request to %s time: %.4fs [%s], RhodeCode %s',
51 count, get_ip_addr(request.environ), request.environ.get('REQUEST_METHOD'),
54 count, user_info, request.environ.get('REQUEST_METHOD'),
52 safe_str(get_access_path(request.environ)), total,
55 safe_str(get_access_path(request.environ)), total,
53 get_user_agent(request. environ), _ver_
56 get_user_agent(request. environ), _ver_
54 )
57 )
General Comments 0
You need to be logged in to leave comments. Login now