javascriptcouchdb

CouchDB - How To Log or Capture Request Object?


Documentation indicates that one can log() a request object toJSON but it don't work.

I've configured info level logging on my Couch instance and crafted by _design document to do it and all I get back from "validate_doc_update": "function(doc, req){log(toJSON(req))}" is:

[info] 2023-07-07T21:53:02.138399Z nonode@nohost <0.32001.0> -------- OS Process #Port<0.44> Log :: {"_id":"abc","_rev":"6-4ce6392348c3ad61213d15184a08c3c3","title":"There is Notaasdfhing Left to Lose","artist":"Fasdfoo Fighters","year":"129297","_revisions":{"start":6,"ids":["4ce6392348c3ad61213d15184a08c3c3","558aa6381166ee2836c112e0eac4b148","fa0362e7c84f3c0df7827515b5c58f86","a266c2261a2d0704c5fe7689b6786dfb","645dd6050dcd378678fea4627db832b3","4c6114c65e295552ab1019e2b046b10e"]}}

which does not include all the good stuff documented to be in the request object?

{
   "body": "undefined",
   "cookie": {
       "AuthSession": "cm9vdDo1MDZBRjQzRjrfcuikzPRfAn-EA37FmjyfM8G8Lw",
       "m": "3234"
   },
   "form": {},
   "headers": {
       "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
       "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.3",
       "Accept-Encoding": "gzip,deflate,sdch",
       "Accept-Language": "en-US,en;q=0.8",
       "Connection": "keep-alive",
       "Cookie": "m=3234:t|3247:t|6493:t|6967:t|34e2:|18c3:t|2c69:t|5acb:t|ca3:t|c01:t|5e55:t|77cb:t|2a03:t|1d98:t|47ba:t|64b8:t|4a01:t;
AuthSession=cm9vdDo1MDZBRjQzRjrfcuikzPRfAn-EA37FmjyfM8G8Lw",
       "Host": "127.0.0.1:5984",
       "User-Agent": "Mozilla/5.0 (Windows NT 5.2) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7"
   },
   "id": "foo",
   "info": {
       "committed_update_seq": 2701412,
       "compact_running": false,
       "db_name": "mailbox",
       "disk_format_version": 6,
       "doc_count": 2262757,
       "doc_del_count": 560,
       "instance_start_time": "1347601025628957",
       "purge_seq": 0,
       "sizes": {
         "active": 7580843252,
         "disk": 14325313673,
         "external": 7803423459
       },
       "update_seq": 2701412
   },
   "method": "GET",
   "path": [
       "mailbox",
       "_design",
       "request",
       "_show",
       "dump",
       "foo"
   ],
   "peer": "127.0.0.1",
   "query": {},
   "raw_path": "/mailbox/_design/request/_show/dump/foo",
   "requested_path": [
       "mailbox",
       "_design",
       "request",
       "_show",
       "dump",
       "foo"
   ],
   "secObj": {
       "admins": {
           "names": [
               "Bob"
           ],
           "roles": []
       },
       "members": {
           "names": [
               "Mike",
               "Alice"
           ],
           "roles": []
       }
   },
   "userCtx": {
       "db": "mailbox",
       "name": "Mike",
       "roles": [
           "user"
       ]
   },
   "uuid": "3184f9d1ea934e1f81a24c71bde5c168"
}

Solution

  • I think you're getting confused between replication filter function and the validate_doc_update function. The call to the latter is not given the request object, as per the docs it's given the new doc, the old doc (what you're logging), the user context and the security object.