Docs Menu
Docs Home
/
MongoDB Cluster-to-Cluster Sync
/

Logging

On this page

  • Destination
  • Standard Output
  • Log to File
  • Verbosity
  • Format
  • Examples

mongosync maintains a running log of events, including entries such as the copying collections and indexes, change stream events, and API calls.

mongosync can write log messages to stdout or to file.

By default, mongosync outputs log messages to stdout:

$ mongosync --config /etc/mongosync.conf

Example output:

{"level":"info","mongosyncID":"shard02","verbosity":"INFO","id":"shard02","port":27301,"time":"2022-06-21T11:15:33-04:00","message":"Mongosync Options"}
{"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."}
{"level":"info","mongosyncID":"shard02","time":"2022-06-21T11:15:33-04:00","message":"Preflight checks completed."}
{"level":"info","mongosyncID":"shard02","time":"2022-06-21T11:15:33-04:00","message":"Launch replication thread"}

To output log messages to file, start mongosync with the --logPath option or set the logPath setting in the configuration file.

When logging to file, mongosync writes logs to a file in the configured directory. The directory is created if it does not exist. If a mongosync.log file already exists in the directory, mongosync rotates the log files to preserve the old logs as it begins a new file.

$ ls /var/log/mongosync

For example:

mongosync-2022-06-17T16-27-58.187.log mongosync.log
mongosync-2022-06-21T13-31-42.668.log

The currently active log file is mongosync.log. The other files are older logs that mongosync has rotated.

If you start mongosync with the --logPath option, you can send a USR1 signal to the mongosync process to rotate its log file:

kill -s USR1 $mongosync_pid

$mongosync_pid is the mongosync process ID.

mongosync supports user-defined verbosity to increase or decrease the level of log messages mongosync outputs.

The verbosity level can be set using the --verbosity option from the command-line or the verbosity setting in the configuration file.

mongosync outputs log messages in structured JSON format. Each log message is a document that holds the key-value pairs for that entry. The keys label the log message elements, the values are the reported events.

For example:

{
"level": "info",
"mongosyncID": "shard01",
"componentName": "Change Event Application",
"time": "2022-06-21T09:31:42-04:00",
"message": "Starting change stream reader."
}

To view log messages, check the mongosync.log file in the log directory. You can format the log by piping its contents to jq or a similar command:

$ cat /var/log/mongosync/mongosync.log | jq

Example output:

{
"level": "info",
"mongosyncID": "shard02",
"verbosity": "INFO",
"id": "shard02",
"port":27301,
"time": "2022-06-21T11:15:33-04:00",
"message": "Mongosync Options"
}
{
"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."
}
{
"level": "info",
"mongosyncID": "shard02",
"time": "2022-06-21T11:15:33-04:00",
"message": "Preflight checks completed."
}
{
"level": "info",
"mongosyncID": "shard02",
"time": "2022-06-21T11:15:33-04:00",
"message": "Launch replication thread"
}

Back

Limitations