Search code examples
mongodblogging

MongoDB logging all queries


The question is as basic as it is simple... How do you log all queries in a "tail"able log file in mongodb?

I have tried:

  • setting the profiling level
  • setting the slow ms parameter starting
  • mongod with the -vv option

The /var/log/mongodb/mongodb.log keeps showing just the current number of active connections...


Solution

  • I ended up solving this by starting mongod like this (hammered and ugly, yeah... but works for development environment):

    mongod --profile=1 --slowms=1 &
    

    This enables profiling and sets the threshold for "slow queries" as 1ms, causing all queries to be logged as "slow queries" to the file:

    /var/log/mongodb/mongodb.log
    

    Now I get continuous log outputs using the command:

    tail -f /var/log/mongodb/mongodb.log
    

    An example log:

    Mon Mar  4 15:02:55 [conn1] query dendro.quads query: { graph: "u:http://example.org/people" } ntoreturn:0 ntoskip:0 nscanned:6 keyUpdates:0 locks(micros) r:73163 nreturned:6 reslen:9884 88ms