From df64e104c11e8e5ca6c7332e4e740fb36c2ef9f0 Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Fri, 11 Jul 2025 09:54:43 -0400 Subject: [PATCH 1/9] DOCSP-51344: Logging --- .../logging-and-monitoring/log4j2-gradle.rst | 6 + .../logging-and-monitoring/log4j2-maven.rst | 9 + .../logging-and-monitoring/logback-gradle.rst | 5 + .../logging-and-monitoring/logback-maven.rst | 9 + .../logging-and-monitoring/logging.rst | 6 + source/logging-and-monitoring/logging.txt | 407 +++++++++++++++++- 6 files changed, 441 insertions(+), 1 deletion(-) create mode 100644 source/includes/logging-and-monitoring/log4j2-gradle.rst create mode 100644 source/includes/logging-and-monitoring/log4j2-maven.rst create mode 100644 source/includes/logging-and-monitoring/logback-gradle.rst create mode 100644 source/includes/logging-and-monitoring/logback-maven.rst create mode 100644 source/includes/logging-and-monitoring/logging.rst diff --git a/source/includes/logging-and-monitoring/log4j2-gradle.rst b/source/includes/logging-and-monitoring/log4j2-gradle.rst new file mode 100644 index 00000000..525ee65b --- /dev/null +++ b/source/includes/logging-and-monitoring/log4j2-gradle.rst @@ -0,0 +1,6 @@ +.. code-block:: groovy + + dependencies { + implementation 'org.apache.logging.log4j:log4j-slf4j-impl:{+log4j2Version+}' + } + \ No newline at end of file diff --git a/source/includes/logging-and-monitoring/log4j2-maven.rst b/source/includes/logging-and-monitoring/log4j2-maven.rst new file mode 100644 index 00000000..a573f3c9 --- /dev/null +++ b/source/includes/logging-and-monitoring/log4j2-maven.rst @@ -0,0 +1,9 @@ +.. code-block:: xml + + + + org.apache.logging.log4j + log4j-slf4j-impl + {+log4j2Version+} + + diff --git a/source/includes/logging-and-monitoring/logback-gradle.rst b/source/includes/logging-and-monitoring/logback-gradle.rst new file mode 100644 index 00000000..2308da3e --- /dev/null +++ b/source/includes/logging-and-monitoring/logback-gradle.rst @@ -0,0 +1,5 @@ +.. code-block:: groovy + + dependencies { + implementation 'ch.qos.logback:logback-classic:{+logbackVersion+}' + } diff --git a/source/includes/logging-and-monitoring/logback-maven.rst b/source/includes/logging-and-monitoring/logback-maven.rst new file mode 100644 index 00000000..8e5737d3 --- /dev/null +++ b/source/includes/logging-and-monitoring/logback-maven.rst @@ -0,0 +1,9 @@ +.. code-block:: xml + + + + ch.qos.logback + logback-classic + {+logbackVersion+} + + diff --git a/source/includes/logging-and-monitoring/logging.rst b/source/includes/logging-and-monitoring/logging.rst new file mode 100644 index 00000000..f2658537 --- /dev/null +++ b/source/includes/logging-and-monitoring/logging.rst @@ -0,0 +1,6 @@ +.. code-block:: kotlin + + val mongoClient = MongoClient.create(); + val database = mongoClient.getDatabase(); + val collection = database.getCollection(); + collection.find().first(); diff --git a/source/logging-and-monitoring/logging.txt b/source/logging-and-monitoring/logging.txt index ee9285ea..fd2381e7 100644 --- a/source/logging-and-monitoring/logging.txt +++ b/source/logging-and-monitoring/logging.txt @@ -8,4 +8,409 @@ Log Driver Events :local: :backlinks: none :depth: 2 - :class: singlecol \ No newline at end of file + :class: singlecol + +Overview +-------- + +In this guide, you can learn how to set up and configure a logger in the {+driver-short+}. + +You will learn how to: + +- Set up a logger by using Simple Logging Facade for Java (SLF4J) +- Configure the log level + +This guide shows how to record events in the driver. If you want to learn how to +use information about the activity of the driver in code, see the :ref:`kotlin-sync-monitoring` +guide. + +Set Up a Logger +--------------- + +The {+driver-short+} uses SLF4J to allow you to specify your logging framework of choice. +For mroe information about SLF4J, see the `SLF4J documentation `__. + +Setting up a logger is optional. To set up a logger, you must include the following in +your project: + +- The ``slf4j-api`` artifact in your classpath +- A logging framework +- A **binding** + +If the driver can't find the ``slf4j-api`` artifact in your classpath, the driver outputs +the following warning and disables all further logging: + +.. code-block:: + + WARNING: SLF4J not found on the classpath. Logging is disabled for the 'org.mongodb.driver' component + +A binding is a piece of code that connects the ``slf4j-api`` artifact to a logging framework. + +Logger Setup Example +~~~~~~~~~~~~~~~~~~~~ + +The following example shows how to set up a logger. Select the :guilabel:`Logback` or +:guilabel:`Log4j2` tab to see the corresponding syntax: + +.. tabs:: + + .. tab:: Logback + :tabid: Logback-binding + + Select the :guilabel:`Maven` or :guilabel:`Gradle` tab to learn about how to set up + Logback with your project's dependency management tool. + + .. tabs:: + + .. tab:: Maven + :tabid: maven + + Add the following dependency to your ``pom.xml`` file. + + .. include:: /includes/logging-and-monitoring/logback-maven.rst + + .. tab:: Gradle + :tabid: gradle + + Add the following dependency to your ``build.gradle`` file. + + .. include:: /includes/logging-and-monitoring/logback-gradle.rst + + Once you have included the preceding dependency, connect to your + MongoDB instance and retrieve a document with the following code: + + .. include:: /includes/logging-and-monitoring/logging.rst + + The preceding code will ouput a message that resembles the following: + + .. code-block:: none + :copyable: false + + ... + 12:14:55.853 [main] DEBUG org.mongodb.driver.connection - Opened connection [connectionId{localValue:3, serverValue:3}] to + 12:14:55.861 [main] DEBUG org.mongodb.driver.protocol.command - Command "find" started on database using a connection with driver-generated ID 3 and server-generated ID 3 to . The request ID is 5. Command: {"find": "", "filter": {}, "limit": 1, "singleBatch": true, "$db": "", "lsid": {"id": {"$binary": {"base64": "<_id>", "subType": "04"}}}, "$readPreference": {"mode": "primaryPreferred"}} + 12:14:55.864 [main] DEBUG org.mongodb.driver.protocol.command - Command "find" succeeded in 4.34 ms using a connection with driver-generated ID 3 and server-generated ID 3 to .", "firstBatch": []}, "ok": 1.0, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1673778535, "i": 1}}, "signature": {"hash": {"$binary": {"base64": "<_id>", "subType": "00"}}, "keyId": 0}}, "operationTime": {"$timestamp": {"t": 1673778535, "i": 1}}} + + .. note:: Default Log Level + + The default log level of Logback is DEBUG. To learn how to change your + Logback logger's log level, see the + :ref:`Configure Log Level ` section of this page. + + For more information about Logback, see the + `Logback manual `__. + + .. tab:: Log4j2 + :tabid: Log4j2-binding + + Select the :guilabel:`Maven` or :guilabel:`Gradle` tab to learn about how to set up + Log4j2 with your project's dependency management tool. + + .. tabs:: + + .. tab:: Maven + :tabid: maven + + Add the following dependency to your ``pom.xml`` file. + + .. include:: /includes/logging-and-monitoring/log4j2-maven.rst + + .. tab:: Gradle + :tabid: gradle + + Add the following dependency to your ``build.gradle`` file. + + .. include:: /includes/logging-and-monitoring/log4j2-gradle.rst + + Once you have included the preceding dependency, log an error by using the + following code: + + .. code-block:: kotlin + + import org.slf4j.Logger; + import org.slf4j.LoggerFactory; + + ... + + val logger = LoggerFactory.getLogger("MyApp"); + logger.error("Logging an Error"); + + The preceding code will ouput a message that resembles the following: + + .. code-block:: none + :copyable: false + + 12:35:00.438 [main] ERROR - Logging an Error + + .. note:: Default Log Level + + The default log level of Log4J2 is ERROR. This means that running + standard operations in the MongoDB Java driver will not produce output + from Log4J2 without configuration. To learn how to change your Log4J2 + logger's log level, see the + :ref:`Configure Log Level ` section of this page. + + For more information about Log4j2, see the + `Log4j2 manual `__. + +.. _kotlin-sync-configure-log-level: + +Configure Log Level +------------------- + +You can configure the log level of your logger by using the configuration system of the logging +framework bound to SLF4J. The log level specifies a lower bound for how urgent a message +must be for the logger to output that message. + +Logger Configuration Example +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The following example configures the log level to ``INFO``. Select the :guilabel:`Logback` or +:guilabel:`Log4j2` tab to see the corresponding syntax: + +.. tabs:: + + .. tab:: Logback + :tabid: Logback-binding + + Specify Logback configurations in a file named ``logback.xml``. + You must be able to access this file from your classpath. + + The Logback framework defines the following log levels ordered from most urgent to + least urgent: + + - ``ERROR`` + - ``WARN`` + - ``INFO`` + - ``DEBUG`` + - ``TRACE`` + + Set your ``logback.xml`` file to the following: + + .. code-block:: xml + + + + + + %-4relative [%thread] %-5level %logger{30} - %msg%n + + + + + + + + + To test that your logger configuration was successful, run the following + code: + + .. include:: /includes/logging-and-monitoring/logging.rst + + This code produces output that resembles the following: + + .. code-block:: none + :copyable: false + + ... + 1317 [cluster-ClusterId{value='', description='null'}-] INFO org.mongodb.driver.cluster - Discovered replica set primary + 1568 [main] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:}] to + + For more information about configuring Logback, see the + `the Logback Manual `__. + + .. tabs:: + + .. tab:: Log4j2 + :tabid: Log4j2-binding + + Specify Log4j2 configurations in a file named ``log4j2.xml``. + You must be able to access this file from your classpath. + + The Log4j2 framework defines the following log levels, ordered from most urgent to + least urgent: + + - ``FATAL`` + - ``ERROR`` + - ``WARN`` + - ``INFO`` + - ``DEBUG`` + - ``TRACE`` + - ``ALL`` + + Set your ``log4j2.xml`` file to the following: + + .. code-block:: xml + + + + + + + + + + + + + + + + To test that your logger configuration was successful, run the following + code: + + .. include:: /includes/logging-and-monitoring/logging.rst + + This code produces output that resembles the following: + + .. code-block:: none + :copyable: false + + ... + 10:14:57.633 [cluster-ClusterId{value=, description='null'}-] INFO org.mongodb.driver.cluster - Discovered replica set primary + 10:14:57.790 [main] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:}] to + +Logger Names +------------ + +Your logger uses logger names to help organize different logging events. Logger names +are strings that form a hierarchy. A logger is an ancestor of another logger if its +name followed by a ``"."`` is a prefix of the other logger's name. For example, +``"grandparent"`` is an ancestor of ``"grandparent.parent"`` which is an ancestor of +``"grandparent.parent.child"``. A logger inherits the properties of its ancestor logger and +can define its own. + +The {+driver-short+} defines the following logger names to organize different logging events: + +.. list-table:: + :widths: 25 75 + :header-rows: 1 + + * - Logger Name + - Description + + * - org.mongodb.driver.authenticator + - Logs authentication events + + * - org.mongodb.driver.client + - Logs events related to MongoClient instances + + * - org.mongodb.driver.cluster + - Logs events related to monitoring of MongoDB deployments + + * - org.mongodb.driver.connection + - Logs connections and connection pools + + * - org.mongodb.driver.connection.tls + - Logs TLS events + + * - org.mongodb.driver.operation + - Logs operations, including logging related to automatic retries + + * - org.mongodb.driver.protocol + - Logs commands sent to and replies received from MongoDB deployments + + * - org.mongodb.driver.uri + - Logs connection string parsing events + + * - org.mongodb.driver.management + - Logs Java Management Extensions (JMX) events + +Logger Name Example +~~~~~~~~~~~~~~~~~~~ + +The following example disables the root logger and sets the log level for the +``org.mongodb.driver.connection`` logger to ``DEBUG``. This will cause the driver to log +only messages related to connections and connection pools at the ``DEBUG`` level or higher. +Select the :guilabel:`Logback` or :guilabel:`Log4j2` tab to see the corresponding syntax: + +.. tabs:: + + .. tab:: Logback + :tabid: Logback-binding + + Set your ``logback.xml`` file to the following: + + .. code-block:: xml + :emphasize-lines: 10 + + + + + + %-4relative [%thread] %-5level %logger{30} - %msg%n + + + + + + + + + + To test that your logger configuration was successful, run the following + code. + + .. include:: /includes/logging-and-monitoring/logging.rst + + This code produces output that resembles the following. + + .. code-block:: none + :copyable: false + + ... + 829 [cluster-rtt-ClusterId{value='', description='null'}-] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:2, serverValue:}] to + 977 [main] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:}] to + + .. tab:: Log4j2 + :tabid: Log4j2-binding + + Set your ``log4j2.xml`` file to the following: + + .. code-block:: xml + :emphasize-lines: 9 + + + + + + + + + + + + + + + + + To test that your logger configuration was successful, run the following + code. + + .. include:: /includes/logging-and-monitoring/logging.rst + + This code produces output that resembles the following: + + .. code-block:: none + :copyable: false + + ... + 15:40:23.005 [cluster-ClusterId{value='', description='null'}-] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:3, serverValue:}] to + 15:40:23.159 [main] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:}] to + +Additional Information +---------------------- + +To learn more about MongoDB's logging capabilities, see :manual:`log-messages` in the {+mdb-server+} +manual. + +For complete information about the logging frameworks discussed in this guide, see the +following external documentation: + +- `SLF4J documentation `__ +- `Logback documentation `__ +- `Log4j2 documentation `__ + From 0960e2d91f2fed21936c69e5a841062b88935e61 Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Fri, 11 Jul 2025 10:16:44 -0400 Subject: [PATCH 2/9] Fixes --- source/logging-and-monitoring.txt | 2 +- source/logging-and-monitoring/logging.txt | 34 ++++++++--------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/source/logging-and-monitoring.txt b/source/logging-and-monitoring.txt index 4aa780f6..a2287066 100644 --- a/source/logging-and-monitoring.txt +++ b/source/logging-and-monitoring.txt @@ -13,8 +13,8 @@ Logging and Monitoring .. toctree:: - Monitoring Logging + Monitoring Change Streams Overview diff --git a/source/logging-and-monitoring/logging.txt b/source/logging-and-monitoring/logging.txt index fd2381e7..15fd6bd2 100644 --- a/source/logging-and-monitoring/logging.txt +++ b/source/logging-and-monitoring/logging.txt @@ -15,11 +15,6 @@ Overview In this guide, you can learn how to set up and configure a logger in the {+driver-short+}. -You will learn how to: - -- Set up a logger by using Simple Logging Facade for Java (SLF4J) -- Configure the log level - This guide shows how to record events in the driver. If you want to learn how to use information about the activity of the driver in code, see the :ref:`kotlin-sync-monitoring` guide. @@ -35,7 +30,7 @@ your project: - The ``slf4j-api`` artifact in your classpath - A logging framework -- A **binding** +- A **binding** that connects the ``slf4j-api`` artifact to a logging framework If the driver can't find the ``slf4j-api`` artifact in your classpath, the driver outputs the following warning and disables all further logging: @@ -44,8 +39,6 @@ the following warning and disables all further logging: WARNING: SLF4J not found on the classpath. Logging is disabled for the 'org.mongodb.driver' component -A binding is a piece of code that connects the ``slf4j-api`` artifact to a logging framework. - Logger Setup Example ~~~~~~~~~~~~~~~~~~~~ @@ -58,7 +51,7 @@ The following example shows how to set up a logger. Select the :guilabel:`Logbac :tabid: Logback-binding Select the :guilabel:`Maven` or :guilabel:`Gradle` tab to learn about how to set up - Logback with your project's dependency management tool. + Logback with your project's dependency management tool: .. tabs:: @@ -97,9 +90,6 @@ The following example shows how to set up a logger. Select the :guilabel:`Logbac Logback logger's log level, see the :ref:`Configure Log Level ` section of this page. - For more information about Logback, see the - `Logback manual `__. - .. tab:: Log4j2 :tabid: Log4j2-binding @@ -290,31 +280,31 @@ The {+driver-short+} defines the following logger names to organize different lo * - Logger Name - Description - * - org.mongodb.driver.authenticator + * - ``org.mongodb.driver.authenticator`` - Logs authentication events - * - org.mongodb.driver.client + * - ``org.mongodb.driver.client`` - Logs events related to MongoClient instances - * - org.mongodb.driver.cluster + * - ``org.mongodb.driver.cluster`` - Logs events related to monitoring of MongoDB deployments - * - org.mongodb.driver.connection + * - ``org.mongodb.driver.connection`` - Logs connections and connection pools - * - org.mongodb.driver.connection.tls + * - ``org.mongodb.driver.connection.tls`` - Logs TLS events - * - org.mongodb.driver.operation + * - ``org.mongodb.driver.operation`` - Logs operations, including logging related to automatic retries - * - org.mongodb.driver.protocol + * - ``org.mongodb.driver.protocol`` - Logs commands sent to and replies received from MongoDB deployments - * - org.mongodb.driver.uri + * - ``org.mongodb.driver.uri`` - Logs connection string parsing events - * - org.mongodb.driver.management + * - ``org.mongodb.driver.management`` - Logs Java Management Extensions (JMX) events Logger Name Example @@ -404,7 +394,7 @@ Select the :guilabel:`Logback` or :guilabel:`Log4j2` tab to see the correspondin Additional Information ---------------------- -To learn more about MongoDB's logging capabilities, see :manual:`log-messages` in the {+mdb-server+} +To learn more about MongoDB's logging capabilities, see :manual:`` in the {+mdb-server+} manual. For complete information about the logging frameworks discussed in this guide, see the From 52322757dde17551f9473c7b62a4d743262223ea Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Fri, 11 Jul 2025 10:21:02 -0400 Subject: [PATCH 3/9] Fix --- source/logging-and-monitoring/logging.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/logging-and-monitoring/logging.txt b/source/logging-and-monitoring/logging.txt index 15fd6bd2..d8d3a7c7 100644 --- a/source/logging-and-monitoring/logging.txt +++ b/source/logging-and-monitoring/logging.txt @@ -394,7 +394,7 @@ Select the :guilabel:`Logback` or :guilabel:`Log4j2` tab to see the correspondin Additional Information ---------------------- -To learn more about MongoDB's logging capabilities, see :manual:`` in the {+mdb-server+} +To learn more about MongoDB's logging capabilities, see :manual:`` in the {+mdb-server+} manual. For complete information about the logging frameworks discussed in this guide, see the From dba8d0b15040fa313d4f81498d24a53e29751830 Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Fri, 11 Jul 2025 10:24:08 -0400 Subject: [PATCH 4/9] fix again --- source/logging-and-monitoring/logging.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/logging-and-monitoring/logging.txt b/source/logging-and-monitoring/logging.txt index d8d3a7c7..5e01a254 100644 --- a/source/logging-and-monitoring/logging.txt +++ b/source/logging-and-monitoring/logging.txt @@ -394,7 +394,7 @@ Select the :guilabel:`Logback` or :guilabel:`Log4j2` tab to see the correspondin Additional Information ---------------------- -To learn more about MongoDB's logging capabilities, see :manual:`` in the {+mdb-server+} +To learn more about MongoDB's logging capabilities, see :manual:`Log Messages ` in the {+mdb-server+} manual. For complete information about the logging frameworks discussed in this guide, see the From c70cc1431525c1d0cd011c876bed91dd3aff430d Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Fri, 11 Jul 2025 10:27:53 -0400 Subject: [PATCH 5/9] Fix --- source/logging-and-monitoring/logging.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/logging-and-monitoring/logging.txt b/source/logging-and-monitoring/logging.txt index 5e01a254..b4f61cfc 100644 --- a/source/logging-and-monitoring/logging.txt +++ b/source/logging-and-monitoring/logging.txt @@ -140,9 +140,6 @@ The following example shows how to set up a logger. Select the :guilabel:`Logbac logger's log level, see the :ref:`Configure Log Level ` section of this page. - For more information about Log4j2, see the - `Log4j2 manual `__. - .. _kotlin-sync-configure-log-level: Configure Log Level @@ -207,9 +204,6 @@ The following example configures the log level to ``INFO``. Select the :guilabel 1317 [cluster-ClusterId{value='', description='null'}-] INFO org.mongodb.driver.cluster - Discovered replica set primary 1568 [main] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:}] to - For more information about configuring Logback, see the - `the Logback Manual `__. - .. tabs:: .. tab:: Log4j2 From c343f5e159e3f1f46dbea8c306da7f9f5d4ae027 Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Fri, 11 Jul 2025 14:14:43 -0400 Subject: [PATCH 6/9] MB feedback --- snooty.toml | 2 ++ source/logging-and-monitoring/logging.txt | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/snooty.toml b/snooty.toml index 1f20e7e9..c0c9ebdd 100644 --- a/snooty.toml +++ b/snooty.toml @@ -36,3 +36,5 @@ kotlin-docs = "https://kotlinlang.org" serialization-version = "1.6.0" kotlinx-dt-version = "0.6.1" mongocrypt-version = "{+full-version+}" +logbackVersion = "1.2.11" +log4j2Version = "2.17.1" diff --git a/source/logging-and-monitoring/logging.txt b/source/logging-and-monitoring/logging.txt index b4f61cfc..4695052b 100644 --- a/source/logging-and-monitoring/logging.txt +++ b/source/logging-and-monitoring/logging.txt @@ -22,8 +22,9 @@ guide. Set Up a Logger --------------- -The {+driver-short+} uses SLF4J to allow you to specify your logging framework of choice. -For mroe information about SLF4J, see the `SLF4J documentation `__. +The {+driver-short+} uses Simple Logging Facade For Java (SLF4J) to allow you to specify +your logging framework of choice. For more information about SLF4J, see the `SLF4J documentation +`__. Setting up a logger is optional. To set up a logger, you must include the following in your project: @@ -135,7 +136,7 @@ The following example shows how to set up a logger. Select the :guilabel:`Logbac .. note:: Default Log Level The default log level of Log4J2 is ERROR. This means that running - standard operations in the MongoDB Java driver will not produce output + standard operations in the {+driver-short+} will not produce output from Log4J2 without configuration. To learn how to change your Log4J2 logger's log level, see the :ref:`Configure Log Level ` section of this page. @@ -261,14 +262,14 @@ Logger Names Your logger uses logger names to help organize different logging events. Logger names are strings that form a hierarchy. A logger is an ancestor of another logger if its name followed by a ``"."`` is a prefix of the other logger's name. For example, -``"grandparent"`` is an ancestor of ``"grandparent.parent"`` which is an ancestor of +``"grandparent"`` is an ancestor of ``"grandparent.parent"``, which is an ancestor of ``"grandparent.parent.child"``. A logger inherits the properties of its ancestor logger and -can define its own. +can also define its own properties. The {+driver-short+} defines the following logger names to organize different logging events: .. list-table:: - :widths: 25 75 + :widths: 40 60 :header-rows: 1 * - Logger Name From 1d9baa99a1a1430533b15a6fe5e68f2a921f843d Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Fri, 11 Jul 2025 15:41:08 -0400 Subject: [PATCH 7/9] Fix --- source/logging-and-monitoring/logging.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/logging-and-monitoring/logging.txt b/source/logging-and-monitoring/logging.txt index 4695052b..e7d848f4 100644 --- a/source/logging-and-monitoring/logging.txt +++ b/source/logging-and-monitoring/logging.txt @@ -307,7 +307,7 @@ Logger Name Example The following example disables the root logger and sets the log level for the ``org.mongodb.driver.connection`` logger to ``DEBUG``. This will cause the driver to log -only messages related to connections and connection pools at the ``DEBUG`` level or higher. +messages only related to connections and connection pools at the ``DEBUG`` level or higher. Select the :guilabel:`Logback` or :guilabel:`Log4j2` tab to see the corresponding syntax: .. tabs:: From e56c7408b985527fca2062c9ed15a5738a7fd7ce Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Tue, 22 Jul 2025 16:31:00 -0400 Subject: [PATCH 8/9] Update log output --- source/logging-and-monitoring/logging.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source/logging-and-monitoring/logging.txt b/source/logging-and-monitoring/logging.txt index e7d848f4..4fa25632 100644 --- a/source/logging-and-monitoring/logging.txt +++ b/source/logging-and-monitoring/logging.txt @@ -202,8 +202,13 @@ The following example configures the log level to ``INFO``. Select the :guilabel :copyable: false ... - 1317 [cluster-ClusterId{value='', description='null'}-] INFO org.mongodb.driver.cluster - Discovered replica set primary - 1568 [main] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:}] to + 13:21:29.164 [main] INFO org.mongodb.driver.client - MongoClient with metadata {"driver": {"name": "mongo-java-driver|sync|kotlin", "version": "5.6.0-alpha0-20-g222541cd92-dirty"}, "os": {"type": "Darwin", "name": "Mac OS X", "architecture": "aarch64", "version": "15.5"}, "platform": "Java/JetBrains s.r.o./17.0.9+8-b1166.2|kotlin/1.8.10"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=null, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=null, transportSettings=null, commandListeners=[], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, CollectionCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, EnumCodecProvider{}, com.mongodb.client.model.mql.ExpressionCodecProvider@63a12c68, com.mongodb.Jep395RecordCodecProvider@28f3b248, com.mongodb.KotlinCodecProvider@1b1426f4]}, loggerSettings=LoggerSettings{maxDocumentLength=1000}, clusterSettings={hosts=[localhost:27017], srvServiceName=mongodb, mode=SINGLE, requiredClusterType=UNKNOWN, requiredReplicaSetName='null', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='15 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverMonitoringMode=AUTO, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=false, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=UNSPECIFIED, serverApi=null, autoEncryptionSettings=null, dnsClient=null, inetAddressResolver=null, contextProvider=null, timeoutMS=null} + 13:21:29.213 [main] DEBUG org.mongodb.driver.connection - Connection created: address=localhost:27017, driver-generated ID=3 + 13:21:29.218 [main] DEBUG org.mongodb.driver.connection - Connection ready: address=localhost:27017, driver-generated ID=3, established in=5 ms + 13:21:29.219 [main] DEBUG org.mongodb.driver.connection - Connection checked out: address=localhost:27017, driver-generated ID=3, duration=10 ms + 13:21:29.237 [main] DEBUG org.mongodb.driver.protocol.command - Command "find" started on database "test" using a connection with driver-generated ID 3 and server-generated ID 516757 to localhost:27017. The request ID is 5 and the operation ID is 5. Command: {"find": "test", "filter": {}, "limit": 1, "singleBatch": true, "$db": "test", "lsid": {"id": {"$binary": {"base64": "Bw3a3QK7QAGob8VghbJguw==", "subType": "04"}}}} + 13:21:29.244 [main] DEBUG org.mongodb.driver.protocol.command - Command "find" succeeded on database "test" in 8.823416 ms using a connection with driver-generated ID 3 and server-generated ID 516757 to localhost:27017. The request ID is 5 and the operation ID is 5. Command reply: {"cursor": {"firstBatch": [{"_id": {"$oid": "6876d15f70164c1e5a47be02"}, "advance": "$clusterTime"}], "id": 0, "ns": "test.test"}, "ok": 1.0, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1753129287, "i": 1}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}, "operationTime": {"$timestamp": {"t": 1753129283, "i": 1}}} + 13:21:29.249 [main] DEBUG org.mongodb.driver.operation - Received batch of 1 documents with cursorId 0 from server localhost:27017 .. tabs:: @@ -253,8 +258,7 @@ The following example configures the log level to ``INFO``. Select the :guilabel :copyable: false ... - 10:14:57.633 [cluster-ClusterId{value=, description='null'}-] INFO org.mongodb.driver.cluster - Discovered replica set primary - 10:14:57.790 [main] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:}] to + Logger Names ------------ From 7cdcde2e8fb45fa07323795769ecc7a8a709eb6f Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Wed, 23 Jul 2025 15:14:15 -0400 Subject: [PATCH 9/9] VS feedback --- source/logging-and-monitoring/logging.txt | 43 +++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/source/logging-and-monitoring/logging.txt b/source/logging-and-monitoring/logging.txt index 4fa25632..01b57477 100644 --- a/source/logging-and-monitoring/logging.txt +++ b/source/logging-and-monitoring/logging.txt @@ -81,9 +81,10 @@ The following example shows how to set up a logger. Select the :guilabel:`Logbac :copyable: false ... - 12:14:55.853 [main] DEBUG org.mongodb.driver.connection - Opened connection [connectionId{localValue:3, serverValue:3}] to - 12:14:55.861 [main] DEBUG org.mongodb.driver.protocol.command - Command "find" started on database using a connection with driver-generated ID 3 and server-generated ID 3 to . The request ID is 5. Command: {"find": "", "filter": {}, "limit": 1, "singleBatch": true, "$db": "", "lsid": {"id": {"$binary": {"base64": "<_id>", "subType": "04"}}}, "$readPreference": {"mode": "primaryPreferred"}} - 12:14:55.864 [main] DEBUG org.mongodb.driver.protocol.command - Command "find" succeeded in 4.34 ms using a connection with driver-generated ID 3 and server-generated ID 3 to .", "firstBatch": []}, "ok": 1.0, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1673778535, "i": 1}}, "signature": {"hash": {"$binary": {"base64": "<_id>", "subType": "00"}}, "keyId": 0}}, "operationTime": {"$timestamp": {"t": 1673778535, "i": 1}}} + 12:14:55.833 [main] DEBUG org.mongodb.driver.connection - Checkout started for connection to + 12:14:55.834 [main] DEBUG org.mongodb.driver.connection - Connection created: address=, driver-generated ID=3 + 12:14:55.836 [main] DEBUG org.mongodb.driver.connection - Connection ready: address=, driver-generated ID=3, established in=4 ms + 12:14:55.843 [main] DEBUG org.mongodb.driver.connection - Connection checked out: address=, driver-generated ID=3, duration=9 ms .. note:: Default Log Level @@ -202,15 +203,8 @@ The following example configures the log level to ``INFO``. Select the :guilabel :copyable: false ... - 13:21:29.164 [main] INFO org.mongodb.driver.client - MongoClient with metadata {"driver": {"name": "mongo-java-driver|sync|kotlin", "version": "5.6.0-alpha0-20-g222541cd92-dirty"}, "os": {"type": "Darwin", "name": "Mac OS X", "architecture": "aarch64", "version": "15.5"}, "platform": "Java/JetBrains s.r.o./17.0.9+8-b1166.2|kotlin/1.8.10"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=null, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=null, transportSettings=null, commandListeners=[], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, CollectionCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, EnumCodecProvider{}, com.mongodb.client.model.mql.ExpressionCodecProvider@63a12c68, com.mongodb.Jep395RecordCodecProvider@28f3b248, com.mongodb.KotlinCodecProvider@1b1426f4]}, loggerSettings=LoggerSettings{maxDocumentLength=1000}, clusterSettings={hosts=[localhost:27017], srvServiceName=mongodb, mode=SINGLE, requiredClusterType=UNKNOWN, requiredReplicaSetName='null', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='15 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, proxySettings=ProxySettings{host=null, port=null, username=null, password=null}}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverMonitoringMode=AUTO, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=false, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=UNSPECIFIED, serverApi=null, autoEncryptionSettings=null, dnsClient=null, inetAddressResolver=null, contextProvider=null, timeoutMS=null} - 13:21:29.213 [main] DEBUG org.mongodb.driver.connection - Connection created: address=localhost:27017, driver-generated ID=3 - 13:21:29.218 [main] DEBUG org.mongodb.driver.connection - Connection ready: address=localhost:27017, driver-generated ID=3, established in=5 ms - 13:21:29.219 [main] DEBUG org.mongodb.driver.connection - Connection checked out: address=localhost:27017, driver-generated ID=3, duration=10 ms - 13:21:29.237 [main] DEBUG org.mongodb.driver.protocol.command - Command "find" started on database "test" using a connection with driver-generated ID 3 and server-generated ID 516757 to localhost:27017. The request ID is 5 and the operation ID is 5. Command: {"find": "test", "filter": {}, "limit": 1, "singleBatch": true, "$db": "test", "lsid": {"id": {"$binary": {"base64": "Bw3a3QK7QAGob8VghbJguw==", "subType": "04"}}}} - 13:21:29.244 [main] DEBUG org.mongodb.driver.protocol.command - Command "find" succeeded on database "test" in 8.823416 ms using a connection with driver-generated ID 3 and server-generated ID 516757 to localhost:27017. The request ID is 5 and the operation ID is 5. Command reply: {"cursor": {"firstBatch": [{"_id": {"$oid": "6876d15f70164c1e5a47be02"}, "advance": "$clusterTime"}], "id": 0, "ns": "test.test"}, "ok": 1.0, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1753129287, "i": 1}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}, "operationTime": {"$timestamp": {"t": 1753129283, "i": 1}}} - 13:21:29.249 [main] DEBUG org.mongodb.driver.operation - Received batch of 1 documents with cursorId 0 from server localhost:27017 - - .. tabs:: + 317 [main] INFO org.mongodb.driver.client - MongoClient with metadata {"driver": {"name": "", "version": ""}, "os": {"type": "", "name": "", "architecture": "", "version": ""}, "platform": ""} created with settings + 345 [cluster-ClusterId{value='', description='null'}-] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=, type=, cryptd=false, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=, minRoundTripTimeNanos=", "version": ""}, "os": {"type": "", "name": "", "architecture": "", "version": ""}, "platform": ""} created with settings + 21:19:25.710 [cluster-ClusterId{value='', description='null'}-] INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=, type=, cryptd=false, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=, minRoundTripTimeNanos= - + @@ -350,8 +345,13 @@ Select the :guilabel:`Logback` or :guilabel:`Log4j2` tab to see the correspondin :copyable: false ... - 829 [cluster-rtt-ClusterId{value='', description='null'}-] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:2, serverValue:}] to - 977 [main] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:}] to + 255 [main] DEBUG org.mongodb.driver.connection - Connection pool created for using options + 301 [cluster-ClusterId{value='', description='null'}-] DEBUG org.mongodb.driver.connection - Connection pool ready for + 321 [main] DEBUG org.mongodb.driver.connection - Checkout started for connection to + 323 [main] DEBUG org.mongodb.driver.connection - Connection created: address=, driver-generated ID=3 + 335 [main] DEBUG org.mongodb.driver.connection - Connection ready: address=, driver-generated ID=3, established in= ms + 336 [main] DEBUG org.mongodb.driver.connection - Connection checked out: address=, driver-generated ID=3, duration= ms + 363 [main] DEBUG org.mongodb.driver.connection - Connection checked in: address=, driver-generated ID=3 .. tab:: Log4j2 :tabid: Log4j2-binding @@ -369,7 +369,7 @@ Select the :guilabel:`Logback` or :guilabel:`Log4j2` tab to see the correspondin - + @@ -387,8 +387,13 @@ Select the :guilabel:`Logback` or :guilabel:`Log4j2` tab to see the correspondin :copyable: false ... - 15:40:23.005 [cluster-ClusterId{value='', description='null'}-] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:3, serverValue:}] to - 15:40:23.159 [main] INFO org.mongodb.driver.connection - Opened connection [connectionId{localValue:7, serverValue:}] to + 21:27:17.035 [main] DEBUG org.mongodb.driver.connection - Connection pool created for using options + 21:27:17.058 [cluster-ClusterId{value='', description='null'}-] DEBUG org.mongodb.driver.connection - Connection pool ready for + 21:27:17.064 [main] DEBUG org.mongodb.driver.connection - Checkout started for connection to + 21:27:17.069 [main] DEBUG org.mongodb.driver.connection - Connection created: address=, driver-generated ID=3 + 21:27:17.075 [main] DEBUG org.mongodb.driver.connection - Connection ready: address=, driver-generated ID=3, established in= ms + 21:27:17.075 [main] DEBUG org.mongodb.driver.connection - Connection checked out: address=, driver-generated ID=3, duration= ms + 21:27:17.086 [main] DEBUG org.mongodb.driver.connection - Connection checked in: address=, driver-generated ID=3 Additional Information ----------------------