~ubuntu-branches/ubuntu/precise/python3.2/precise-proposed

« back to all changes in this revision

Viewing changes to Doc/howto/logging-cookbook.rst

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2012-03-09 18:40:39 UTC
  • mfrom: (30.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120309184039-j3yk2emxr1plyo21
Tags: 3.2.3~rc1-1
* Python 3.2.3 release candidate 1.
* Update to 20120309 from the 3.2 branch.
* Fix libpython.a symlink. Closes: #660146.
* Build-depend on xauth.
* Run the gdb tests for the debug build only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
674
674
to have all the processes log to a :class:`SocketHandler`, and have a separate
675
675
process which implements a socket server which reads from the socket and logs
676
676
to file. (If you prefer, you can dedicate one thread in one of the existing
677
 
processes to perform this function.) The following section documents this
678
 
approach in more detail and includes a working socket receiver which can be
679
 
used as a starting point for you to adapt in your own applications.
 
677
processes to perform this function.) :ref:`This section <network-logging>`
 
678
documents this approach in more detail and includes a working socket receiver
 
679
which can be used as a starting point for you to adapt in your own
 
680
applications.
680
681
 
681
682
If you are using a recent version of Python which includes the
682
683
:mod:`multiprocessing` module, you could write your own handler which uses the
960
961
``.1``. Each of the existing backup files is renamed to increment the suffix
961
962
(``.1`` becomes ``.2``, etc.)  and the ``.6`` file is erased.
962
963
 
963
 
Obviously this example sets the log length much much too small as an extreme
 
964
Obviously this example sets the log length much too small as an extreme
964
965
example.  You would want to set *maxBytes* to an appropriate value.
965
966
 
966
967
.. _zeromq-handlers:
1037
1038
   :ref:`A basic logging tutorial <logging-basic-tutorial>`
1038
1039
 
1039
1040
   :ref:`A more advanced logging tutorial <logging-advanced-tutorial>`
 
1041
 
 
1042
 
 
1043
An example dictionary-based configuration
 
1044
-----------------------------------------
 
1045
 
 
1046
Below is an example of a logging configuration dictionary - it's taken from
 
1047
the `documentation on the Django project <https://docs.djangoproject.com/en/1.3/topics/logging/#configuring-logging>`_.
 
1048
This dictionary is passed to :func:`~logging.config.dictConfig` to put the configuration into effect::
 
1049
 
 
1050
    LOGGING = {
 
1051
        'version': 1,
 
1052
        'disable_existing_loggers': True,
 
1053
        'formatters': {
 
1054
            'verbose': {
 
1055
                'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
 
1056
            },
 
1057
            'simple': {
 
1058
                'format': '%(levelname)s %(message)s'
 
1059
            },
 
1060
        },
 
1061
        'filters': {
 
1062
            'special': {
 
1063
                '()': 'project.logging.SpecialFilter',
 
1064
                'foo': 'bar',
 
1065
            }
 
1066
        },
 
1067
        'handlers': {
 
1068
            'null': {
 
1069
                'level':'DEBUG',
 
1070
                'class':'django.utils.log.NullHandler',
 
1071
            },
 
1072
            'console':{
 
1073
                'level':'DEBUG',
 
1074
                'class':'logging.StreamHandler',
 
1075
                'formatter': 'simple'
 
1076
            },
 
1077
            'mail_admins': {
 
1078
                'level': 'ERROR',
 
1079
                'class': 'django.utils.log.AdminEmailHandler',
 
1080
                'filters': ['special']
 
1081
            }
 
1082
        },
 
1083
        'loggers': {
 
1084
            'django': {
 
1085
                'handlers':['null'],
 
1086
                'propagate': True,
 
1087
                'level':'INFO',
 
1088
            },
 
1089
            'django.request': {
 
1090
                'handlers': ['mail_admins'],
 
1091
                'level': 'ERROR',
 
1092
                'propagate': False,
 
1093
            },
 
1094
            'myproject.custom': {
 
1095
                'handlers': ['console', 'mail_admins'],
 
1096
                'level': 'INFO',
 
1097
                'filters': ['special']
 
1098
            }
 
1099
        }
 
1100
    }
 
1101
 
 
1102
For more information about this configuration, you can see the `relevant
 
1103
section <https://docs.djangoproject.com/en/1.3/topics/logging/#configuring-logging>`_
 
1104
of the Django documentation.