MongoDB: log mongod to stdout

I already work MongoDB on my home laptop. launch mongod outputs on stdout as needed. super...

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

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

MongoDB should by default register with stdout according to the docs. This mongoDB installation was done through the brew home page. Why is mongod registered in the file, and how can I get it to register on stdout?

+6
source share
5 answers

If you run cat `which mongod` , you will see that the Ruby shell around the mongod binary adds the default configuration if --config arguments are not 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 configuration 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 . Typically, the logpath None option means /dev/stdout .

Exactly. mongod --config false will be output to STDOUT. This will launch the mongod binary without configuration. If this is not the case, change the configuration settings in /usr/local/etc/mongod.conf .

+10
source

Besides disabling file registration, as others suggested, you can also do the following:

 sudo mongod; tail -f /usr/local/var/log/mongodb/mongo.log 
+4
source

As the other answers said, it is likely that you have the "logpath" parameter made in the configuration file. If you don’t know where it is, you can find it by running mongod as:

 sudo su - strace -e open mongod 

This displays some information - each mongod file tries to open - in which you can find the configuration file. For me, it looked like this (in part):

 open("/proc/cpuinfo", O_RDONLY) = 3 open("/dev/urandom", O_RDONLY) = 3 open("/etc/mongodb.conf", O_RDONLY) = 4 all output going to: /var/log/mongodb/mongodb.log open("/var/log/mongodb/mongodb.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 4 open("/var/log/mongodb/mongodb.log", O_WRONLY|O_CREAT|O_APPEND, 0666) = 1 

After you find the file, comment out (C #) the line logpath = and your log should be displayed on stdout.

+1
source

from docs :

systemLog.destination Type: string

The destination to which MongoDB sends the entire output log entry. Specify either a file or syslog. If you specify a file, you must also specify systemLog.path.

If you do not specify systemLog.destination, MongoDB will send the entire output log to standard output.

+1
source

On my brew machine, the mongod.conf file was created in /usr/local/etc/ .

In addition, you should see something like this on line 7 (or so) of your /usr/local/var/log/mongodb/mongo.log log file:

 Tue Jan 8 10:14:25 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb" } 
0
source

All Articles