diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-11-23 14:27:54 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-11-23 14:27:54 (GMT) |
commit | 631a7e23c5afec8a53a92296d08b0865322540ca (patch) | |
tree | bc16cdab08e3ce8e22bf96af377a4e63f19a053e /Doc/howto | |
parent | 287f24691dd8bda7f8acfebdda3201c738d67533 (diff) | |
download | cpython-631a7e23c5afec8a53a92296d08b0865322540ca.zip cpython-631a7e23c5afec8a53a92296d08b0865322540ca.tar.gz cpython-631a7e23c5afec8a53a92296d08b0865322540ca.tar.bz2 |
Added a configuration dictionary example to the logging cookbook.
Diffstat (limited to 'Doc/howto')
-rw-r--r-- | Doc/howto/logging-cookbook.rst | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/Doc/howto/logging-cookbook.rst b/Doc/howto/logging-cookbook.rst index 7038ca4..7dc8021 100644 --- a/Doc/howto/logging-cookbook.rst +++ b/Doc/howto/logging-cookbook.rst @@ -1038,3 +1038,67 @@ of queues, for example a ZeroMQ 'subscribe' socket. Here's an example:: :ref:`A basic logging tutorial <logging-basic-tutorial>` :ref:`A more advanced logging tutorial <logging-advanced-tutorial>` + + +An example dictionary-based configuration +----------------------------------------- + +Below is an example of a logging configuration dictionary - it's taken from +the `documentation on the Django project <https://docs.djangoproject.com/en/1.3/topics/logging/#configuring-logging>`_. +This dictionary is passed to :func:`~logging.config.dictConfig` to put the configuration into effect:: + + LOGGING = { + 'version': 1, + 'disable_existing_loggers': True, + 'formatters': { + 'verbose': { + 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s' + }, + 'simple': { + 'format': '%(levelname)s %(message)s' + }, + }, + 'filters': { + 'special': { + '()': 'project.logging.SpecialFilter', + 'foo': 'bar', + } + }, + 'handlers': { + 'null': { + 'level':'DEBUG', + 'class':'django.utils.log.NullHandler', + }, + 'console':{ + 'level':'DEBUG', + 'class':'logging.StreamHandler', + 'formatter': 'simple' + }, + 'mail_admins': { + 'level': 'ERROR', + 'class': 'django.utils.log.AdminEmailHandler', + 'filters': ['special'] + } + }, + 'loggers': { + 'django': { + 'handlers':['null'], + 'propagate': True, + 'level':'INFO', + }, + 'django.request': { + 'handlers': ['mail_admins'], + 'level': 'ERROR', + 'propagate': False, + }, + 'myproject.custom': { + 'handlers': ['console', 'mail_admins'], + 'level': 'INFO', + 'filters': ['special'] + } + } + } + +For more information about this configuration, you can see the `relevant +section <https://docs.djangoproject.com/en/1.3/topics/logging/#configuring-logging>`_ +of the Django documentation. |