You can send your MongoDB logs to Loggly. We will automatically parse fields like timestamp and module from the MongoDB log as well. This script configures the rsyslog daemon to monitor the log file for the newest events, and then sends them to Loggly. For alternatives, please see the Advanced Options section.
MongoDB Logging Setup
1. Setup File Monitoring for MongoDB
Use our automated script to setup file monitoring for the MongoDB log file, or manually configure file monitoring with rsyslog. Setup file monitoring for mongod.log file. This examples assumes Ubuntu. For RHEL and CentOS the file is /var/log/mongod.log.
curl -O https://www.loggly.com/install/configure-file-monitoring.sh sudo bash configure-file-monitoring.sh -a SUBDOMAIN -u USERNAME -f /var/log/mongodb/mongod.log -l mongodb -tag MongoDB
- SUBDOMAIN: your account subdomain that you created when you signed up for Loggly
- USERNAME: your Loggly username
2. Verify Events
Search Loggly for events with the tag MongoDB over the past hour. It may take few minutes to index the event. If if doesn’t work, see the troubleshooting section below.
Click on one of the logs to show a list of mongo fields (see screenshot below). If you don’t see them, please check that you are using one of our automatically parsed formats.
Advanced MongoDB Logging Options
- MongoDB Automated Parsing – the lines we parse from the MongoDB logs
- Log File Monitoring – how to setup file monitoring on any file
- Log Rotation – if you use log rotation, you must add commands to refresh the files
- RHEL and CentOS – the default file location is /var/log/mongod.log
Troubleshooting MongoDB Logs
If you don’t see any data show up in the verification step, then check for these common problems.
- Wait a few minutes in case indexing needs to catch up
- Check if mongodb log file exists on the path you included in the arguments and there are recent logs in it
- Troubleshooting Rsyslog if the files are being written but not being sent to Loggly
- Search or post your own MongoDB logging questions in the community forum.