Example #1
0
# http://www.gnu.org/licenses/agpl-3.0.html.

from datetime import datetime
import inspect
import json
import logging
import traceback

from utils.dataprintout import DataPrinter

EXTRA_FIELDS = [
    'path', 'status_code', 'method', 'view', 'query', 'post_data', 'metrics',
    'user'
]

data_printer = DataPrinter(max_size=500, max_item_size=100, max_repr_size=50)


def record_data(record):
    data = {
        '@version': '1',
        '@timestamp': format_timestamp(record.created),
        'message': record.getMessage(),
        'level': record.levelname,
        'name': record.name,
    }
    if record.exc_info:
        data['exception'] = str(record.exc_info[0])
        data['traceback'] = format_traceback(record.exc_info[2])
    for name in EXTRA_FIELDS:
        if hasattr(record, name):
Example #2
0
from django.utils.cache import patch_vary_headers
from django.utils.http import cookie_date

from utils.dataprintout import DataPrinter

access_logger = logging.getLogger('access')
error_logger = logging.getLogger('unhandled_error')

SECTIONS = {
    'widget': 'widget',
    'api': 'api-v1',
    'api2': 'api-v2',
    'teams': 'teams',
}

data_printer = DataPrinter(max_size=1024, max_item_size=100, max_repr_size=50)


class P3PHeaderMiddleware(object):
    def process_response(self, request, response):
        response['P3P'] = settings.P3P_COMPACT
        return response


# Got this from CsrfViewMiddleware
# Use the system (hardware-based) random number generator if it exists.
if hasattr(random, 'SystemRandom'):
    randrange = random.SystemRandom().randrange
else:
    randrange = random.randrange