Merge pull request #26 from fbertsch/add_logging
Bug 1299840 - Log requests against aggregator service
This commit is contained in:
Коммит
4e8aaabbb5
|
@ -1,5 +1,6 @@
|
|||
import ujson as json
|
||||
import config
|
||||
import logging
|
||||
|
||||
from flask import Flask, Response, request, abort
|
||||
from flask.ext.cors import CORS
|
||||
|
@ -13,6 +14,8 @@ from psycogreen.gevent import patch_psycopg
|
|||
from psycopg2.pool import SimpleConnectionPool
|
||||
from aggregator import simple_measures_labels, count_histogram_labels
|
||||
from db import get_db_connection_string, histogram_revision_map
|
||||
from logging.handlers import SysLogHandler
|
||||
|
||||
|
||||
pool = None
|
||||
app = Flask(__name__)
|
||||
|
@ -26,6 +29,16 @@ patch_all()
|
|||
patch_psycopg()
|
||||
cache.clear()
|
||||
|
||||
### Papertrail Logging Config ###
|
||||
logger = logging.getLogger('RequestLogger')
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
syslog = SysLogHandler(address=('logs5.papertrailapp.com', 47698))
|
||||
formatter = logging.Formatter('%(asctime)s -- %(message)s')
|
||||
|
||||
syslog.setFormatter(formatter)
|
||||
logger.addHandler(syslog)
|
||||
|
||||
|
||||
def cache_request(f):
|
||||
@wraps(f)
|
||||
|
@ -61,6 +74,20 @@ def execute_query(query, params=tuple()):
|
|||
pool.putconn(db)
|
||||
|
||||
|
||||
@app.before_request
|
||||
def log_request():
|
||||
"""Log format: Referrer URL, Referrer, IP Address, URL
|
||||
"""
|
||||
ip_addr = request.access_route[0] or request.remote_addr
|
||||
data = (request.values.get('url', ''),
|
||||
request.values.get('Referer', ''),
|
||||
ip_addr,
|
||||
request.url)
|
||||
|
||||
if ip_addr != '127.0.0.1':
|
||||
logger.info(','.join([d.replace(',', '\,') for d in data]))
|
||||
|
||||
|
||||
@app.route('/status')
|
||||
def status():
|
||||
return "OK"
|
||||
|
|
2
setup.py
2
setup.py
|
@ -8,7 +8,7 @@
|
|||
from setuptools import setup
|
||||
|
||||
setup(name='python_mozaggregator',
|
||||
version='0.2.5.13',
|
||||
version='0.2.5.14',
|
||||
author='Roberto Agostino Vitillo',
|
||||
author_email='rvitillo@mozilla.com',
|
||||
description='Telemetry aggregation job',
|
||||
|
|
Загрузка…
Ссылка в новой задаче