Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ MongoDB {+driver-short+} Documentation
Aggregation </aggregation>
Security </security>
Data Formats </data-formats>
Logging </logging>
Third-Party Tools </tools>
FAQ </faq>
Troubleshooting </troubleshooting>
Expand Down
61 changes: 61 additions & 0 deletions source/logging.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.. _pymongo-logging:

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

.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol

.. facet::
:name: genre
:values: reference

.. meta::
:keywords: debugging, printing

Overview
--------

In this guide, you can learn how to configure logging options for different
{+driver-short+} components.

{+driver-short+} supports {+language+}'s native logging library. You can configure the logging
verbosity for the following components:

- ``pymongo.command``, which logs command operations
- ``pymongo.connection``, which logs connection management operations
- ``pymongo.serverSelection``, which logs server selection operations

In addition to configuring these options individually, you can configure the global
logging level by setting the log level on ``pymongo``. To learn more about the native
logging library, see the `Python logging library documentation <https://docs.python.org/3/howto/logging.html>`__.

Examples
--------

The follwing example sets the global logging level to ``INFO``:

.. code-block:: python

import logging
logging.getLogger('pymongo').setLevel(logging.INFO)

The following example sets the log level on the ``pymongo.command`` component to
``DEBUG``:

.. code-block:: python

import logging
logging.getLogger('pymongo.command').setLevel(logging.DEBUG)

Configuring Truncation
----------------------

If you enable logging for the ``pymongo.command`` component, the resulting logs will
be truncated after 1000 bytes by default. You can configure this truncation limit
by setting the ``MONGODB_LOG_MAX_DOCUMENT_LENGTH`` environment variable to your
desired length.
Loading