diff --git a/source/index.txt b/source/index.txt index 8ca66669..d131f2ad 100644 --- a/source/index.txt +++ b/source/index.txt @@ -22,6 +22,7 @@ MongoDB {+driver-short+} Documentation Aggregation Security Data Formats + Logging Third-Party Tools FAQ Troubleshooting diff --git a/source/logging.txt b/source/logging.txt new file mode 100644 index 00000000..84ba3470 --- /dev/null +++ b/source/logging.txt @@ -0,0 +1,66 @@ +.. _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 `__. + +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, as shown in the following example: + +.. code-block:: python + + import os + os.environ["MONGODB_LOG_MAX_DOCUMENT_LENGTH"] = "2000"