Showing posts with label logging. Show all posts
Showing posts with label logging. Show all posts

Jan 7, 2013

Generate safe bug reports

…
from django.views.decorators.debug import sensitive_post_parameters

@sensitive_post_parameters("password")
def login_view(request):
    …
POST:<QueryDict: {u'csrfmiddlewaretoken': [u'F3d71EHWECfavaeK4H7nUTzLwgY07AHT'],
                  u'password': [u'********************'],
                  u'email': [u'aruseni.magiku@gmail.com']}>
…
from django.views.decorators.debug import sensitive_variables

@sensitive_variables("payment_card_id")
def process_payment(request):
    …
http://habrahabr.ru/post/164935/

Aug 6, 2012

How to log an exception instance

http://blog.tplus1.com/index.php/2012/08/05/python-log-uncaught-exceptions-with-sys-excepthook/

If you do any of these, you probably won’t like what you get:
logging.error(ex)
logging.error(str(ex))
In both cases, you are just turning the exception to a string. You won’t see the traceback and you won’t see the exception type.
Instead of those, make sure you do one of these:
logging.exception(ex) # this is exactly what logging.exception does inside
logging.error(ex, exc_info=1) # sets a higher log level than error 
logging.critical(ex, exc_info=1)
For the last two, without that exc_info=1 parameter, you won’t see the traceback in your logs. You’ll just see the message from the exception.

Mar 19, 2012

Statistics, Logging, Monitoring

Monitoring

django-statsd - Django Statsd library to track the page load times with Graphite
django-kitsune - monitoring using Nagios plugins

scales - Tracks server state and statistics, allowing you to see what your server is doing. It can also send metrics to Graphite for graphing or to a file for crash forensics.
django-peavy -  is a tool for improving your Django application logging.
  • Middleware to tag each request with a unique ID.
  • Logging filters to capture request metadata like user, remote IP, and headers.
  • Logging handlers for:
  • Capturing exception information, including a copy of the Django server error page, in a database.
  • Sending error notifications to admins without revealing sensitive information like the contents of request.POST.
  • A database router for sending log records to a separate database.
  • A simple user interface for browsing log records in the database.
django-app-metrics - Simple framework for capturing in application metrics and emailing aggregation results

Jan 30, 2012

Logging

import logging
import logging.handlers

# Sets up a basic textfile log, with formatting
logging.basicConfig(level=logging.DEBUG,
   format='%(asctime)s %(levelname)-8s %(message)s',
   datefmt='%m/%d/%y %H:%M:%S',
   filename=r'C:\temp\mylog.log',
   filemode='a')

# Log a few different events
logging.info('Just testing the water.')
logging.warning('Hmm, something is not right here')
logging.error("Oh no, now you're in for it")
The resulting text log:
02/14/08 22:19:03 INFO     Just testing the water.
02/14/08 22:19:03 WARNING  Hmm, something is not right here
02/14/08 22:19:03 ERROR    Oh no, now you're in for it
Add a few more lines and it sends you an email for any logs that are level "ERROR" or above:
email = logging.handlers.SMTPHandler('smtp.foo.com',
   'script@foo.com',('techart@bar.com'),'Error Report')
email.setLevel(logging.ERROR)

logging.getLogger('').addHandler(email)