|
| 1 | +.. _c2c-logging: |
| 2 | + |
| 3 | +======= |
| 4 | +Logging |
| 5 | +======= |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +:program:`mongosync` maintains a running log of events, including entries |
| 10 | +such as the copying collections and indexes, change stream events, and API |
| 11 | +calls. |
| 12 | + |
| 13 | +.. contents:: On this page |
| 14 | + :local: |
| 15 | + :backlinks: none |
| 16 | + :depth: 2 |
| 17 | + :class: singlecol |
| 18 | + |
| 19 | + |
| 20 | +Destination |
| 21 | +----------- |
| 22 | + |
| 23 | +:program:`mongosync` can write log messages to stdout or to file. |
| 24 | + |
| 25 | +Standard Output |
| 26 | +^^^^^^^^^^^^^^^ |
| 27 | + |
| 28 | +By default, ``mongosync`` outputs log messages to stdout: |
| 29 | + |
| 30 | +.. code-block:: console |
| 31 | + |
| 32 | + $ mongosync --config /etc/mongosync.conf |
| 33 | + |
| 34 | +Example output: |
| 35 | + |
| 36 | +.. code-block:: json |
| 37 | + :copyable: false |
| 38 | + |
| 39 | + {"level":"info","mongosyncID":"shard02","verbosity":"INFO","id":"shard02","port":27301,"time":"2022-06-21T11:15:33-04:00","message":"Mongosync Options"} |
| 40 | + {"level":"info","mongosyncID":"shard02","time":"2022-06-21T11:15:33-04:00","message":"Initialized client0 with URI: mongodb://192.0.2.1:27130 and client1 with URI: mongodb://192.0.2.2:27140."} |
| 41 | + {"level":"info","mongosyncID":"shard02","time":"2022-06-21T11:15:33-04:00","message":"Preflight checks completed."} |
| 42 | + {"level":"info","mongosyncID":"shard02","time":"2022-06-21T11:15:33-04:00","message":"Launch replication thread"} |
| 43 | + |
| 44 | +Log to File |
| 45 | +^^^^^^^^^^^ |
| 46 | + |
| 47 | +To output log messages to file, start ``mongosync`` with the |
| 48 | +:option:`--logPath` option or set the :setting:`logPath` setting |
| 49 | +in the configuration file. |
| 50 | + |
| 51 | +When logging to file, ``mongosync`` writes logs to a file in the configured |
| 52 | +directory. The directory is created if it does not exist. If a ``mongosync.log`` |
| 53 | +file already exists in the directory, ``mongosync`` rotates the log files to |
| 54 | +preserve the old logs as it begins a new file. |
| 55 | + |
| 56 | +.. code-block:: console |
| 57 | + |
| 58 | + $ ls /var/log/mongosync |
| 59 | + |
| 60 | +For example: |
| 61 | + |
| 62 | +.. code-block:: none |
| 63 | + :copyable: false |
| 64 | + |
| 65 | + mongosync-2022-06-17T16-27-58.187.log mongosync.log |
| 66 | + mongosync-2022-06-21T13-31-42.668.log |
| 67 | + |
| 68 | +The currently active log file is ``mongosync.log``. The other files are older |
| 69 | +logs that ``mongosync`` has rotated. |
| 70 | + |
| 71 | + |
| 72 | +Verbosity |
| 73 | +--------- |
| 74 | + |
| 75 | +:program:`mongosync` supports user-defined verbosity to increase or decrease |
| 76 | +the level of log messages ``mongosync`` outputs. |
| 77 | + |
| 78 | +The verbosity level can be set using the :option:`--verbosity` option from the |
| 79 | +command-line or the :setting:`verbosity` setting in the configuration file. |
| 80 | + |
| 81 | +Format |
| 82 | +------ |
| 83 | + |
| 84 | +:program:`mongosync` outputs log messages in structured JSON format. |
| 85 | +Each log message is a document that holds the key-value pairs for that entry. |
| 86 | +The keys label the log message elements, the values are the reported events. |
| 87 | + |
| 88 | +For example: |
| 89 | + |
| 90 | +.. code-block:: json |
| 91 | + :copyable: false |
| 92 | + |
| 93 | + { |
| 94 | + "level": "info", |
| 95 | + "mongosyncID": "shard01", |
| 96 | + "componentName": "Change Event Application", |
| 97 | + "time": "2022-06-21T09:31:42-04:00", |
| 98 | + "message": "Starting change stream reader." |
| 99 | + } |
| 100 | + |
| 101 | +Examples |
| 102 | +-------- |
| 103 | + |
| 104 | +To view log messages, check the ``mongosync.log`` file in the log directory. |
| 105 | +You can format the log by piping its contents to ``jq`` or a similar command: |
| 106 | + |
| 107 | +.. code-block:: console |
| 108 | + |
| 109 | + $ cat /var/log/mongosync/mongosync.log | jq |
| 110 | + |
| 111 | +Example output: |
| 112 | + |
| 113 | +.. code-block:: json |
| 114 | + :copyable: false |
| 115 | + |
| 116 | + { |
| 117 | + "level": "info", |
| 118 | + "mongosyncID": "shard02", |
| 119 | + "verbosity": "INFO", |
| 120 | + "id": "shard02", |
| 121 | + "port":27301, |
| 122 | + "time": "2022-06-21T11:15:33-04:00", |
| 123 | + "message": "Mongosync Options" |
| 124 | + } |
| 125 | + { |
| 126 | + "level": "info", |
| 127 | + "mongosyncID": "shard02", |
| 128 | + "time": "2022-06-21T11:15:33-04:00", |
| 129 | + "message": "Initialized client0 with URI: mongodb://192.0.2.1:27130 and client1 with URI: mongodb://192.0.2.2:27140." |
| 130 | + } |
| 131 | + { |
| 132 | + "level": "info", |
| 133 | + "mongosyncID": "shard02", |
| 134 | + "time": "2022-06-21T11:15:33-04:00", |
| 135 | + "message": "Preflight checks completed." |
| 136 | + } |
| 137 | + { |
| 138 | + "level": "info", |
| 139 | + "mongosyncID": "shard02", |
| 140 | + "time": "2022-06-21T11:15:33-04:00", |
| 141 | + "message": "Launch replication thread" |
| 142 | + } |
| 143 | + |
| 144 | + |
0 commit comments