Couchdb Logging

2019-09-06 04:23发布

问题:

Due to application requirements, I have an externally accessible CouchDB instance. I would like to see what IP addresses are attempting to authenticate with my database. By checking the couchdb.log file, I can see failed authentication attempts. They look similar to this.

[Mon, 29 Sep 2014 13:43:32 GMT] [info] [<0.28472.7>] 127.0.0.1 - - GET /offline_master/ 401

However, no matter where I connect from, it seems that the IP address that is logged is always 127.0.0.1. Am I mis-understanding how this works? I would really like to see the IP address that is attempting to connect.

回答1:

The 127.0.0.1 is the address couchDB is bound to. It's there because you can set up couchdb to respond differently depending on what host name is being used.

The only way to get the client ip address is by turning the logging level to "debug". You can do this in the configuration page in futon.

You get records like this (client IP is on 1st line):

[Tue, 30 Sep 2014 00:14:27 GMT] [debug] [<0.451.4>] 'GET' / {1,1} from "192.168.1.52"
Headers: [{'Accept',"*/*"},
          {'Host',"localhost:5984"},
          {'User-Agent',"curl/7.30.0"}]
[Tue, 30 Sep 2014 00:14:27 GMT] [debug] [<0.451.4>] OAuth Params: []
[Tue, 30 Sep 2014 00:14:27 GMT] [info] [<0.451.4>] 127.0.0.1 - - GET / 200

Be careful with this. The debug logs are extremely verbose. It doesn't take long to fill up a hard drive.

It is possible to set log levels by module. The module you need to set is couch_httpd. Set the default for the rest to "error" or "fatal".

See: 3.6.2 Per module logging