Commit 7cdc60e4 authored by Chris Lamb's avatar Chris Lamb
Browse files

Don't require that log formatting "knows" about the HTTPRequest and alter API...

Don't require that log formatting "knows" about the HTTPRequest and alter API to make this more obvious. (Closes: #40)
parent 229cd09e
......@@ -35,7 +35,7 @@ class LoginView(TwoFactorLoginView):
def done(self, *args, **kwargs):
response = super().done(*args, **kwargs)
log.info(self.request, "Login successful")
log.info("Login successful", request=self.request)
if self.request.user.is_staff and \
self.redirect_field_name not in self.request.GET:
......
......@@ -18,9 +18,10 @@ def info(*args, **kwargs):
_log(logging.INFO, *args, **kwargs)
def _log(level, request, *args, **kwargs):
def _log(level, *args, **kwargs):
logger = logging.getLogger('freenodejobs')
request = kwargs.pop('request', None)
changed_data = []
try:
......@@ -59,10 +60,15 @@ class FreenodejobsFormatter(logging.Formatter):
xs.append('{}: {!r} -> {!r}'.format(name, prev, current))
record.msg = '{} ({})'.format(record.msg, ', '.join(xs))
record.path_info = request.path
record.remote_addr = request.META['REMOTE_ADDR']
record.email = request.user.email \
if request.user.is_authenticated else '-'
record.email = '-'
record.geoip = 'unknown'
record.remote_addr = 'unknown'
if request is not None:
record.path_info = request.path
record.remote_addr = request.META['REMOTE_ADDR']
record.email = request.user.email \
if request.user.is_authenticated else '(anonymous)'
try:
data = GEOIP.city(request.META['REMOTE_ADDR'])
......@@ -70,6 +76,6 @@ class FreenodejobsFormatter(logging.Formatter):
data[x] for x in ('city', 'country_name') if data[x]
)
except Exception:
record.geoip = "unknown"
pass
return super().format(record)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment