• Home
  • Raw
  • Download

Lines Matching +full:formatting +full:- +full:error +full:- +full:messages

1 :mod:`!logging` --- Logging facility for Python
7 .. moduleauthor:: Vinay Sajip <vinay_sajip@red-dove.com>
8 .. sectionauthor:: Vinay Sajip <vinay_sajip@red-dove.com>
19 * :ref:`Basic Tutorial <logging-basic-tutorial>`
20 * :ref:`Advanced Tutorial <logging-advanced-tutorial>`
21 * :ref:`Logging Cookbook <logging-cookbook>`
23 --------------
30 can include your own messages integrated with messages from third-party
60 .. code-block:: none
69 code fine-grained control if needed. Logged messages to the module-level logger
70 get forwarded to handlers of loggers in higher-level modules, all the way up to
71 the highest-level logger known as the root logger; this approach is known as
76 often based on command-line arguments or application configuration. In most
78 all the lower level loggers at module level eventually forward their messages to
100 --------------
103 *NEVER* be instantiated directly, but always through the module-level function
107 The ``name`` is potentially a period-separated hierarchical value, like
114 and identical to it if you organise your loggers on a per-module basis using
126 .. note:: This attribute should be treated as read-only.
132 .. note:: Do not set this attribute directly - always use :meth:`setLevel`,
140 .. note:: This value should be treated as read-only.
146 any handlers attached to this logger. Messages are passed directly to the
147 ancestor loggers' handlers - neither the level nor filters of the ancestor
150 If this evaluates to false, logging messages are not passed to the handlers
155 ``logging.getLogger('A.B.C').error(...)`` will [subject to passing that logger's
166 should not need to attach a handler to more than one logger - if you just
177 .. note:: This attribute should be treated as read-only; it is normally changed via
179 thread-safe operation.
186 .. note:: This attribute should be treated as read-only.
190 Sets the threshold for this logger to *level*. Logging messages which are less
191 severe than *level* will be ignored; logging messages which have severity *level*
196 all messages to be processed when the logger is the root logger, or delegation
197 to the parent when the logger is a non-root logger). Note that the root logger
208 If the root is reached, and it has a level of NOTSET, then all messages will be
224 This method checks first the module-level level set by
266 *msg* using the string formatting operator. (Note that this means that you can
268 No % formatting operation is performed on *msg* when no *args* are supplied.
291 .. code-block:: none
309 created for the logging event with user-defined attributes. These custom
311 incorporated into logged messages. For example::
313 FORMAT = '%(asctime)s %(clientip)-15s %(user)-8s %(message)s'
321 .. code-block:: none
323 2006-02-08 22:20:02,165 192.168.0.1 fbloggs Protocol problem: connection reset
326 by the logging system. (See the section on :ref:`logrecord-attributes` for more
329 If you choose to use these attributes in logged messages, you need to exercise
333 not be logged because a string formatting exception will occur. So in this case,
337 circumstances, such as multi-threaded servers where the same code executes in
370 it - use ``warning`` instead.
372 .. method:: Logger.error(msg, *args, **kwargs)
374 Logs a message with level :const:`ERROR` on this logger. The arguments are
392 Logs a message with level :const:`ERROR` on this logger. The arguments are
429 number, function name and stack information as a 4-element tuple. The stack
445 Logger-level filtering is applied using :meth:`~Logger.filter`.
459 false is found - that will be the last logger which is checked for the
470 --------------
478 +-----------------------+---------------+-------------------------------------+
488 +-----------------------+---------------+-------------------------------------+
492 +-----------------------+---------------+-------------------------------------+
495 +-----------------------+---------------+-------------------------------------+
502 +-----------------------+---------------+-------------------------------------+
503 | .. py:data:: ERROR | 40 | Due to a more serious problem, the |
506 +-----------------------+---------------+-------------------------------------+
507 | .. py:data:: CRITICAL | 50 | A serious error, indicating that the|
510 +-----------------------+---------------+-------------------------------------+
516 ---------------
550 Sets the threshold for this handler to *level*. Logging messages which are
552 level is set to :const:`NOTSET` (which causes all messages to be
611 during an :meth:`emit` call. If the module-level attribute
613 what is mostly wanted for a logging system - most users will not care about
623 Do formatting for a record - if a formatter is set, use it. Otherwise, use the
633 .. warning:: This method is called after a handler-level lock is acquired, which
639 * Logging configuration APIs acquire the module-level lock, and then
640 individual handler-level locks as those handlers are configured.
642 * Many logging APIs lock the module-level lock. If such an API is called
645 module-level lock *before* the handler-level lock, whereas this thread
646 tries to acquire the module-level lock *after* the handler-level lock
647 (because in this method, the handler-level lock has already been acquired).
651 .. _formatter-objects:
654 -----------------
666 :ref:`logrecord-attributes`.
678 :ref:`old-string-formatting` (``%``), :meth:`str.format` (``{``)
681 not to the actual log messages passed to the logging methods.
682 However, there are :ref:`other ways <formatting-styles>`
683 to use ``{``- and ``$``-formatting for log messages.
688 ``logging.Formatter('%(asctime)s - %(message)s', style='{')``.
709 formatting operation. Returns the resulting string. Before formatting the
712 formatting string contains ``'(asctime)'``, :meth:`formatTime` is called
718 more than one :class:`Formatter` subclass which customizes the formatting
721 has done its formatting, so that the next formatter to handle the event
735 record. Otherwise, the format '%Y-%m-%d %H:%M:%S,uuu' is used, where the
738 ``2003-01-23 00:29:50,411``. The resulting string is returned.
740 This function uses a user-configurable function to convert the creation
749 Previously, the default format was hard-coded as in this example:
750 ``2010-09-06 22:38:15,292`` where the part before the comma is
751 handled by a strptime format string (``'%Y-%m-%d %H:%M:%S'``), and the
754 appended using another format string, ``'%s,%03d'`` --- and both of these
756 these strings are defined as class-level attributes which can be
809 --------------
829 yes. Filters can either modify log records in-place or return a completely
866 information into logs (see :ref:`filters-contextual`).
869 .. _log-record:
872 -----------------
912 which can be a %-format string with placeholders for variable data,
913 or an arbitrary object (see :ref:`arbitrary-object-messages`).
937 user-supplied arguments with the message. If the user-supplied message
939 convert it to a string. This allows use of user-defined classes as
940 messages, whose ``__str__`` method can return the actual format string to
967 .. _logrecord-attributes:
970 --------------------
977 attribute names, their meanings and the corresponding placeholder in a %-style
980 If you are using {}-formatting (:func:`str.format`), you can use
982 $-formatting (:class:`string.Template`), use the form ``${attrname}``. In
986 In the case of {}-formatting, you can specify formatting flags by placing them
992 +----------------+-------------------------+-----------------------------------------------+
999 +----------------+-------------------------+-----------------------------------------------+
1000 | asctime | ``%(asctime)s`` | Human-readable time when the |
1002 | | | this is of the form '2003-07-08 16:49:45,896' |
1005 +----------------+-------------------------+-----------------------------------------------+
1008 +----------------+-------------------------+-----------------------------------------------+
1011 +----------------+-------------------------+-----------------------------------------------+
1013 +----------------+-------------------------+-----------------------------------------------+
1015 +----------------+-------------------------+-----------------------------------------------+
1018 | | | ``'ERROR'``, ``'CRITICAL'``). |
1019 +----------------+-------------------------+-----------------------------------------------+
1022 | | | :const:`WARNING`, :const:`ERROR`, |
1024 +----------------+-------------------------+-----------------------------------------------+
1027 +----------------+-------------------------+-----------------------------------------------+
1031 +----------------+-------------------------+-----------------------------------------------+
1033 +----------------+-------------------------+-----------------------------------------------+
1036 +----------------+-------------------------+-----------------------------------------------+
1040 | | | (see :ref:`arbitrary-object-messages`). |
1041 +----------------+-------------------------+-----------------------------------------------+
1043 +----------------+-------------------------+-----------------------------------------------+
1046 +----------------+-------------------------+-----------------------------------------------+
1048 +----------------+-------------------------+-----------------------------------------------+
1050 +----------------+-------------------------+-----------------------------------------------+
1054 +----------------+-------------------------+-----------------------------------------------+
1060 +----------------+-------------------------+-----------------------------------------------+
1062 +----------------+-------------------------+-----------------------------------------------+
1064 +----------------+-------------------------+-----------------------------------------------+
1066 +----------------+-------------------------+-----------------------------------------------+
1074 .. _logger-adapter:
1077 ---------------------
1081 :ref:`adding contextual information to your logging output <context-info>`.
1086 underlying :class:`Logger` instance, a dict-like object (*extra*), and a
1110 :meth:`~Logger.warning`, :meth:`~Logger.error`, :meth:`~Logger.exception`,
1134 -------------
1136 The logging module is intended to be thread-safe without any special work
1144 re-entrant, and so cannot be invoked from such signal handlers.
1147 Module-Level Functions
1148 ----------------------
1150 In addition to the classes described above, there are a number of module-level
1158 dot-separated hierarchical name like *'a'*, *'a.b'* or *'a.b.c.d'*. Choice
1201 ``debug`` and the other module-level functions may be convenient. However,
1203 configuration, and should therefore prefer creating a module-level logger and
1204 calling :meth:`Logger.debug` (or other level-specific methods) on it, as
1221 it - use ``warning`` instead.
1224 .. function:: error(msg, *args, **kwargs)
1226 Logs a message with level :const:`ERROR` on the root logger. The arguments and behavior
1238 Logs a message with level :const:`ERROR` on the root logger. The arguments and behavior
1279 section on :ref:`custom-levels`.
1293 If *level* is one of the predefined levels :const:`CRITICAL`, :const:`ERROR`,
1310 ``%(levelname)s`` format specifier (see :ref:`logrecord-attributes`), and
1345 :func:`error` and :func:`critical` will call :func:`basicConfig` automatically
1356 such as messages being duplicated in the log.
1362 +--------------+---------------------------------------------+
1368 +--------------+---------------------------------------------+
1372 +--------------+---------------------------------------------+
1377 +--------------+---------------------------------------------+
1380 +--------------+---------------------------------------------+
1383 | | ``'{'`` or ``'$'`` for :ref:`printf-style |
1384 | | <old-string-formatting>`, |
1388 +--------------+---------------------------------------------+
1391 +--------------+---------------------------------------------+
1394 | | argument is incompatible with *filename* - |
1397 +--------------+---------------------------------------------+
1404 | | with *filename* or *stream* - if both |
1406 +--------------+---------------------------------------------+
1412 +--------------+---------------------------------------------+
1417 +--------------+---------------------------------------------+
1427 +--------------+---------------------------------------------+
1495 Module-Level Attributes
1496 -----------------------
1504 ``sys.stderr``. This replaces the earlier error message saying that
1518 for a logging system - most users will not care about errors in
1523 ------------------------------------
1551 :pep:`282` - A Logging System
1555 `Original Python logging package <https://old.red-dove.com/python_logging.html>`_