|
| 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