Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Finally, fix logging format #318

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Finally, fix logging format #318

wants to merge 11 commits into from

Conversation

y8
Copy link

@y8 y8 commented Sep 20, 2014

Sorry, I'm kinda late for 2.0 release, but still.

Before this pull request, when you copy & paste stuff from logs it was like:

mongo>  {"$query"=>{:likes=>{"$exists"=>false}}, "$explain"=>true, "$orderby"=>{:_id=>1}, "$maxScan"=>10} flags=[] limit=0 skip=0 batch_size=nil fields=nil
SyntaxError: Unexpected token >

 (ノಥ益ಥ)ノ ┻━┻

After this pull request and after Moped.log_format = Moped::LogFormat::ShellFormat it is like:

mongo> db.users.find({"likes":{"$exists":false}})._addSpecial({"$maxScan":1}).explain(true)
{
    "cursor" : "BasicCursor",
    "isMultiKey" : false,
    "n" : 1109994,
    "nscannedObjects" : 1109994,
    "nscanned" : 1109994,
    "nscannedObjectsAllPlans" : 1109994,
    "nscannedAllPlans" : 1109994,
    "scanAndOrder" : false,
    "indexOnly" : false,
    "nYields" : 8671,
    "nChunkSkips" : 0,
    "millis" : 5979,
    "allPlans" : [
        {
            "cursor" : "BasicCursor",
            "isMultiKey" : false,
            "n" : 1109994,
            "nscannedObjects" : 1109994,
            "nscanned" : 1109994,
            "scanAndOrder" : false,
            "indexOnly" : false,
            "nChunkSkips" : 0
        }
    ],
    "server" : "yopp-air:27017",
    "filterSet" : false,
    "stats" : {
        "type" : "COLLSCAN",
        "works" : 1109996,
        "yields" : 8671,
        "unyields" : 8671,
        "invalidates" : 0,
        "advanced" : 1109994,
        "needTime" : 1,
        "needFetch" : 0,
        "isEOF" : 1,
        "docsTested" : 1109994,
        "children" : [ ]
    }
}
ヽ(^。^)ノ

Give it a try rake MOPED_LOG_FORMAT=shell MOPED_PRINT_LOG=1

Few notes:

  1. It's backward compatible: useless DefaultFormat is default!
  2. Now in technicolor!
  3. Be creative, make your own log formatter without dirty patching!
  4. ShellFormat is not fully tested. It might produce something incompatible in some cases. Feedback is very welcome.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.11%) when pulling 5ceef14 on y8:master into 2d92a6b on mongoid:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.75%) when pulling 13e87d8 on y8:master into 2d92a6b on mongoid:master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants