File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ MongoDB {+driver-short+} Documentation
22
22
Aggregation </aggregation>
23
23
Security </security>
24
24
Data Formats </data-formats>
25
+ Logging </logging>
25
26
Third-Party Tools </tools>
26
27
FAQ </faq>
27
28
Troubleshooting </troubleshooting>
Original file line number Diff line number Diff line change
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 cursor 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 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.
You can’t perform that action at this time.
0 commit comments