Permalink
Browse files

Merge branch 'logging'

* logging:
  Add logging in bccc.client.channel and bccc.client.client
  Add logging in bccc.client.atom and bccc.ui.thread
  • Loading branch information...
2 parents ea5af0d + 47f9293 commit febd55015e63d4ed6577a477aec7cb24066eb968 @Schnouki committed Jun 6, 2012
Showing with 41 additions and 12 deletions.
  1. +7 −7 bccc/client/atom.py
  2. +15 −2 bccc/client/channel.py
  3. +9 −0 bccc/client/client.py
  4. +10 −3 bccc/ui/thread.py
View
@@ -17,8 +17,8 @@
import dateutil.parser
-logger = logging.getLogger('bccc.client.atom')
-logger.addHandler(logging.NullHandler())
+log = logging.getLogger(__name__)
+log.addHandler(logging.NullHandler())
ATOM_NS = "http://www.w3.org/2005/Atom"
ATOM_THR_NS = "http://purl.org/syndication/thread/1.0"
@@ -45,7 +45,7 @@ def author(self):
a = self.get_child("author")
if a is None:
# Something is terribly wrong.
- logger.warning("Atom without author")
+ log.warning("Atom without author")
return "[unknown author]"
name = a.find("{{{}}}name".format(ATOM_NS))
if name is not None:
@@ -54,22 +54,22 @@ def author(self):
# This should NOT happen >:-(
url = a.find("{{{}}}url".format(ATOM_NS))
if url is not None:
- logger.warning("Atom without author name")
+ log.warning("Atom without author name")
return url.text
else:
- logger.warning("Atom without author name & URL")
+ log.warning("Atom without author name & URL")
# Really ??!?
return "[unknown author]"
@property
def content(self):
cnt = self.get_child("content")
if cnt is None:
- logger.warning("Atom without content")
+ log.warning("Atom without content")
return ""
text = self.get_child("content").text
if text is None:
- logger.warning("Atom without content text")
+ log.warning("Atom without content text")
text = ""
return text.strip()
@@ -13,12 +13,16 @@
import datetime
from xml.etree import cElementTree as ET
+import logging
import threading
import dateutil.parser
from bccc.client import Atom, ATOM_NS, ATOM_THR_NS, UpdatableAtomsList
+log = logging.getLogger(__name__)
+log.addHandler(logging.NullHandler())
+
# {{{ Exceptions
class PostError(Exception):
"""Error when handling a post"""
@@ -36,6 +40,7 @@ class Channel:
)
def __init__(self, client, jid):
+ log.info("Initializing channel %s", jid)
self.client = client
self.jid = jid
@@ -222,23 +227,30 @@ def _make_atom(self, text, author_name=None, in_reply_to=None, update_time=None)
return entry
def publish(self, text, author_name=None, in_reply_to=None):
+ log.debug("Publishing to channel %s...", self.jid)
entry = self._make_atom(text, author_name=author_name, in_reply_to=in_reply_to)
node = "/user/{}/posts".format(self.jid)
res = self.client.ps.publish(self.client.channels_jid, node, payload=entry)
- return res["pubsub"]["publish"]["item"]["id"]
+ id_ = res["pubsub"]["publish"]["item"]["id"]
+ log.info("Published to channel %s with id %s", self.jid, id_)
+ return id_
def retract(self, id_):
+ log.debug("Retracting %s from channel %s", id_, self.jid)
node = "/user/{}/posts".format(self.jid)
res = self.client.ps.retract(self.client.channels_jid, node, id_, notify=True)
with self.atoms_lock:
self.atoms.remove(id_)
return res
def set_status(self, text, author_name=None):
+ log.debug("Setting status for channel %s...", self.jid)
entry = self._make_atom(text, author_name=author_name)
node = "/user/{}/status".format(self.jid)
res = self.client.ps.publish(self.client.channels_jid, node, payload=entry)
- return res["pubsub"]["publish"]["item"]["id"]
+ id_ = res["pubsub"]["publish"]["item"]["id"]
+ log.info("Status set for channel %s with id %s", self.jid, id_)
+ return id_
def update_config(self, **kwds):
# Create config form
@@ -248,6 +260,7 @@ def update_config(self, **kwds):
if dk in kwds:
form.add_field(var=ik, value=kwds[dk])
+ log.info("Updating config for channel %s", self.jid)
node = "/user/{}/posts".format(self.jid)
self.client.ps.set_node_config(self.client.channels_jid, node, form)
# }}}
@@ -11,6 +11,7 @@
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
+import logging
import threading
import sleekxmpp
@@ -20,6 +21,9 @@
from bccc.client.channel import Channel
+log = logging.getLogger(__name__)
+log.addHandler(logging.NullHandler())
+
# {{{ Exceptions
class ClientError(Exception):
"""Error in a client operation"""
@@ -37,6 +41,7 @@ class Client(sleekxmpp.ClientXMPP):
# {{{ Init, login, discovery, etc.
def __init__(self, jid, password):
+ log.info("Initializing SleekXMPP client")
sleekxmpp.ClientXMPP.__init__(self, jid, password)
self.channels_cond = threading.Condition()
@@ -67,6 +72,7 @@ def __repr__(self):
def start(self, event):
# Try to find channels service
+ log.info("Starting service discovery")
items = self.disco.get_items(jid=self.boundjid.host, block=True)
for jid, node, name in items["disco_items"]["items"]:
@@ -76,6 +82,7 @@ def start(self, event):
continue
for id_ in info["disco_info"]["identities"]:
if id_[0] == "pubsub" and id_[1] == "channels":
+ log.info("Channels service found at %s", jid)
with self.channels_cond:
self.channels_jid = jid
self.channels_cond.notify()
@@ -149,6 +156,7 @@ def handle_pubsub_event(self, msg):
elif chan_type == "status":
evt_type = EVENT_STATUS
else:
+ log.debug("Unsupported node type for items event: %s", node)
return
data = [item.get_payload() for item in items]
@@ -158,6 +166,7 @@ def handle_pubsub_event(self, msg):
node = data["node"]
jid, chan_type = node[6:].rsplit("/", 1)
if chan_type != "posts":
+ log.debug("Unsupported node type for configuration event: %s", node)
return
# Do we have everything we need?
View
@@ -20,8 +20,8 @@
NewPostWidget, NewReplyWidget
from .util import extract_urls
-logger = logging.getLogger('bccc.ui.thread')
-logger.addHandler(logging.NullHandler())
+log = logging.getLogger(__name__)
+log.addHandler(logging.NullHandler())
# {{{ ThreadList helper
class ThreadList(list):
@@ -133,6 +133,7 @@ def get_next(self, position):
# }}}
# {{{ Channel management
def set_channel(self, channel):
+ log.info("Loading channel %s", channel.jid)
del self.threads[:]
self.extra_widget = None
self.channel = channel
@@ -149,6 +150,7 @@ def set_channel(self, channel):
def _load_more_posts(self):
if not self.more_posts_requested:
+ log.debug("Requesting more posts")
after_id = None
if self.oldest_item is not None:
after_id = self.oldest_item.id
@@ -167,6 +169,7 @@ def goto_focused_post_channel(self):
# }}}
# {{{ Threads management
def add(self, item):
+ log.debug("Adding item %s", item.id)
self.more_posts_requested = False
if self.oldest_item is None or item.published < self.oldest_item.published:
self.oldest_item = item
@@ -225,6 +228,7 @@ def find_thread_by_id(self, thr_id):
return (pos, thr)
def remove(self, id_):
+ log.debug("Removing item %s", id_)
focus_pos = self.focus_item[1]
# Find post/reply with specified id
@@ -293,7 +297,7 @@ def _delete_item(text):
text = text.strip().lower()
if text == "y":
id_ = w.id
- logger.info("Deleting post %s", id_)
+ log.info("Deleting post %s", id_)
self.channel.retract(id_)
self.remove(id_)
self.ui.status.set_text("Post {} deleted.".format(id_))
@@ -380,20 +384,23 @@ def update_description(self):
def _set_desc(text):
text = text.strip()
if len(text) > 0:
+ log.info("Setting channel description to %s", text)
self.content.channel.update_config(description=text)
self.ui.status.ask("New channel description: ", _set_desc)
def update_status(self):
def _set_status(text):
text = text.strip()
if len(text) > 0:
+ log.info("Setting channel status to %s", text)
self.content.channel.set_status(text)
self.ui.status.ask("New status message: ", _set_status)
def update_title(self):
def _set_title(text):
text = text.strip()
if len(text) > 0:
+ log.info("Setting channel title to %s", text)
self.content.channel.update_config(title=text)
self.ui.status.ask("New channel title: ", _set_title)
# }}}

0 comments on commit febd550

Please sign in to comment.