Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB: log mongod to stdout

Tags:

mongodb

I have been running MongoDB on my home laptop for awhile now. running mongod outputs to stdout as it should. super...

I just installed it on my work laptop but it is logging to a file.

$ sudo mongod
all output going to: /usr/local/var/log/mongodb/mongo.log

MongoDB should by default be logging to stdout according to the docs. This installation of mongoDB was done via home brew. Why is mongod logging to a file, and how do i get it to log to stdout instead?

like image 786
brewster Avatar asked Nov 22 '12 05:11

brewster


People also ask

How do I access MongoDB logs?

MongoDB logs can be found in the MongoDB log files at /var/log/mongodb/mongodb. log. If you can't find the log files from this location, you can check the mongodb.

How do I log errors in MongoDB?

Let's take a look at the latest format for MongoDB errors which you can find by looking at your MongoDB log file which is commonly located at /var/log/mongodb/mongodb. log . If the file's not there, you'll need to find your mongodb. conf file which specifies where your log file lives.

How do I rotate a log in MongoDB?

When reporting activity data to a log file, by default, MongoDB only rotates logs in response to the logRotate command, or when the mongod or mongos process receives a SIGUSR1 signal from the operating system. Both server logs and audit logs may be rotated with the logRotate command, either together or independently.

How do I change the log level in MongoDB?

Use the db. setLogLevel(<level>, <component>) method to update a single component log level. For a component, you can specify verbosity level of 0 to 5 , or you can specify -1 to inherit the verbosity of the parent.


Video Answer


1 Answers

If you run cat `which mongod` you can see that the Ruby wrapper around the mongod binary appends the default config if the --config arguments isn't passed.

ARGV << '--config' << '/usr/local/etc/mongod.conf' unless ARGV.find { |arg| arg =~ /--config/ }
exec "/usr/local/Cellar/mongodb/2.2.3-x86_64/mongod", *ARGV

The default config contains the following

# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb

# Append logs to /usr/local/var/log/mongodb/mongo.log
logpath = /usr/local/var/log/mongodb/mongo.log
logappend = true

# Only accept local connections
bind_ip = 127.0.0.1

as you can see both logappend and logpath is set. The logpath setting is normally None meaning /dev/stdout.

To the point. mongod --config false will output to STDOUT. That will run the mongod binary without a config. If that isn't ideal, change the config settings in /usr/local/etc/mongod.conf.

like image 57
Kevin Sjöberg Avatar answered Sep 26 '22 09:09

Kevin Sjöberg