Skip to content

Commit 59c5334

Browse files
DOCSP-47888-custom-log-location (#379)
* DOCSP-47888-custom-log-location * WIP * first draft * wording * wording * add on this page * wording * use iocodeblock * retry build * test staging * remove TEST * add link * use tip * remove test * add info for log file prefixes
1 parent b13f2e4 commit 59c5334

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

source/includes/list-table-shell-properties.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
to ``Infinity`` (the javascript object) prints all nested
5454
objects to their full depth.
5555

56+
* - ``logLocation``
57+
- string
58+
- Depends on your operating system. See :ref:`mdb-shell-view-logs`.
59+
- Directory where MongoDB Shell writes log files. Specify an
60+
absolute filepath. See :ref:`mongosh-log-location`.
61+
5662
* - ``redactHistory``
5763
- string
5864
- ``remove``

source/logs.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ View |mdb-shell| Logs
3030

3131
.. include:: /includes/steps/view-logs.rst
3232

33+
.. tip::
34+
35+
To change where MongoDB Shell writes logs, see
36+
:ref:`mongosh-log-location`.
37+
3338
.. _mdb-shell-command-history:
3439

3540
View |mdb-shell| Command History
@@ -64,4 +69,5 @@ automatically deletes log files older than 30 days.
6469
.. toctree::
6570
:titlesonly:
6671

72+
Specify Log Location <logs/location>
6773
Write Custom Log Entries <logs/custom-entries>

source/logs/location.txt

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
.. _mongosh-log-location:
2+
3+
=========================
4+
Specify Log File Location
5+
=========================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
You can specify where MongoDB Shell writes log files. By default,
14+
MongoDB Shell saves the log for each session to your user's
15+
``.mongodb/mongosh`` directory, which depends on your operating system:
16+
17+
.. list-table::
18+
:header-rows: 1
19+
20+
* - Operating System
21+
- Default Log Location
22+
* - macOS and Linux
23+
- ``~/.mongodb/mongosh/<LogID>_log``
24+
* - Windows
25+
- ``%UserProfile%/AppData/Local/mongodb/mongosh/<LogID>_log``
26+
27+
About this Task
28+
---------------
29+
30+
To view the current log file location, use the :ref:`config API
31+
<configure-settings-api>` to return the ``logLocation`` value:
32+
33+
.. code-block:: javascript
34+
35+
config.get("logLocation")
36+
37+
After you modify your log file location, your current MongoDB Shell
38+
session continues to use the previous log file location. Sessions that
39+
start after you change the log file location use the updated location.
40+
41+
Log File Names
42+
~~~~~~~~~~~~~~
43+
44+
If you modify the default log file location, log files have a
45+
``mongosh_`` prefix before the session ID. For example, the log for
46+
session ID ``67be0c0eb6227e211a1979e8`` is saved as
47+
``mongosh_67be0c0eb6227e211a1979e8_log``.
48+
49+
If you use the default log file location, the file name does not include
50+
the ``mongosh_`` prefix. For example, the log for session ID
51+
``67be0c0eb6227e211a1979e8`` is saved as
52+
``67be0c0eb6227e211a1979e8_log``.
53+
54+
Steps
55+
-----
56+
57+
To change the log file location, modify the ``logLocation``
58+
configuration option. You can modify configuration options with the
59+
configuration API or a configuration file.
60+
61+
.. important::
62+
63+
Specify ``logLocation`` as an absolute filepath.
64+
65+
Modify Log Location with the API
66+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67+
68+
The following command uses the config API to set the ``logLocation``
69+
setting to ``/path/to/log/directory``:
70+
71+
.. io-code-block::
72+
:copyable: true
73+
74+
.. input::
75+
:language: javascript
76+
77+
config.set("logLocation", "/path/to/log/directory")
78+
79+
.. output::
80+
:language: javascript
81+
82+
Setting "logLocation" has been changed
83+
84+
Modify Log Location with a Configuration File
85+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86+
87+
The following :ref:`configuration file <configure-settings-global>` sets
88+
the ``logLocation`` setting to ``/path/to/log/directory``:
89+
90+
.. code-block:: yaml
91+
92+
mongosh:
93+
logLocation: "/path/to/log/directory"

0 commit comments

Comments
 (0)