add debug logging to irclib rather than the gross print()ing

note that with the default logging config, nothing is printed at INFO,
so irclib is silent. but this is better control over the debugging
This commit is contained in:
Brian S. Stephan 2012-07-26 20:17:18 -05:00
parent 2a0cd05cbc
commit 26596e5e00
3 changed files with 24 additions and 30 deletions

View File

@ -49,9 +49,6 @@ except NoSectionError as e:
except NoOptionError as e:
sys.exit("Aborted due to error with necessary configuration: " + str(e))
# load additional options
irclib.DEBUG = config.getboolean('dr.botzo', 'debug')
logging.config.fileConfig('logging.cfg')
log = logging.getLogger('drbotzo')

View File

@ -64,6 +64,7 @@ Current limitations:
"""
import bisect
import logging
import re
import select
import socket
@ -80,7 +81,7 @@ try:
except Exception:
VERSION = ()
DEBUG = False
log = logging.getLogger('irclib')
# TODO
# ----
@ -568,8 +569,7 @@ class ServerConnection(Connection):
self.previous_buffer = lines.pop()
for line in lines:
if DEBUG:
print "FROM SERVER:", line
log.debug("FROM SERVER:" + line)
if not line:
continue
@ -630,16 +630,14 @@ class ServerConnection(Connection):
command = "ctcpreply"
m = list(m)
if DEBUG:
print "command: %s, source: %s, target: %s, arguments: %s" % (
command, prefix, target, m)
log.debug("command: %s, source: %s, target: %s, arguments: %s" % (
command, prefix, target, m))
self._handle_event(Event(command, prefix, target, m))
if command == "ctcp" and m[0] == "ACTION":
self._handle_event(Event("action", prefix, target, m[1:]))
else:
if DEBUG:
print "command: %s, source: %s, target: %s, arguments: %s" % (
command, prefix, target, [m])
log.debug("command: %s, source: %s, target: %s, arguments: %s" % (
command, prefix, target, [m]))
self._handle_event(Event(command, prefix, target, [m]))
else:
target = None
@ -656,9 +654,8 @@ class ServerConnection(Connection):
if not is_channel(target):
command = "umode"
if DEBUG:
print "command: %s, source: %s, target: %s, arguments: %s" % (
command, prefix, target, arguments)
log.debug("command: %s, source: %s, target: %s, arguments: %s" % (
command, prefix, target, arguments))
self._handle_event(Event(command, prefix, target, arguments))
def _handle_event(self, event):
@ -853,8 +850,7 @@ class ServerConnection(Connection):
self.ssl.write(string + "\r\n")
else:
self.socket.send(string + "\r\n")
if DEBUG:
print "TO SERVER:", string
log.debug("TO SERVER:" + string)
except socket.error:
# Ouch!
self.disconnect("Connection reset by peer.")
@ -1011,9 +1007,8 @@ class DCCConnection(Connection):
self.socket.close()
self.socket = conn
self.connected = 1
if DEBUG:
print "DCC connection from %s:%d" % (
self.peeraddress, self.peerport)
log.debug("DCC connection from %s:%d" % (
self.peeraddress, self.peerport))
self.irclibobj._handle_event(
self,
Event("dcc_connect", self.peeraddress, None, None))
@ -1049,12 +1044,10 @@ class DCCConnection(Connection):
prefix = self.peeraddress
target = None
for chunk in chunks:
if DEBUG:
print "FROM PEER:", chunk
log.debug("FROM PEER:" + chunk)
arguments = [chunk]
if DEBUG:
print "command: %s, source: %s, target: %s, arguments: %s" % (
command, prefix, target, arguments)
log.debug("command: %s, source: %s, target: %s, arguments: %s" % (
command, prefix, target, arguments))
self.irclibobj._handle_event(
self,
Event(command, prefix, target, arguments))
@ -1073,8 +1066,7 @@ class DCCConnection(Connection):
self.socket.send(string)
if self.dcctype == "chat":
self.socket.send("\n")
if DEBUG:
print "TO PEER: %s\n" % string
log.debug("TO PEER: %s\n" % string)
except socket.error:
# Ouch!
self.disconnect("Connection reset by peer.")
@ -1109,8 +1101,7 @@ class SimpleIRCClient(object):
def _dispatcher(self, c, e):
"""[Internal]"""
if DEBUG:
print("irclib.py:_dispatcher:%s" % e.eventtype())
log.debug("irclib.py:_dispatcher:%s" % e.eventtype())
m = "on_" + e.eventtype()
if hasattr(self, m):

View File

@ -1,5 +1,5 @@
[loggers]
keys = root,drbotzo
keys = root,drbotzo,irclib
[handlers]
keys = stdout,logfile
@ -11,6 +11,12 @@ keys = verbose
level = INFO
handlers = stdout,logfile
[logger_irclib]
level = INFO
handlers = stdout,logfile
propagate = 0
qualname = irclib
[logger_drbotzo]
level = DEBUG
handlers = stdout,logfile