Permalink
Browse files

Logging no longer uses root logger.

Each module should now log into its own logger.
  • Loading branch information...
1 parent d0c506f commit 4fb77ac8787422169566d613562127acf75a427b @legastero legastero committed Nov 6, 2010
View
@@ -26,6 +26,9 @@
from sleekxmpp.xmlstream.handler import *
+log = logging.getLogger(__name__)
+
+
# Flag indicating if DNS SRV records are available for use.
SRV_SUPPORT = True
try:
@@ -192,9 +195,9 @@ class if using custom plugins.
xep = "(XEP-%s) " % self.plugin[plugin].xep
desc = (xep, self.plugin[plugin].description)
- logging.debug("Loaded Plugin %s%s" % desc)
+ log.debug("Loaded Plugin %s%s" % desc)
except:
- logging.exception("Unable to load plugin: %s", plugin)
+ log.exception("Unable to load plugin: %s", plugin)
def register_plugins(self):
"""
@@ -228,7 +231,7 @@ def __getitem__(self, key):
if key in self.plugin:
return self.plugin[key]
else:
- logging.warning("""Plugin "%s" is not loaded.""" % key)
+ log.warning("""Plugin "%s" is not loaded.""" % key)
return False
def get(self, key, default):
@@ -446,69 +449,69 @@ def jid(self):
"""
Attribute accessor for bare jid
"""
- logging.warning("jid property deprecated. Use boundjid.bare")
+ log.warning("jid property deprecated. Use boundjid.bare")
return self.boundjid.bare
@jid.setter
def jid(self, value):
- logging.warning("jid property deprecated. Use boundjid.bare")
+ log.warning("jid property deprecated. Use boundjid.bare")
self.boundjid.bare = value
@property
def fulljid(self):
"""
Attribute accessor for full jid
"""
- logging.warning("fulljid property deprecated. Use boundjid.full")
+ log.warning("fulljid property deprecated. Use boundjid.full")
return self.boundjid.full
@fulljid.setter
def fulljid(self, value):
- logging.warning("fulljid property deprecated. Use boundjid.full")
+ log.warning("fulljid property deprecated. Use boundjid.full")
self.boundjid.full = value
@property
def resource(self):
"""
Attribute accessor for jid resource
"""
- logging.warning("resource property deprecated. Use boundjid.resource")
+ log.warning("resource property deprecated. Use boundjid.resource")
return self.boundjid.resource
@resource.setter
def resource(self, value):
- logging.warning("fulljid property deprecated. Use boundjid.full")
+ log.warning("fulljid property deprecated. Use boundjid.full")
self.boundjid.resource = value
@property
def username(self):
"""
Attribute accessor for jid usernode
"""
- logging.warning("username property deprecated. Use boundjid.user")
+ log.warning("username property deprecated. Use boundjid.user")
return self.boundjid.user
@username.setter
def username(self, value):
- logging.warning("username property deprecated. Use boundjid.user")
+ log.warning("username property deprecated. Use boundjid.user")
self.boundjid.user = value
@property
def server(self):
"""
Attribute accessor for jid host
"""
- logging.warning("server property deprecated. Use boundjid.host")
+ log.warning("server property deprecated. Use boundjid.host")
return self.boundjid.server
@server.setter
def server(self, value):
- logging.warning("server property deprecated. Use boundjid.host")
+ log.warning("server property deprecated. Use boundjid.host")
self.boundjid.server = value
def set_jid(self, jid):
"""Rip a JID apart and claim it as our own."""
- logging.debug("setting jid to %s" % jid)
+ log.debug("setting jid to %s" % jid)
self.boundjid.full = jid
def getjidresource(self, fulljid):
@@ -588,7 +591,7 @@ def _handle_presence(self, presence):
# disconnects. Determine if this was the last connection
# for the JID.
if show == 'unavailable':
- logging.debug("%s %s got offline" % (jid, resource))
+ log.debug("%s %s got offline" % (jid, resource))
del connections[resource]
if not connections and not self.roster[jid]['in_roster']:
@@ -604,7 +607,7 @@ def _handle_presence(self, presence):
self.event("changed_status", presence)
if got_online:
self.event("got_online", presence)
- logging.debug("STATUS: %s%s/%s[%s]: %s" % (name, jid, resource,
+ log.debug("STATUS: %s%s/%s[%s]: %s" % (name, jid, resource,
show, status))
def _handle_subscribe(self, presence):
View
@@ -32,6 +32,9 @@
SRV_SUPPORT = False
+log = logging.getLogger(__name__)
+
+
class ClientXMPP(BaseXMPP):
"""
@@ -133,7 +136,7 @@ def handle_connected(self, event=None):
def _session_timeout_check(self):
if not self.session_started_event.isSet():
- logging.debug("Session start has taken more than 15 seconds")
+ log.debug("Session start has taken more than 15 seconds")
self.disconnect(reconnect=self.auto_reconnect)
def connect(self, address=tuple()):
@@ -150,19 +153,19 @@ def connect(self, address=tuple()):
self.session_started_event.clear()
if not address or len(address) < 2:
if not self.srv_support:
- logging.debug("Did not supply (address, port) to connect" + \
+ log.debug("Did not supply (address, port) to connect" + \
" to and no SRV support is installed" + \
" (http://www.dnspython.org)." + \
" Continuing to attempt connection, using" + \
" server hostname from JID.")
else:
- logging.debug("Since no address is supplied," + \
+ log.debug("Since no address is supplied," + \
"attempting SRV lookup.")
try:
xmpp_srv = "_xmpp-client._tcp.%s" % self.server
answers = dns.resolver.query(xmpp_srv, dns.rdatatype.SRV)
except dns.resolver.NXDOMAIN:
- logging.debug("No appropriate SRV record found." + \
+ log.debug("No appropriate SRV record found." + \
" Using JID server name.")
else:
# Pick a random server, weighted by priority.
@@ -276,7 +279,7 @@ def _handle_starttls(self, xml):
self.send_xml(xml)
return True
else:
- logging.warning("The module tlslite is required to log in" +\
+ log.warning("The module tlslite is required to log in" +\
" to some servers, and has not been found.")
return False
@@ -286,7 +289,7 @@ def _handle_tls_start(self, xml):
Restarts the stream.
"""
- logging.debug("Starting TLS")
+ log.debug("Starting TLS")
if self.start_tls():
raise RestartStream()
@@ -300,7 +303,7 @@ def _handle_sasl_auth(self, xml):
if '{urn:ietf:params:xml:ns:xmpp-tls}starttls' in self.features:
return False
- logging.debug("Starting SASL Auth")
+ log.debug("Starting SASL Auth")
sasl_ns = 'urn:ietf:params:xml:ns:xmpp-sasl'
self.add_handler("<success xmlns='%s' />" % sasl_ns,
self._handle_auth_success,
@@ -334,7 +337,7 @@ def _handle_sasl_auth(self, xml):
sasl_ns,
'ANONYMOUS'))
else:
- logging.error("No appropriate login method.")
+ log.error("No appropriate login method.")
self.disconnect()
return True
@@ -356,7 +359,7 @@ def _handle_auth_fail(self, xml):
Arguments:
xml -- The SASL authentication failure element.
"""
- logging.info("Authentication failed.")
+ log.info("Authentication failed.")
self.event("failed_auth", direct=True)
self.disconnect()
@@ -367,7 +370,7 @@ def _handle_bind_resource(self, xml):
Arguments:
xml -- The bind feature element.
"""
- logging.debug("Requesting resource: %s" % self.boundjid.resource)
+ log.debug("Requesting resource: %s" % self.boundjid.resource)
xml.clear()
iq = self.Iq(stype='set')
if self.boundjid.resource:
@@ -381,10 +384,10 @@ def _handle_bind_resource(self, xml):
self.set_jid(response.xml.find('{%s}bind/{%s}jid' % (bind_ns,
bind_ns)).text)
self.bound = True
- logging.info("Node set to: %s" % self.boundjid.fulljid)
+ log.info("Node set to: %s" % self.boundjid.fulljid)
session_ns = 'urn:ietf:params:xml:ns:xmpp-session'
if "{%s}session" % session_ns not in self.features or self.bindfail:
- logging.debug("Established Session")
+ log.debug("Established Session")
self.sessionstarted = True
self.session_started_event.set()
self.event("session_start")
@@ -399,7 +402,7 @@ def _handle_start_session(self, xml):
if self.authenticated and self.bound:
iq = self.makeIqSet(xml)
response = iq.send()
- logging.debug("Established Session")
+ log.debug("Established Session")
self.sessionstarted = True
self.session_started_event.set()
self.event("session_start")
@@ -22,6 +22,9 @@
from sleekxmpp.xmlstream.handler import *
+log = logging.getLogger(__name__)
+
+
class ComponentXMPP(BaseXMPP):
"""
@@ -82,7 +85,7 @@ def connect(self):
Overrides XMLStream.connect.
"""
- logging.debug("Connecting to %s:%s" % (self.server_host,
+ log.debug("Connecting to %s:%s" % (self.server_host,
self.server_port))
return XMLStream.connect(self, self.server_host,
self.server_port)
@@ -14,6 +14,9 @@
from .. stanza.iq import Iq
+log = logging.getLogger(__name__)
+
+
class GmailQuery(ElementBase):
namespace = 'google:mail:notify'
name = 'query'
@@ -34,12 +37,12 @@ class MailBox(ElementBase):
namespace = 'google:mail:notify'
name = 'mailbox'
plugin_attrib = 'mailbox'
- interfaces = set(('result-time', 'total-matched', 'total-estimate',
+ interfaces = set(('result-time', 'total-matched', 'total-estimate',
'url', 'threads', 'matched', 'estimate'))
def getThreads(self):
threads = []
- for threadXML in self.xml.findall('{%s}%s' % (MailThread.namespace,
+ for threadXML in self.xml.findall('{%s}%s' % (MailThread.namespace,
MailThread.name)):
threads.append(MailThread(xml=threadXML, parent=None))
return threads
@@ -55,10 +58,10 @@ class MailThread(ElementBase):
namespace = 'google:mail:notify'
name = 'mail-thread-info'
plugin_attrib = 'thread'
- interfaces = set(('tid', 'participation', 'messages', 'date',
+ interfaces = set(('tid', 'participation', 'messages', 'date',
'senders', 'url', 'labels', 'subject', 'snippet'))
sub_interfaces = set(('labels', 'subject', 'snippet'))
-
+
def getSenders(self):
senders = []
sendersXML = self.xml.find('{%s}senders' % self.namespace)
@@ -91,13 +94,13 @@ class gmail_notify(base.base_plugin):
"""
Google Talk: Gmail Notifications
"""
-
+
def plugin_init(self):
self.description = 'Google Talk: Gmail Notifications'
self.xmpp.registerHandler(
Callback('Gmail Result',
- MatchXPath('{%s}iq/{%s}%s' % (self.xmpp.default_ns,
+ MatchXPath('{%s}iq/{%s}%s' % (self.xmpp.default_ns,
MailBox.namespace,
MailBox.name)),
self.handle_gmail))
@@ -108,7 +111,7 @@ def plugin_init(self):
NewMail.namespace,
NewMail.name)),
self.handle_new_mail))
-
+
registerStanzaPlugin(Iq, GmailQuery)
registerStanzaPlugin(Iq, MailBox)
registerStanzaPlugin(Iq, NewMail)
@@ -118,12 +121,12 @@ def plugin_init(self):
def handle_gmail(self, iq):
mailbox = iq['mailbox']
approx = ' approximately' if mailbox['estimated'] else ''
- logging.info('Gmail: Received%s %s emails' % (approx, mailbox['total-matched']))
+ log.info('Gmail: Received%s %s emails' % (approx, mailbox['total-matched']))
self.last_result_time = mailbox['result-time']
self.xmpp.event('gmail_messages', iq)
def handle_new_mail(self, iq):
- logging.info("Gmail: New emails received!")
+ log.info("Gmail: New emails received!")
self.xmpp.event('gmail_notify')
self.checkEmail()
@@ -135,9 +138,9 @@ def checkEmail(self):
def search(self, query=None, newer=None):
if query is None:
- logging.info("Gmail: Checking for new emails")
+ log.info("Gmail: Checking for new emails")
else:
- logging.info('Gmail: Searching for emails matching: "%s"' % query)
+ log.info('Gmail: Searching for emails matching: "%s"' % query)
iq = self.xmpp.Iq()
iq['type'] = 'get'
iq['to'] = self.xmpp.jid
View
@@ -3,15 +3,19 @@
from xml.etree import cElementTree as ET
import types
+
+log = logging.getLogger(__name__)
+
+
class jobs(base.base_plugin):
def plugin_init(self):
self.xep = 'pubsubjob'
self.description = "Job distribution over Pubsub"
-
+
def post_init(self):
pass
#TODO add event
-
+
def createJobNode(self, host, jid, node, config=None):
pass
@@ -40,7 +44,7 @@ def _setState(self, host, node, jobid, state, ifrom=None):
iq['psstate']['payload'] = state
result = iq.send()
if result is None or type(result) == types.BooleanType or result['type'] != 'result':
- logging.error("Unable to change %s:%s to %s" % (node, jobid, state))
+ log.error("Unable to change %s:%s to %s" % (node, jobid, state))
return False
return True
Oops, something went wrong.

0 comments on commit 4fb77ac

Please sign in to comment.