Search code examples
javamongodbspring-data-mongodb

MongoDB: How to log all queries to log file on Windows


This Questions could not help me: MongoDB logging all queries

Here is my configuration file:

dbpath  = C:\mongodb\data
logpath = C:\mongodb\mongo.log
diaglog = 3                      
profile = 2
slowms  = 1

but my log file contains no queries. What I'm doing wrong?

P.S: I'm using mongodb version v3.2.3


Solution

  • You have two options to increase your log verbosity.

    1. Increase your log verbosity in configuration file. systemLog.component.query.verbosity = 4 see systemLog.component.query.verbosity documentation

    2. db.setLogLevel(...) see setLogLevel documentation.

    your final config file should look like

    storage:
       dbPath: "C:\mongodb\data"
    
    systemLog:
       destination: file
       path: "C:\mongodb\mongo.log"
       component:
           query:
               verbosity: 2
    
    operationProfiling:
        slowOpThresholdMs: 100
        mode: slowOp