Skip to content

Commit 4ba95d1

Browse files
committed
DOCSP-46696: Logging page (#154)
(cherry picked from commit 0876f2f)
1 parent d7faea9 commit 4ba95d1

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

source/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ MongoDB {+driver-short+} Documentation
2222
Aggregation </aggregation>
2323
Security </security>
2424
Data Formats </data-formats>
25+
Logging </logging>
2526
Third-Party Tools </tools>
2627
FAQ </faq>
2728
Troubleshooting </troubleshooting>

source/logging.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
.. _pymongo-logging:
2+
3+
=======
4+
Logging
5+
=======
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:keywords: debugging, printing
19+
20+
Overview
21+
--------
22+
23+
In this guide, you can learn how to configure logging options for different
24+
{+driver-short+} components.
25+
26+
{+driver-short+} supports {+language+}'s native logging library. You can configure the logging
27+
verbosity for the following components:
28+
29+
- ``pymongo.command``, which logs command operations
30+
- ``pymongo.connection``, which logs connection management operations
31+
- ``pymongo.serverSelection``, which logs server selection operations
32+
33+
In addition to configuring these options individually, you can configure the global
34+
logging level by setting the log level on ``pymongo``. To learn more about the native
35+
logging library, see the `Python logging library documentation <https://docs.python.org/3/howto/logging.html>`__.
36+
37+
Examples
38+
--------
39+
40+
The follwing example sets the global logging level to ``INFO``:
41+
42+
.. code-block:: python
43+
44+
import logging
45+
logging.getLogger("pymongo").setLevel(logging.INFO)
46+
47+
The following example sets the log level on the ``pymongo.command`` component to
48+
``DEBUG``:
49+
50+
.. code-block:: python
51+
52+
import logging
53+
logging.getLogger("pymongo.command").setLevel(logging.DEBUG)
54+
55+
Configuring Truncation
56+
----------------------
57+
58+
If you enable logging for the ``pymongo.command`` component, the resulting logs will
59+
be truncated after 1000 bytes by default. You can configure this truncation limit
60+
by setting the ``MONGODB_LOG_MAX_DOCUMENT_LENGTH`` environment variable to your
61+
desired length, as shown in the following example:
62+
63+
.. code-block:: python
64+
65+
import os
66+
os.environ["MONGODB_LOG_MAX_DOCUMENT_LENGTH"] = "2000"

0 commit comments

Comments
 (0)