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: except NoOptionError as e:
sys.exit("Aborted due to error with necessary configuration: " + str(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') logging.config.fileConfig('logging.cfg')
log = logging.getLogger('drbotzo') log = logging.getLogger('drbotzo')

View File

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

View File

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