comparison src/plugins/plugin_misc_xmllog.py @ 993:301b342c697a

core: use of the new core.log module: /!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author Goffi <goffi@goffi.org>
date Sat, 19 Apr 2014 19:19:19 +0200
parents bfabeedbf32e
children aa60bd58ac23
comparison
equal deleted inserted replaced
992:f51a1895275c 993:301b342c697a
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from logging import debug, info, error 21 from sat.core.log import getLogger
22 log = getLogger(__name__)
22 from twisted.words.protocols.jabber.xmlstream import XmlStream 23 from twisted.words.protocols.jabber.xmlstream import XmlStream
23 from twisted.words.xish import domish 24 from twisted.words.xish import domish
24 25
25 PLUGIN_INFO = { 26 PLUGIN_INFO = {
26 "name": "Raw XML log Plugin", 27 "name": "Raw XML log Plugin",
41 if isinstance(obj, basestring): 42 if isinstance(obj, basestring):
42 log = unicode(obj) 43 log = unicode(obj)
43 elif isinstance(obj, domish.Element): 44 elif isinstance(obj, domish.Element):
44 log = obj.toXml() 45 log = obj.toXml()
45 else: 46 else:
46 error(_('INTERNAL ERROR: Unmanaged XML type')) 47 log.error(_('INTERNAL ERROR: Unmanaged XML type'))
47 self._host.bridge.xmlLog("OUT", log, self._profile) 48 self._host.bridge.xmlLog("OUT", log, self._profile)
48 return XmlStream.send(self, obj) 49 return XmlStream.send(self, obj)
49 50
50 def dataReceived(self, data): 51 def dataReceived(self, data):
51 self._host.bridge.xmlLog("IN", data.decode('utf-8'), self._profile) 52 self._host.bridge.xmlLog("IN", data.decode('utf-8'), self._profile)
63 </general> 64 </general>
64 </params> 65 </params>
65 """ % {"label_xmllog": _("Activate XML log")} 66 """ % {"label_xmllog": _("Activate XML log")}
66 67
67 def __init__(self, host): 68 def __init__(self, host):
68 info(_("Plugin XML Log initialization")) 69 log.info(_("Plugin XML Log initialization"))
69 self.host = host 70 self.host = host
70 71
71 #parameters 72 #parameters
72 host.memory.updateParams(self.params) 73 host.memory.updateParams(self.params)
73 74
74 #bridge 75 #bridge
75 host.bridge.addSignal("xmlLog", ".plugin", signature='sss') # args: direction("IN" or "OUT"), xml_data, profile 76 host.bridge.addSignal("xmlLog", ".plugin", signature='sss') # args: direction("IN" or "OUT"), xml_data, profile
76 77
77 do_log = self.host.memory.getParamA("Xml log", "Debug") 78 do_log = self.host.memory.getParamA("Xml log", "Debug")
78 if do_log: 79 if do_log:
79 info(_("XML log activated")) 80 log.info(_("XML log activated"))
80 host.trigger.add("XML Initialized", self.logXml) 81 host.trigger.add("XML Initialized", self.logXml)
81 82
82 def logXml(self, xmlstream, profile): 83 def logXml(self, xmlstream, profile):
83 xmlstream.__class__ = LoggingXmlStream 84 xmlstream.__class__ = LoggingXmlStream
84 xmlstream._profile = profile 85 xmlstream._profile = profile