Skip to content

Commit

Permalink
docs for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
davedash committed Jul 13, 2011
1 parent 98980a4 commit 38131d7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Contents
operations
migrations
l10n
logging
docs
bestpractices

Expand Down
64 changes: 64 additions & 0 deletions logging.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.. _logging:

=======
Logging
=======

Logging is a great way to track what is going on with your app.

How to log
----------

Logging is provided via `commonware`_.

Within our webapps we typically use a small namespace prefix for logging::

i: input
z: zamboni

When we log in our app we can do the following::

import commonware.log

log = commonware.log.getLogger('i.myapp')


def my_view(request):
log.info('%s got here' % request.user)
pass

Anytime someone goes to `myapp.views.my_view` a log entry at level `INFO` will
be made.

In development this shows up as standard output.

.. _commonware: https://github.com/jsocol/commonware

Silence Logging
---------------

Sometimes logging can be noisy::

elasticsearch: DEBUG: Search disabled for <function add_to_index at 0x102e58848>.

Commonware as configured in playdoh, allows you to configure logging via
a ``dict`` in your `settings` (preferrably `settings_local.py`)::

error = dict(level=logging.ERROR)
info = dict(level=logging.INFO)

LOGGING = {
'loggers': {
'product_details': error,
'nose.plugins.manager': error,
'django.db.backends': error,
'elasticsearch': info,
},
}

This configuration says:

* Only tell me if there are errors with any logs in the `product_details`,
`nose.plugins.manager` and `django.db.backends` namespace
* Only tell me if there are `INFO`, `WARNING` or `ERROR` messages with
ElasticSearch.

0 comments on commit 38131d7

Please sign in to comment.