Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

raw xml stream #29

Closed
Jajcus opened this issue May 3, 2011 · 1 comment
Closed

raw xml stream #29

Jajcus opened this issue May 3, 2011 · 1 comment

Comments

@Jajcus
Copy link
Owner

Jajcus commented May 3, 2011

hi, I'm looking some way to monitor raw xml stream, and noticed that in changelog of 2003:

2003-08-08 08:02 +0000 [r96] Jacek Konieczny jajcus@jajcus.net
* pyxmpp/stream.py:
- data_in() and data_out() methods to override for 'raw XML
console'

but data_in() and data_out methods are missing in the new version.
How can I monitor the raw xml stream?

@Jajcus
Copy link
Owner Author

Jajcus commented May 3, 2011

Now the XML streams are logged using the Python standard 'logging' module -- the data is fed to the 'pyxmpp.Stream.in' and 'pyxmpp.Stream.out' loggers:

Here is sample code printing stream data (based on CJC 'xmlconsole' module):

{{{
#!python
import logging

class DataInHandler(logging.Handler):
def init(self):
logging.Handler.init(self, level = logging.DEBUG)
def emit(self, record):
data=record.args[0]
if not data or data in (" ", "\n"):
# skip keepalive data (but we are not sure it is keepalive)
return
print "IN:", record.args[0]

class DataOutHandler(logging.Handler):
def init(self):
logging.Handler.init(self, level = logging.DEBUG)
def emit(self, record):
data = record.args[0]
if not data or data in (" ", "\n"):
# skip keepalive data (but we are not sure it is keepalive)
return
print "OUT:", record.args[0]

data_in_handler=DataInHandler()
data_out_handler=DataOutHandler()
logging.getLogger("pyxmpp.Stream.in").addHandler(data_in_handler)
logging.getLogger("pyxmpp.Stream.out").addHandler(data_out_handler)
}}}

--jajcus

@Jajcus Jajcus closed this as completed May 3, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant