changeset 439:d52f529a6d42

browser side: use of new log system (first draft): - configuration is hardcoded in libervia.py, it will change in the (hopefuly) near future - log level is DEBUG for the moment, will be changed to INFO when configuration will not be hardcoded anymore - the basic log backend is used, in the future, a console.debug/info/etc should be used instead. A log widget which HTML colors is also an option
author Goffi <goffi@goffi.org>
date Thu, 08 May 2014 17:21:34 +0200
parents 582c435dab6b
children 88461e9c3e47
files browser_side/base_panels.py browser_side/base_widget.py browser_side/card_game.py browser_side/contact.py browser_side/dialog.py browser_side/file_tools.py browser_side/list_manager.py browser_side/menu.py browser_side/notification.py browser_side/panels.py browser_side/radiocol.py browser_side/xmlui.py libervia.py
diffstat 13 files changed, 122 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/base_panels.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/base_panels.py	Thu May 08 17:21:34 2014 +0200
@@ -18,6 +18,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import pyjd  # this is dummy in pyjs
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.AbsolutePanel import AbsolutePanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
 from pyjamas.ui.HorizontalPanel import HorizontalPanel
@@ -67,7 +69,7 @@
         """
         @param nick: the user nickname
         @param state: the user chate state (XEP-0085)
-        @param special: a string of symbols (e.g: for activities) 
+        @param special: a string of symbols (e.g: for activities)
         """
         HTML.__init__(self)
         self.nick = nick
@@ -119,7 +121,7 @@
         try:
             self.remove(self.occupants_list[nick])
         except KeyError:
-            print "ERROR: trying to remove an unexisting nick"
+            log.error("trying to remove an unexisting nick")
 
     def clear(self):
         self.occupants_list.clear()
--- a/browser_side/base_widget.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/base_widget.py	Thu May 08 17:21:34 2014 +0200
@@ -18,6 +18,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import pyjd  # this is dummy in pyjs
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.AbsolutePanel import AbsolutePanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
@@ -116,15 +118,15 @@
             if item_type and item_type[-1] == '\0':  # Workaround for what looks like a pyjamas bug: the \0 should not be there, and
                 item_type = item_type[:-1]           # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report
             # item_type = dt.getData("type")
-            print "message: %s" % item
-            print "type: %s" % item_type
+            log.debug("message: %s" % item)
+            log.debug("type: %s" % item_type)
         except:
-            print "no message found"
+            log.debug("no message found")
             item = '&nbsp;'
             item_type = None
         if item_type == "WIDGET":
             if not LiberviaDragWidget.current:
-                print "ERROR: No widget registered in LiberviaDragWidget !"
+                log.error("No widget registered in LiberviaDragWidget !")
                 return
             _new_panel = LiberviaDragWidget.current
             if self == _new_panel:  # We can't drop on ourself
@@ -141,13 +143,13 @@
         elif item_type in self.drop_keys:
             _new_panel = self.drop_keys[item_type](self.host, item)
         else:
-            print "WARNING: unmanaged item type"
+            log.warning("unmanaged item type")
             return
         if isinstance(self, LiberviaWidget):
             self.host.unregisterWidget(self)
             self.onQuit()
             if not isinstance(_new_panel, LiberviaWidget):
-                print ('WARNING: droping an object which is not a class of LiberviaWidget')
+                log.warning("droping an object which is not a class of LiberviaWidget")
         _flextable = self.getParent()
         _widgetspanel = _flextable.getParent().getParent()
         row_idx, cell_idx = self._getCellAndRow(_flextable, event)
@@ -229,7 +231,7 @@
         """
         Note: this method overrides pyjamas.ui.Widget.getParent
         @param class_: class of the ancestor to look for or None to return the first parent
-        @param verbose: set to True to log error messages
+        @param verbose: set to True to log error messages # FIXME: must be removed
         @return: the parent/ancestor or None if it has not been found
         """
         current = Widget.getParent(self)
@@ -238,7 +240,7 @@
         while current is not None and not isinstance(current, class_):
             current = Widget.getParent(current)
         if current is None and verbose:
