Skip to content

Commit aac9398

Browse files
authored
Docsp 27636: Add maxDocumentLength (#375)
* DOCSP-27636: Adding new logging settings options. * Added Logger section * Added code example * PR feedback * Missed a label correction. * Final PR feedback touches
1 parent 8e141fb commit aac9398

File tree

2 files changed

+114
-59
lines changed

2 files changed

+114
-59
lines changed

source/fundamentals/connection/mongoclientsettings.txt

Lines changed: 98 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ To create a ``MongoClientSettings`` object, use the
4242
settings. After chaining them, use the ``build()`` method to create the
4343
``MongoClientSettings`` object.
4444

45-
The following table describes all the methods you can chain to modify your
45+
The following table describes the methods you can chain to modify your
4646
connection behavior:
4747

4848
.. list-table::
@@ -71,6 +71,10 @@ connection behavior:
7171
- Applies the ``ConnectionPoolSettings.Builder`` block and then sets the
7272
:ref:`connection pool settings <mcs-connectionpool-settings>`.
7373

74+
* - ``applyToLoggerSettings()``
75+
- Applies the ``LoggerSettings.Builder`` block and then sets the
76+
:ref:`logger settings <mcs-logger-settings>`.
77+
7478
* - ``applyToServerSettings()``
7579
- Applies the ``ServerSettings.Builder`` block and then sets the
7680
:ref:`server settings <mcs-server-settings>`.
@@ -201,7 +205,7 @@ Chain the `applyToClusterSettings() <{+api+}/apidocs/mongodb-driver-core/com/mon
201205
method to modify the driver's behavior when interacting with your
202206
MongoDB cluster.
203207

204-
The following table describes all the methods you can chain to your
208+
The following table describes the methods you can chain to your
205209
settings to modify the driver's behavior:
206210

207211
.. list-table::
@@ -289,60 +293,6 @@ regardless of the type of MongoDB cluster its' a part of:
289293
in your connection URI. See :ref:`<connection-options>` for more
290294
information.
291295

292-
.. _mcs-socket-settings:
293-
294-
Socket Settings
295-
---------------
296-
297-
Chain the `applyToSocketSettings() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html#applyToSocketSettings(com.mongodb.Block)>`__
298-
method to modify the driver's behavior when connecting and communicating
299-
with your MongoDB server.
300-
301-
The following table describes all the methods you can chain to your settings
302-
to modify the driver's behavior:
303-
304-
.. list-table::
305-
:widths: 40 60
306-
:header-rows: 1
307-
308-
* - Method
309-
- Description
310-
311-
* - ``applyConnectionString()``
312-
- Uses the settings from a ``ConnectionString`` object.
313-
314-
* - ``applySettings()``
315-
- Uses the socket settings specified in a ``SocketSettings`` object.
316-
317-
* - ``connectTimeout()``
318-
- Sets the maximum time to connect to an available socket before throwing
319-
a timeout exception.
320-
321-
* - ``readTimeout()``
322-
- Sets the maximum time to read to an available socket before throwing a
323-
timeout exception.
324-
325-
* - ``receiveBufferSize()``
326-
- Sets the socket's buffer size when receiving.
327-
328-
* - ``sendBufferSize()``
329-
- Sets the socket's buffer size when sending.
330-
331-
Example
332-
~~~~~~~
333-
334-
This example specifies the following driver behavior in a MongoDB socket:
335-
336-
- To connect to an available socket within ``10 SECONDS``
337-
- To read from an available socket within ``15 SECONDS``
338-
339-
.. literalinclude:: /includes/fundamentals/code-snippets/mcs.java
340-
:start-after: begin SocketSettings
341-
:end-before: end SocketSettings
342-
:language: java
343-
:emphasize-lines: 3-5
344-
:dedent:
345-
346296
.. _mcs-connectionpool-settings:
347297

348298
Connection Pool Settings
@@ -351,7 +301,7 @@ Connection Pool Settings
351301
Chain the `applyToConnectionPoolSettings() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html#applyToConnectionPoolSettings(com.mongodb.Block)>`__
352302
method to modify the way the driver manages its connection pool.
353303

354-
The following table describes all the methods you can chain to your
304+
The following table describes the methods you can chain to your
355305
settings to modify the driver's behavior:
356306

357307
.. list-table::
@@ -421,6 +371,41 @@ This example specifies the following driver behavior in a pool of
421371
:emphasize-lines: 3-5
422372
:dedent:
423373

374+
.. _mcs-logger-settings:
375+
376+
Logger Settings
377+
---------------
378+
379+
Chain the `applyToLoggerSettings() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html#applyToLoggerSettings(com.mongodb.Block)>`__
380+
method to modify the logging behavior of the driver.
381+
382+
The following table describes the methods you can chain to your
383+
settings to modify the logging behavior:
384+
385+
.. list-table::
386+
:widths: 40 60
387+
:header-rows: 1
388+
389+
* - Method
390+
- Description
391+
392+
* - ``maxDocumentLength()``
393+
- Sets the maximum document length, in characters, of a single log
394+
message.
395+
396+
Example
397+
~~~~~~~
398+
399+
This example specifies that the maximum number of characters for a single log
400+
message is set to ``5000`` characters.
401+
402+
.. literalinclude:: /includes/fundamentals/code-snippets/mcs.java
403+
:start-after: begin LoggerSettings
404+
:end-before: end LoggerSettings
405+
:language: java
406+
:emphasize-lines: 3-4
407+
:dedent:
408+
424409
.. _mcs-server-settings:
425410

426411
Server Settings
@@ -430,7 +415,7 @@ Chain the `applyToServerSettings() <{+api+}/apidocs/mongodb-driver-core/com/mong
430415
method to modify the driver's behavior when monitoring each MongoDB
431416
server.
432417

433-
The following table describes all the methods you can chain to your
418+
The following table describes the methods you can chain to your
434419
settings to modify the driver's behavior:
435420

436421
.. list-table::
@@ -474,6 +459,60 @@ This example specifies the following driver behavior in a MongoDB server:
474459
:emphasize-lines: 3-5
475460
:dedent:
476461

462+
.. _mcs-socket-settings:
463+
464+
Socket Settings
465+
---------------
466+
467+
Chain the `applyToSocketSettings() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html#applyToSocketSettings(com.mongodb.Block)>`__
468+
method to modify the driver's behavior when connecting and communicating
469+
with your MongoDB server.
470+
471+
The following table describes the methods you can chain to your settings
472+
to modify the driver's behavior:
473+
474+
.. list-table::
475+
:widths: 40 60
476+
:header-rows: 1
477+
478+
* - Method
479+
- Description
480+
481+
* - ``applyConnectionString()``
482+
- Uses the settings from a ``ConnectionString`` object.
483+
484+
* - ``applySettings()``
485+
- Uses the socket settings specified in a ``SocketSettings`` object.
486+
487+
* - ``connectTimeout()``
488+
- Sets the maximum time to connect to an available socket before throwing
489+
a timeout exception.
490+
491+
* - ``readTimeout()``
492+
- Sets the maximum time to read to an available socket before throwing a
493+
timeout exception.
494+
495+
* - ``receiveBufferSize()``
496+
- Sets the socket's buffer size when receiving.
497+
498+
* - ``sendBufferSize()``
499+
- Sets the socket's buffer size when sending.
500+
501+
Example
502+
~~~~~~~
503+
504+
This example specifies the following driver behavior in a MongoDB socket:
505+
506+
- To connect to an available socket within ``10 SECONDS``
507+
- To read from an available socket within ``15 SECONDS``
508+
509+
.. literalinclude:: /includes/fundamentals/code-snippets/mcs.java
510+
:start-after: begin SocketSettings
511+
:end-before: end SocketSettings
512+
:language: java
513+
:emphasize-lines: 3-5
514+
:dedent:
515+
477516
.. _mcs-ssl-settings:
478517

479518
TLS/SSL Settings
@@ -483,7 +522,7 @@ Chain the `applyToSslSettings() <{+api+}/apidocs/mongodb-driver-core/com/mongodb
483522
method to modify the driver's behavior when using TLS/SSL to secure a
484523
connection between your application and MongoDB.
485524

486-
The following table describes all the methods you can chain to your
525+
The following table describes the methods you can chain to your
487526
settings to modify the driver's behavior:
488527

489528
.. list-table::

source/includes/fundamentals/code-snippets/mcs.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,20 @@ private static void createSslSettings() {
134134
System.out.print("---------------------------------------");
135135
}
136136
}
137+
138+
private static void createLoggerSettings() {
139+
try {
140+
////begin LoggerSettings
141+
MongoClient mongoClient = MongoClients.create(
142+
MongoClientSettings.builder().applyConnectionString(new ConnectionString("<your connection string>"))
143+
.applyToLoggerSettings(builder ->
144+
builder.maxDocumentLength(5_000))
145+
.build());
146+
//end LoggerSettings
147+
mongoClient.listDatabaseNames().forEach(n -> System.out.println(n));
148+
mongoClient.close();
149+
} finally {
150+
System.out.print("---------------------------------------");
151+
}
152+
}
137153
}

0 commit comments

Comments
 (0)