How to show query log ?

36 views
Skip to first unread message

Thanh Trần Văn

unread,
Feb 5, 2015, 5:31:56 AM2/5/15
to mgo-...@googlegroups.com
Hi Team,

I want show log query when execute, but i don't know how to do.

Example:
type Person struct { Name string Phone string }

c := session.DB("test").C("people")
c.Insert(
    &Person{"Ale", "+55 53 8116 9639"},
    &Person{"Cla", "+55 53 8402 8510"},
)

When run go, console will print:
db.people.insert([{name: "Ale", "phone": "+55 53 8116 9639"},{name: "Cla", "phone": "+55 53 8402 8510"}])

Please help me

Thank you very much !

Gustavo Niemeyer

unread,
Feb 9, 2015, 11:34:03 AM2/9/15
to mgo-...@googlegroups.com, Thanh Trần Văn
There are two ways you can handle this issue:

1. 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/

2. 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
> --
> You received this message because you are subscribed to the Google Groups
> "mgo-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mgo-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

gustavo @ http://niemeyer.net
Reply all
Reply to author
Forward
0 new messages