Profiling level history/audit log

when setProfilingLevel is executed it returns something like

{
   "was" : 2,
   "slowms" : 100,
   "sampleRate" : 1,
   "filter" : {
      "$and" : [
         {
            "op" : {
               "$eq" : "query"
            }
         },
         {
            "millis" : {
               "$gt" : 20000
            }
         }
      ]
   },
   "note" : "When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines.",
   "ok" : 1
}

If you clear the terminal or forgot to check the value of was how can you revert to the previous value?

Is there some sort of history for Profiling Level?

To see when it changed and from what value?

Hi @zikohh,

Changes to profiling level are also noted in the log file.

For example:

> db.setProfilingLevel(1)
{ was: 0, slowms: 100, sampleRate: 1, ok: 1 }

… has a corresponding log entry:

{“t”:{"$date":“2022-04-13T15:32:04.728+10:00”},“s”:“I”, “c”:“COMMAND”, “id”:48742, “ctx”:“conn1”,“msg”:“Profiler settings changed”,“attr”:{“from”:{“level”:0,“slowms”:100,“sampleRate”:1},“to”:{“level”:1,“slowms”:100,“sampleRate”:1}}}

… which is more readable if you format the JSON log entry:

{
  "t": {
    "$date": "2022-04-13T15:32:04.728+10:00"
  },
  "s": "I",
  "c": "COMMAND",
  "id": 48742,
  "ctx": "conn1",
  "msg": "Profiler settings changed",
  "attr": {
    "from": {
      "level": 0,
      "slowms": 100,
      "sampleRate": 1
    },
    "to": {
      "level": 1,
      "slowms": 100,
      "sampleRate": 1
    }
  }
}

Regards,
Stennie

Hi @Stennie thanks for your response.

How can I retrieve it’s corresponding log entry? Is this in the system.profile collection?

Found it using
db.serverCmdLineOpts()

Then visit the file at the systemLog node