jgarzik/python-bitcoinrpc — pull request #31 by gavinandresen (2014-04-17 12:53:25+00:00)
Title: Add optional logging of all RPC communication

More convenient than figuring out how to insert wireshark into the RPC communication path.

Logging the RPC calls and results made can be useful when debugging problems. This uses the standard python logging module; simple usage to trace all RPC calls to stderr:

import logging
logging.basicConfig()
logging.getLogger("BitcoinRPC").setLevel(logging.DEBUG)

Example logging output:

>>> c = AuthServiceProxy("http://u:p@127.0.0.1:18332")
>>> c.getinfo()
DEBUG:BitcoinRPC:-1-> getinfo []
DEBUG:BitcoinRPC:<-1- {"connections": 8, ...etc }

>>> c.setgenerate(True, 2)
DEBUG:BitcoinRPC:-2-> setgenerate [true, 2]
DEBUG:BitcoinRPC:<-2- null

>>> c.setgenerate(True, Decimal('2'))
DEBUG:BitcoinRPC:-3-> setgenerate [true, 2.0]
DEBUG:BitcoinRPC:<-- {"result":null,"error":{"code":-1,"message":"value is type real, expected int"},"id":3}