connection: added proper logging

Instead of hardcoding debug output to go to stdout, this commit updates
the connection module to use the python logging interface, allowing
clients to customize handling and format of any generated messages.