浏览代码

Fixed #19395 -- Added a simple example logging config.

Thanks ken.nelson at maclaren.com.
Tim Graham 11 年之前
父节点
当前提交
69f0249d7b
共有 1 个文件被更改,包括 33 次插入4 次删除
  1. 33 4
      docs/topics/logging.txt

+ 33 - 4
docs/topics/logging.txt

@@ -230,13 +230,40 @@ use in your project code.
 
 .. _dictConfig format: http://docs.python.org/library/logging.config.html#configuration-dictionary-schema
 
-An example
-----------
+Examples
+--------
 
 The full documentation for `dictConfig format`_ is the best source of
 information about logging configuration dictionaries. However, to give
-you a taste of what is possible, here is an example of a fairly
-complex logging setup, configured using :func:`logging.config.dictConfig`::
+you a taste of what is possible, here are a couple examples.
+
+First, here's a simple configuration which writes all request logging from the
+:ref:`django-request-logger` logger to a local file::
+
+    LOGGING = {
+        'version': 1,
+        'disable_existing_loggers': False,
+        'handlers': {
+            'file': {
+                'level': 'DEBUG',
+                'class': 'logging.FileHandler',
+                'filename': '/path/to/django/debug.log',
+            },
+        },
+        'loggers': {
+            'django.request': {
+                'handlers': ['file'],
+                'level': 'DEBUG',
+                'propagate': True,
+            },
+        },
+    }
+
+If you use this example, be sure to change the ``'filename'`` path to a
+location that's writable by the user that's running the Django application.
+
+Second, here's an example of a fairly complex logging setup, configured using
+:func:`logging.config.dictConfig`::
 
     LOGGING = {
         'version': 1,
@@ -396,6 +423,8 @@ Django provides four built-in loggers.
 ``django`` is the catch-all logger. No messages are posted directly to
 this logger.
 
+.. _django-request-logger:
+
 ``django.request``
 ~~~~~~~~~~~~~~~~~~