How to log every query with mgo in standard output? I set logger but it shows a lot of information without actual queries.
An answer from Gustavo Niemeyer, author of mgo : http://grokbase.com/t/gg/mgo-users/152571ky82/how-to-show-query-log#20150209zwzki7mxjfigdzuqp245wskkl4
There are two ways you can handle this issue:
By enabling MongoDB logging
This is independent from the driver (mgo in this case), and can be enabled in the shell or by running the respective command via mgo:
http://docs.mongodb.org/manual/reference/method/db.setProfilingLevel/
By enabling mgo logging
You can do this by creating a Logger via the standard package's log.New function and providing it to mgo's SetLogger function:
http://golang.org/pkg/log/#New, http://gopkg.in/mgo.v2#SetLogger
Use mgo.SetDebug to increase the verbosity:
http://gopkg.in/mgo.v2#SetDebug
So if you already have the Logger set, enable the debug mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With