Log Forwarded for address in accesslog instead of client address for gevent
This commit is contained in:
+23
-1
@@ -16,7 +16,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
from gevent.pywsgi import WSGIHandler
|
from gevent.pywsgi import WSGIHandler
|
||||||
|
|
||||||
|
|
||||||
@@ -27,4 +27,26 @@ class MyWSGIHandler(WSGIHandler):
|
|||||||
env['RAW_URI'] = path
|
env['RAW_URI'] = path
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
def format_request(self):
|
||||||
|
now = datetime.now().replace(microsecond=0)
|
||||||
|
length = self.response_length or '-'
|
||||||
|
if self.time_finish:
|
||||||
|
delta = '%.6f' % (self.time_finish - self.time_start)
|
||||||
|
else:
|
||||||
|
delta = '-'
|
||||||
|
forwarded = self.environ.get('HTTP_X_FORWARDED_FOR', None)
|
||||||
|
if forwarded:
|
||||||
|
client_address = forwarded
|
||||||
|
else:
|
||||||
|
client_address = self.client_address[0] if isinstance(self.client_address, tuple) else self.client_address
|
||||||
|
return '%s - - [%s] "%s" %s %s %s' % (
|
||||||
|
client_address or '-',
|
||||||
|
now,
|
||||||
|
self.requestline or '',
|
||||||
|
# Use the native string version of the status, saved so we don't have to
|
||||||
|
# decode. But fallback to the encoded 'status' in case of subclasses
|
||||||
|
# (Is that really necessary? At least there's no overhead.)
|
||||||
|
(self._orig_status or self.status or '000').split()[0],
|
||||||
|
length,
|
||||||
|
delta)
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import os
|
|||||||
import errno
|
import errno
|
||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
import asyncio
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from gevent.pywsgi import WSGIServer
|
from gevent.pywsgi import WSGIServer
|
||||||
|
|||||||
Reference in New Issue
Block a user