Maybe you could add a boolean named "debug" or something and only register these functions for onError, onOpen, onClose etc if it's true. It would also make it easier to turn on debugging again by just setting it to true instead of uncommenting all these lines below.