-            print "Can't find parent %s for %s" % (class_, self)
+            log.debug("Can't find parent %s for %s" % (class_, self))
         return current
 
     def onClick(self, sender):
@@ -365,7 +367,7 @@
             - NONE
         """
         if not self.__selectable:
-            print "ERROR: getWarningLevel must not be called for an unselectable widget"
+            log.error("getWarningLevel must not be called for an unselectable widget")
             raise Exception
         # TODO: cleaner warning types (more general constants)
         return ("NONE", None)
@@ -486,19 +488,19 @@
 
     def changeWidget(self, row, col, wid):
         """Change the widget in the given location, add row or columns when necessary"""
-        print "changing widget:", wid.getDebugName(), row, col
+        log.debug("changing widget: %s %s %s" % (wid.getDebugName(), row, col))
         last_row = max(0, self.flextable.getRowCount() - 1)
         try:
             prev_wid = self.flextable.getWidget(row, col)
         except:
-            print "ERROR: Trying to change an unexisting widget !"
+            log.error("Trying to change an unexisting widget !")
             return
 
         cellFormatter = self.flextable.getFlexCellFormatter()
 
         if isinstance(prev_wid, BorderWidget):
             # We are on a border, we must create a row and/or columns
-            print "BORDER WIDGET"
+            log.debug("BORDER WIDGET")
             prev_wid.removeStyleName('dragover')
 
             if isinstance(prev_wid, BottomBorderWidget):
@@ -512,14 +514,14 @@
 
             elif isinstance(prev_wid, LeftBorderWidget):
                 if col != 0:
-                    print "ERROR: LeftBorderWidget must be on the first column !"
+                    log.error("LeftBorderWidget must be on the first column !")
                     return
                 self.flextable.insertCell(row, col + 1)
                 self.flextable.setWidget(row, 1, wid)
 
             elif isinstance(prev_wid, RightBorderWidget):
                 if col != self.flextable.getCellCount(row) - 1:
-                    print "ERROR: RightBorderWidget must be on the last column !"
+                    log.error("RightBorderWidget must be on the last column !")
                     return
                 self.flextable.insertCell(row, col)
                 self.flextable.setWidget(row, col, wid)
@@ -550,7 +552,7 @@
     def addWidget(self, wid):
         """Add a widget to a new cell on the next to last row"""
         last_row = max(0, self.flextable.getRowCount() - 1)
-        print "putting widget %s at %d, %d" % (wid.getDebugName(), last_row, 0)
+        log.debug("putting widget %s at %d, %d" % (wid.getDebugName(), last_row, 0))
         self.changeWidget(last_row, 0, wid)
 
     def removeWidget(self, wid):
@@ -577,7 +579,7 @@
                     current.onWidgetPanelRemove(self)
                     return
                 current = current.getParent()
-            print "Error: no MainTabPanel found !"
+            log.error("no MainTabPanel found !")
 
     def getWidgetCoords(self, wid):
         return self.flextable.getIndex(wid)
@@ -660,22 +662,22 @@
             if item_type and item_type[-1] == '\0':  # Workaround for what looks like a pyjamas bug: the \0 should not be there, and
                 item_type = item_type[:-1]           # .strip('\0') and .replace('\0','') don't work. TODO: check this and fill a bug report
             # item_type = dt.getData("type")
-            print "message: %s" % item
-            print "type: %s" % item_type
+            log.debug("message: %s" % item)
+            log.debug("type: %s" % item_type)
         except:
-            print "no message found"
+            log.debug("no message found")
             item = '&nbsp;'
             item_type = None
         if item_type == "WIDGET":
             if not LiberviaDragWidget.current:
-                print "ERROR: No widget registered in LiberviaDragWidget !"
+                log.error("No widget registered in LiberviaDragWidget !")
                 return
             _new_panel = LiberviaDragWidget.current
             _new_panel.getWidgetsPanel().removeWidget(_new_panel)
         elif item_type in DropCell.drop_keys:
             _new_panel = DropCell.drop_keys[item_type](self.tab_panel.host, item)
         else:
-            print "WARNING: unmanaged item type"
+            log.warning("unmanaged item type")
             return
 
         widgets_panel = self.tab_panel.getWidget(self._getIndex())
@@ -700,7 +702,7 @@
         tab_panel_elt = self.getElement()
         _elts = doc().getElementsByClassName('gwt-TabBar')
         if not _elts.length:
-            print ("ERROR: no TabBar found, it should exist !")
+            log.error("no TabBar found, it should exist !")
             tab_bar_h = 0
         else:
             tab_bar_h = _elts.item(0).offsetHeight
--- a/browser_side/card_game.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/card_game.py	Thu May 08 17:21:34 2014 +0200
@@ -18,6 +18,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import pyjd  # this is dummy in pyjs
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.AbsolutePanel import AbsolutePanel
 from pyjamas.ui.DockPanel import DockPanel
 from pyjamas.ui.SimplePanel import SimplePanel
@@ -172,11 +174,11 @@
     def loadCards(self):
         """Load all the cards in memory"""
         def _getTarotCardsPathsCb(paths):
-            print "_getTarotCardsPathsCb"
+            log.debug("_getTarotCardsPathsCb")
             for file_ in paths:
-                print "path:", file_
+                log.debug("path:", file_)
                 card = CardWidget(self, file_)
-                print "card:", card
+                log.debug("card:", card)
                 self.cards[(card.suit, card.value)] = card
                 self.deck.append(card)
             self._parent.host.bridge.call('tarotGameReady', None, self.player_nick, self.referee)
@@ -277,7 +279,7 @@
         elif phase == "ecart":
             self.state = "ecart"
         else:
-            print 'INTERNAL ERROR: unmanaged game phase'
+            log.error("INTERNAL ERROR: unmanaged game phase") # FIXME: raise an exception here
 
         for suit, value in played_cards:
             self.hand.append(self.cards[(suit, value)])
@@ -317,15 +319,15 @@
         for location in ['top', 'left', 'bottom', 'right']:
             if getattr(self, '%s_nick' % location) == nick:
                 return location
-        print ("ERROR: This line should not be reached")
+        log.error("This line should not be reached")
 
     def tarotGameCardsPlayed(self, player, cards):
         """A card has been played by player"""
         if not len(cards):
-            print ("WARNING: cards should not be empty")
+            log.warning("cards should not be empty")
             return
         if len(cards) > 1:
-            print ("ERROR: can't manage several cards played")
+            log.error("can't manage several cards played")
         if self.to_show:
             self.to_show = []
             self.updateToShow()
--- a/browser_side/contact.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/contact.py	Thu May 08 17:21:34 2014 +0200
@@ -18,6 +18,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import pyjd  # this is dummy in pyjs
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.ScrollPanel import ScrollPanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
@@ -264,7 +266,7 @@
         classname = 'widgetsPanel' if isinstance(self.getParent().getParent(), UniBoxPanel) else'gwt-TabBar'
         _elts = doc().getElementsByClassName(classname)
         if not _elts.length:
-            print ("ERROR: no element of class %s found, it should exist !" % classname)
+            log.error("no element of class %s found, it should exist !" % classname)
             tab_bar_h = height
         else:
             tab_bar_h = DOM.getAbsoluteTop(_elts.item(0)) or height  # getAbsoluteTop can be 0 if tabBar is hidden
--- a/browser_side/dialog.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/dialog.py	Thu May 08 17:21:34 2014 +0200
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.VerticalPanel import VerticalPanel
 from pyjamas.ui.Grid import Grid
 from pyjamas.ui.HorizontalPanel import HorizontalPanel
@@ -117,9 +119,9 @@
         elif nb_contact is not None:
             nb_contact = (nb_contact, nb_contact)
         if nb_contact is None:
-            print "Need to select as many contacts as you want"
+            log.warning("Need to select as many contacts as you want")
         else:
-            print "Need to select between %d and %d contacts" % nb_contact
+            log.warning("Need to select between %d and %d contacts" % nb_contact)
         self.nb_contact = nb_contact
         self.ok_button = ok_button
         VerticalPanel.__init__(self, Width='100%')
--- a/browser_side/file_tools.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/file_tools.py	Thu May 08 17:21:34 2014 +0200
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.FileUpload import FileUpload
 from pyjamas.ui.FormPanel import FormPanel
 from pyjamas import Window
@@ -123,7 +125,7 @@
         if self.close_cb:
             self.close_cb()
         else:
-            print ("WARNING: no close method defined")
+            log.warning("no close method defined")
 
     def onSubmitBtnClick(self):
         if not self.file_upload.check():
--- a/browser_side/list_manager.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/list_manager.py	Thu May 08 17:21:34 2014 +0200
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.Grid import Grid
 from pyjamas.ui.Button import Button
 from pyjamas.ui.ListBox import ListBox
@@ -494,7 +496,7 @@
             sender.setVisibleLength(len(contact))
         except:
             # IndexSizeError: Index or size is negative or greater than the allowed amount
-            print "FIXME: len(%s) returns %d... javascript bug?" % (contact, len(contact))
+            log.warning("FIXME: len(%s) returns %d... javascript bug?" % (contact, len(contact)))
         self._parent.removeFromRemainingList(contact)
         self._last_textbox.setFocus(True)
         return True
--- a/browser_side/menu.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/menu.py	Thu May 08 17:21:34 2014 +0200
@@ -18,23 +18,20 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import pyjd  # this is dummy in pyjs
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.MenuBar import MenuBar
 from pyjamas.ui.MenuItem import MenuItem
-from pyjamas.ui.ListBox import ListBox
-from pyjamas.ui.Label import Label
-from pyjamas.ui.TextBox import TextBox
 from pyjamas.ui.HTML import HTML
 from pyjamas.ui.Frame import Frame
 from pyjamas import Window
 from jid import JID
-from html_tools import html_sanitize
 from file_tools import FileUploadPanel
 from xmlui import XMLUI
 from browser_side import panels
 from browser_side import dialog
 from contact_group import ContactGroupEditor
-import re
 from sat.core.i18n import _
 
 
@@ -100,7 +97,7 @@
 
         def addMenu(menu_name, menu_name_i18n, item_name_i18n, icon, menu_cmd):
             """ add a menu to menu_dict """
-            print "addMenu:", menu_name, menu_name_i18n, item_name_i18n, icon, menu_cmd
+            log.info("addMenu: %s %s %s %s %s" % (menu_name, menu_name_i18n, item_name_i18n, icon, menu_cmd))
             try:
                 menu_bar = menus_dict[menu_name]
             except KeyError:
@@ -120,16 +117,16 @@
         # additional menus
         for action_id, type_, path, path_i18n in add_menus:
             if not path:
-                print "WARNING: skipping menu without path"
+                log.warning("skipping menu without path")
                 continue
             if len(path) != len(path_i18n):
-                print "ERROR: inconsistency between menu paths"
+                log.error("inconsistency between menu paths")
                 continue
             menu_name = path[0]
             menu_name_i18n = path_i18n[0]
             item_name = path[1:]
             if not item_name:
-                print "WARNING: skipping menu with a path of lenght 1 [%s]" % path[0]
+                log.warning("skipping menu with a path of lenght 1 [%s]" % path[0])
                 continue
             item_name_i18n = ' | '.join(path_i18n[1:])
             addMenu(menu_name, menu_name_i18n, item_name_i18n, 'plugins', PluginMenuCmd(self.host, action_id))
@@ -169,7 +166,7 @@
     def onDisconnect(self):
         def confirm_cb(answer):
             if answer:
-                print "disconnection"
+                log.info("disconnection")
                 self.host.bridge.call('disconnect', None)
         _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to disconnect ?")
         _dialog.show()
--- a/browser_side/notification.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/notification.py	Thu May 08 17:21:34 2014 +0200
@@ -1,4 +1,6 @@
 from __pyjamas__ import JS, wnd
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas import Window
 from pyjamas.Timer import Timer
 from browser_side import dialog
@@ -60,22 +62,22 @@
             version_full = [s for s in self.user_agent.split() if "Chrome" in s][0].split('/')[1]
             version = int(version_full.split('.')[0])
         except (IndexError, ValueError):
-            print "Can't find Chromium version"
+            log.warning("Can't find Chromium version")
             version = 0
-        print "Chromium version: %d" % (version,)
+        log.info("Chromium version: %d" % (version,))
         if version < 22:
-            print "Notification use the old prefixed version or are unmanaged"
+            log.info("Notification use the old prefixed version or are unmanaged")
             return
         if version < 32:
             dialog.InfoDialog(_("Notifications activation for Chromium"), _('You need to activate notifications manually for your Chromium version.<br/>To activate notifications, click on the favicon on the left of the address bar')).show()
             return
 
-        print "==> Installing Chromium notifications request workaround <=="
+        log.info("==> Installing Chromium notifications request workaround <==")
         self._old_click = wnd().onclick
         wnd().onclick = self._chromiumWorkaround
 
     def _chromiumWorkaround(self):
-        print "Activating workaround"
+        log.info("Activating workaround")
         JS("""
             Notification.requestPermission(function(permission){
                 if (permission !== 'granted')
--- a/browser_side/panels.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/panels.py	Thu May 08 17:21:34 2014 +0200
@@ -18,6 +18,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import pyjd  # this is dummy in pyjs
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.AbsolutePanel import AbsolutePanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
@@ -187,7 +189,7 @@
         try:
             self.getCompletionItems().completions.remove(key)
         except KeyError:
-            print "WARNING: trying to remove an unknown key"
+            log.warning("trying to remove an unknown key")
 
     def _getTarget(self, txt):
         """ Say who will receive the messsage
@@ -227,7 +229,7 @@
                     msg = MicroblogPanel.warning_msg_group % group
                     target_hook = (txt[_end + 2:], group)
         else:
-            print "ERROR: Unknown target"
+            log.error("Unknown target")
             target_hook, _type, msg = getSelectedOrStatus()
 
         return (target_hook, _type, msg)
@@ -317,7 +319,7 @@
         if type_ == "NONE":
             return
         if not msg:
-            print "WARNING: no msg set uniBox warning"
+            log.warning("no msg set uniBox warning")
             return
         if type_ == "PUBLIC":
             style = "targetPublic"
@@ -328,7 +330,7 @@
         elif type_ == "ONE2ONE":
             style = "targetOne2One"
         else:
-            print "ERROR: unknown message type"
+            log.error("unknown message type")
             return
         contents = HTML(msg)
 
@@ -585,7 +587,7 @@
                 }
         entry = self._blog_panel.addEntry(data)
         if entry is None:
-            print "The entry of id %s can not be commented" % self.id
+            log.info("The entry of id %s can not be commented" % self.id)
             return
         entry._parent_entry = self
         self._current_comment = entry
@@ -733,7 +735,7 @@
         @return: a couple (type, msg) for calling self.host.showWarning"""
         if comment is None:  # composing from the unibox
             if self.selected_entry and not self.selected_entry.comments:
-                print ("ERROR: an item without comment is selected")
+                log.error("an item without comment is selected")
                 return ("NONE", None)
             comment = self.selected_entry is not None
         if comment:
@@ -773,12 +775,12 @@
         """Insert several microblogs at once
         @param mblogs: dictionary of microblogs, as the result of getMassiveLastGroupBlogs
         """
-        print "Massive insertion of %d microblogs" % len(mblogs)
+        log.debug("Massive insertion of %d microblogs" % len(mblogs))
         for publisher in mblogs:
-            print "adding blogs for [%s]" % publisher
+            log.debug("adding blogs for [%s]" % publisher)
             for mblog in mblogs[publisher]:
                 if not "content" in mblog:
-                    print ("WARNING: No content found in microblog [%s]", mblog)
+                    log.warning("No content found in microblog [%s]", mblog)
                     continue
                 self.addEntry(mblog)
 
@@ -788,7 +790,7 @@
         """
         for mblog in mblogs:
             if not "content" in mblog:
-                print ("WARNING: No content found in microblog [%s]", mblog)
+                log.warning("No content found in microblog [%s]", mblog)
                 continue
             self.addEntry(mblog)
 
@@ -897,7 +899,7 @@
         try:
             self.vpanel.getParent().ensureVisible(entry)  # scroll to the clicked entry
         except AttributeError:
-            print "FIXME: MicroblogPanel.vpanel should be wrapped in a ScrollPanel!"
+            log.warning("FIXME: MicroblogPanel.vpanel should be wrapped in a ScrollPanel!")
         removeStyle = lambda entry: entry.removeStyleName('selected_entry')
         if not self.host.uni_box or not entry.comments:
             entry.addStyleName('selected_entry')  # blink the clicked entry
@@ -912,7 +914,7 @@
         if self.selected_entry:
             removeStyle(self.selected_entry)
         if entry:
-            print "microblog entry selected (author=%s)" % entry.author
+            log.debug("microblog entry selected (author=%s)" % entry.author)
             entry.addStyleName('selected_entry')
         self.selected_entry = entry
 
@@ -1064,7 +1066,7 @@
         self.type = type_
         self.nick = None
         if not target:
-            print "ERROR: Empty target !"
+            log.error("Empty target !")
             return
         self.target = target
         self.__body = AbsolutePanel()
@@ -1236,7 +1238,7 @@
         attr = "%s_panel" % attr
         if hasattr(self, attr):
             return
-        print ("%s Game Started \o/" % game_type)
+        log.info("%s Game Started \o/" % game_type)
         panel = classes[game_type](self, referee, self.nick, players, *args)
         setattr(self, attr, panel)
         self.vpanel.insert(panel, 0)
--- a/browser_side/radiocol.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/radiocol.py	Thu May 08 17:21:34 2014 +0200
@@ -18,6 +18,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import pyjd  # this is dummy in pyjs
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.VerticalPanel import VerticalPanel
 from pyjamas.ui.HorizontalPanel import HorizontalPanel
 from pyjamas.ui.FlexTable import FlexTable
@@ -198,7 +200,7 @@
         self.album = album
         self.played = False
         self.setSrc("radiocol/%s" % html_sanitize(filename))
-        print "preloading %s in %s" % (title, self._id)
+        log.debug("preloading %s in %s" % (title, self._id))
 
     def play(self, play=True):
         """Play or pause the song
@@ -291,7 +293,7 @@
                 preloaded = True
                 break
         if not preloaded:
-            print(_("WARNING: Can't preload song, we are getting too many songs to preload, we shouldn't have more than %d at once") % self.queue_data[1])
+            log.warning("Can't preload song, we are getting too many songs to preload, we shouldn't have more than %d at once" % self.queue_data[1])
         else:
             self.pushNextSong(title)
             self._parent.printInfo(_('%(user)s uploaded %(artist)s - %(title)s') % {'user': sender, 'artist': artist, 'title': title})
@@ -307,7 +309,7 @@
             else:
                 player.play(False)  # in case the previous player was not sync
         if not found:
-            print("WARNING: Song not found in queue, can't play it. This should not happen")
+            log.error("Song not found in queue, can't play it. This should not happen")
 
     def radiocolNoUpload(self):
         self.control_panel.blockUpload()
--- a/browser_side/xmlui.py	Thu May 08 17:21:30 2014 +0200
+++ b/browser_side/xmlui.py	Thu May 08 17:21:34 2014 +0200
@@ -17,13 +17,13 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from pyjamas.ui.VerticalPanel import VerticalPanel
 from pyjamas.ui.HorizontalPanel import HorizontalPanel
-from pyjamas.ui.CellPanel import CellPanel
 from pyjamas.ui.TabPanel import TabPanel
 from pyjamas.ui.Grid import Grid
 from pyjamas.ui.Label import Label
-from pyjamas.ui.TextBoxBase import TextBoxBase
 from pyjamas.ui.TextBox import TextBox
 from pyjamas.ui.PasswordTextBox import PasswordTextBox
 from pyjamas.ui.TextArea import TextArea
@@ -33,7 +33,6 @@
 from pyjamas.ui.HTML import HTML
 from nativedom import NativeDOM
 from sat_frontends.tools import xmlui
-from sat.core.i18n import _
 
 
 class EmptyWidget(xmlui.EmptyWidget, Label):
@@ -168,7 +167,7 @@
         try:
             label = [label for label, _value in self._xmlui_attr_map.items() if _value == value][0]
         except IndexError:
-            print(_("WARNING: Can't find value [%s] to select" % value))
+            log.warning("Can't find value [%s] to select" % value)
             return
         self.selectItem(label)
 
@@ -223,7 +222,7 @@
         try:
             self._xmlui_select_cb(self)
         except AttributeError:
-            print "WARNING: no select callback set"
+            log.warning("no select callback set")
 
 
     def _xmluiAppend(self, widget):
@@ -392,7 +391,7 @@
         if self.close_cb:
             self.close_cb()
         else:
-            print "WARNING: no close method defined"
+            log.warning("no close method defined")
 
     def _xmluiLaunchAction(self, action_id, data):
         self.host.launchAction(action_id, data)
--- a/libervia.py	Thu May 08 17:21:30 2014 +0200
+++ b/libervia.py	Thu May 08 17:21:34 2014 +0200
@@ -18,6 +18,20 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import pyjd  # this is dummy in pyjs
+
+from constants import Const as C
+### logging configuration ###
+from sat.core.log import configure, getLogger
+configure(C.LOG_BACKEND_BASIC,
+          level = C.LOG_LVL_DEBUG,
+          fmt = '[%(name)s / %(levelname)s] %(message)s',
+          output = None,
+          logger = None,
+          colors = False,
+          force_colors = False)
+log = getLogger(__name__)
+###
+
 from pyjamas.ui.RootPanel import RootPanel
 from pyjamas.ui.HTML import HTML
 from pyjamas.ui.KeyboardListener import KEY_ESCAPE
@@ -37,7 +51,6 @@
 
 from sat_frontends.tools.misc import InputHistory
 from sat_frontends.tools.strings import getURLParams
-from constants import Const as C
 from sat.core.i18n import _
 
 
@@ -63,7 +76,7 @@
         if cb:
             if isinstance(cb, tuple):
                 if len(cb) != 2:
-                    print ("ERROR: tuple syntax for bridge.call is (callback, errback), aborting")
+                    log.error("tuple syntax for bridge.call is (callback, errback), aborting")
                     return
                 if cb[0] is not None:
                     self.cb[_id] = cb[0]
@@ -98,14 +111,14 @@
             del self.eb[request_info.id]
         else:
             if code != 0:
-                print ("Internal server error")
+                log.error("Internal server error")
                 """for o in code, error, request_info:
                     dump(o)"""
             else:
                 if isinstance(errobj['message'], dict):
-                    print("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString']))
+                    log.error("Error %s: %s" % (errobj['message']['faultCode'], errobj['message']['faultString']))
                 else:
-                    print("Error: %s" % errobj['message'])
+                    log.error("%s" % errobj['message'])
 
 
 class RegisterCall(LiberviaJsonProxy):
@@ -159,7 +172,7 @@
 
 class SatWebFrontend(InputHistory):
     def onModuleLoad(self):
-        print "============ onModuleLoad =============="
+        log.info("============ onModuleLoad ==============")
         panels.ChatPanel.registerClass()
         panels.MicroblogPanel.registerClass()
         self.whoami = None
@@ -201,7 +214,7 @@
     def getSelected(self):
         wid = self.tab_panel.getCurrentPanel()
         if not isinstance(wid, WidgetsPanel):
-            print "ERROR: Tab widget is not a WidgetsPanel, can't get selected widget"
+            log.error("Tab widget is not a WidgetsPanel, can't get selected widget")
             return None
         return wid.selected
 
@@ -263,14 +276,14 @@
         return self.avatars_cache[jid_str]
 
     def registerWidget(self, wid):
-        print "Registering", wid.getDebugName()
+        log.debug("Registering %s" % wid.getDebugName())
         self.libervia_widgets.add(wid)
 
     def unregisterWidget(self, wid):
         try:
             self.libervia_widgets.remove(wid)
         except KeyError:
-            print ('WARNING: trying to remove a non registered Widget:', wid.getDebugName())
+            log.warning('trying to remove a non registered Widget: %s' % wid.getDebugName())
 
     def refresh(self):
         """Refresh the general display."""
@@ -346,7 +359,7 @@
 
         def domain_cb(value):
             self._defaultDomain = value
-            print("new account domain: %s" % value)
+            log.info("new account domain: %s" % value)
 
         def domain_eb(value):
             self._defaultDomain = "libervia.org"
@@ -419,7 +432,7 @@
 
     def _getSignalsCB(self, signal_data):
         self.bridge_signals.call('getSignals', self._getSignalsCB)
-        print('Got signal ==> name: %s, params: %s' % (signal_data[0], signal_data[1]))
+        log.debug("Got signal ==> name: %s, params: %s" % (signal_data[0], signal_data[1]))
         name, args = signal_data
         if name == 'personalEvent':
             self._personalEventCb(*args)
@@ -490,7 +503,7 @@
         for publisher in mblogs:
             for mblog in mblogs[publisher]:
                 if not mblog.has_key('content'):
-                    print ("WARNING: No content found in microblog [%s]", mblog)
+                    log.warning("No content found in microblog [%s]" % mblog)
                     continue
                 if mblog.has_key('groups'):
                     _groups = set(mblog['groups'].split() if mblog['groups'] else [])
@@ -537,7 +550,7 @@
         sender = JID(sender).bare
         if event_type == "MICROBLOG":
             if not 'content' in data:
-                print ("WARNING: No content found in microblog data")
+                log.warning("No content found in microblog data")
                 return
             if 'groups' in data:
                 _groups = set(data['groups'].split() if data['groups'] else [])
@@ -567,7 +580,8 @@
             for lib_wid in self.libervia_widgets:
                 if isinstance(lib_wid, panels.MicroblogPanel):
                     lib_wid.removeEntry(data['type'], data['id'])
-            print self.whoami.bare, sender, data['type']
+            log.debug("%s %s %s" % (self.whoami.bare, sender, data['type']))
+
             if sender == self.whoami.bare and data['type'] == 'main_item':
                 for index in xrange(0, len(self.mblog_cache)):
                     entry = self.mblog_cache[index]
@@ -595,7 +609,7 @@
             self.addBlogEntry(mblog_panel, self.whoami.bare, *cache_entry)
 
     def getEntityMBlog(self, entity):
-        print "geting mblog for entity [%s]" % (entity,)
+        log.info("geting mblog for entity [%s]" % (entity,))
         for lib_wid in self.libervia_widgets:
             if isinstance(lib_wid, panels.MicroblogPanel):
                 if lib_wid.isJidAccepted(entity):
@@ -617,7 +631,7 @@
             if isinstance(lib_wid, class_):
                 try:
                     if lib_wid.matchEntity(entity):
-                        print "existing widget found: %s" % lib_wid.getDebugName()
+                        log.debug("existing widget found: %s" % lib_wid.getDebugName())
                         return lib_wid
                 except AttributeError as e:
                     e.stack_list()
@@ -844,7 +858,7 @@
     def sendError(self, errorData):
         dialog.InfoDialog("Error while sending message",
                           "Your message can't be sent", Width="400px").center()
-        print "sendError: %s" % str(errorData)
+        log.error("sendError: %s" % str(errorData))
 
     def send(self, targets, text, extra={}):
         """Send a message to any target type.
@@ -868,7 +882,7 @@
             elif type_ in ("groupchat", "chat"):
                 addresses.append((addr, entities))
             else:
-                print "ERROR: Unknown target type"
+                log.error("Unknown target type")
         if addresses:
             if len(addresses) == 1 and addresses[0][0] == 'to':
                 self.bridge.call('sendMessage', (None, self.sendError), addresses[0][1], text, '', type_, extra)