Skip to content

Commit a5703bc

Browse files
(DOCSP-10364): Document mongosh logging (#18)
* (DOCSP-10364): mongosh logging * (DOCSP-10364): try to fix some tabs * (DOCSP-10364): try to fix other tabs * (DOCSP-10364): formatting fixes * (DOCSP-10364): copy review feedback * (DOCSP-10364): tech review feedback
1 parent 35eca8a commit a5703bc

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

source/includes/steps-view-logs.yaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: "Find your Session ID."
3+
level: 4
4+
ref: session-id
5+
content: |
6+
7+
.. example::
8+
9+
|mdb-shell| displays the session ID each time you open the shell.
10+
11+
.. code-block:: javascript
12+
:copyable: false
13+
:emphasize-lines: 3
14+
15+
$ mongosh
16+
17+
Current sessionID: c2961dbd6b73b052671d9df0
18+
Connecting to: mongodb://127.0.0.1:27017
19+
Using MongoDB: 4.2.8
20+
Using Mongosh Beta: 0.0.6
21+
22+
---
23+
title: "View the log for the session."
24+
level: 4
25+
ref: view-session-log
26+
content: |
27+
28+
|mdb-shell| saves the log for each session to your user's
29+
``.mongodb/mongosh`` directory:
30+
31+
.. tabs::
32+
33+
.. tab::
34+
:tabid: macOS and Linux
35+
36+
.. code-block:: sh
37+
38+
~/.mongodb/mongosh/<sessionId>_log
39+
40+
Run the following command to view the log for a session:
41+
42+
.. code-block:: sh
43+
44+
cat ~/.mongodb/mongosh/<sessionId>_log
45+
46+
Run the following command to tail the log for a session:
47+
48+
.. code-block:: sh
49+
50+
tail -f ~/.mongodb/mongosh/<sessionId>_log
51+
52+
.. tip::
53+
54+
You can pipe the output to an installed ``ndjson`` pretty
55+
printer, such as `pino-colada
56+
<https://www.npmjs.com/package/pino-colada>`__
57+
or `pino-pretty <https://www.npmjs.com/package/pino-pretty>`__
58+
to improve readability:
59+
60+
.. code-block:: sh
61+
62+
tail -f ~/.mongodb/mongosh/<sessionId>_log | pino-colada
63+
64+
.. tab::
65+
:tabid: windows
66+
67+
.. code-block:: sh
68+
69+
%UserProfile%/.mongodb/mongosh/<sessionId>_log
70+
71+
Run the following PowerShell command to view the log for a session:
72+
73+
.. code-block:: sh
74+
75+
Get-Content %UserProfile%/.mongodb/mongosh/<sessionId>_log
76+
77+
Run the following PowerShell command to tail the log for a
78+
session:
79+
80+
.. code-block:: sh
81+
82+
Get-Content %UserProfile%/.mongodb/mongosh/<sessionId>_log -Wait
83+
84+
.. tip::
85+
86+
You can pipe the output to an installed ``ndjson`` pretty
87+
printer, such as `pino-colada
88+
<https://www.npmjs.com/package/pino-colada>`__
89+
or `pino-pretty <https://www.npmjs.com/package/pino-pretty>`__
90+
to improve readability:
91+
92+
.. code-block:: sh
93+
94+
Get-Content %UserProfile%/.mongodb/mongosh/<sessionId>_log -Wait | pino-colada
95+
96+
...

source/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@ Learn More
114114
/connect
115115
/crud
116116
/run-agg-pipelines
117+
/logs
117118
/reference

source/logs.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
.. _mdb-shell-logs:
2+
3+
===========================
4+
Retrieve MongoDB Shell Logs
5+
===========================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
.. include:: /includes/admonitions/fact-mdb-shell-beta.rst
16+
17+
|mdb-shell| stores logs for each session in `ndjson
18+
<http://ndjson.org/>`__ format using `pino
19+
<https://github.com/pinojs/pino>`__.
20+
21+
You can view or tail the logs for a |mdb-shell| session based on its
22+
session ID.
23+
24+
View |mdb-shell| Logs
25+
---------------------
26+
27+
.. include:: /includes/steps/view-logs.rst
28+
29+
View |mdb-shell| Command History
30+
--------------------------------
31+
32+
|mdb-shell| saves a history of all commands you've run across sessions.
33+
When a new command is issued, it is added to the beginning of the
34+
history file.
35+
36+
Open the following file in a text editor to view the |mdb-shell| command
37+
history:
38+
39+
.. list-table::
40+
:header-rows: 1
41+
:widths: 1 2
42+
43+
* - Operating System
44+
- Path to History File
45+
46+
* - macOS and Linux
47+
- ``~/.mongodb/mongosh/.mongosh_repl_history``
48+
49+
* - Windows
50+
- ``%UserProfile%/.mongodb/mongosh/.mongosh_repl_history``

0 commit comments

Comments
 (0)