Video Transcript (English)
In this video, you will learn how to access, download, and read logs by using MongoDB Atlas UI and CLI tools.
MongoDB maintains a running log of events, including entries such as incoming connections, commands run, and issues encountered.
We can use log messages to diagnose issues such as slow queries, to help with tuning performance, and to monitor deployments.
Something to keep in mind is that free and shared clusters do not provide downloadable logs.
We’ll go through this process by using a dedicated M20 cluster in the Atlas UI.
To download logs, we click here, under Database Deployments.
Let’s select the primary server and set the time period as the past 24 hours. Success!
To download the logs by using the Atlas CLI, we can run the `atlas logs download` command.
In the command, we specify the hostname, the file format, and additional parameters or flags, such as changing the default time range of log messages to retrieve.
MongoDB logs are output in structured JSON format.
This means that log entries are written as a series of key-value pairs. Each key indicates a log message field type, and each corresponding value records the associated logging information for that field type.
Let’s examine a sample log message to learn more about structured JSON format.
First, we have the timestamp, which tells us when the event was logged.
Next, `s` represents the severity level of the message. The three most severe levels are Fatal, Error, and Warning, which indicate that something is wrong. The severity level here is I, for informational. Informational entries will only be displayed when the log verbosity is set to 0.
`c` is the full component string for the log message, which indicates the category of the logged event. In this case, the category is COMMAND, which means that this entry is related to a database command.
`id` is the unique identifier for each type of log statement.
`ctx` tells us the name of the thread that caused the log message.
And `msg` is the log output message that’s passed from the server or driver. In this case, the message is “Slow query”.
The next section, attributes, provides more information about the slow query.
The output for this section can be long, so we’re viewing only a few attributes.
The attribute section contains details about the query command.
Next, the planSummary is listed as a collection scan, and the total number of documents that were examined is 1,000,001. Based on this information, we should consider building an index to support this query.
Here is a full list of key-value pairs that you might see in a log message. Log messages include only necessary keys. So, if there are no associated `tags` for a log message, that key will not be included.
Let’s recap what you learned about log messages in MongoDB: MongoDB maintains a running log of events that we can use to diagnose issues, tune performance, and monitor deployments. Log messages are output in structured JSON format, a series of key-value pairs that contain information about each log event. We can access logs for a dedicated cluster by using the Atlas UI or the Atlas CLI. When using the CLI, we need to run the `atlas download logs` command.