On Fri, Mar 23, 2012 at 4:32 PM, Phil Charlesworth <[email protected]> wrote: > On 23/03/12 10:03, Peter Bittner wrote: >> Phil, >> >> thanks for the testing. >> >> What I have noticed is that the logging module works with Pyjamas >> Desktop, unfortunately it doesn't work quite that well with pyjs. I >> hope I'll have some time in the evenings this weekend to look into >> this more closely. >> >> 2012/3/22 Phil Charlesworth<[email protected]>: >> >>> I've done a bit of very rudimentary testing of the various handlers >>> under pyjd on Windows >>> (just AlertLogger, AppendLogger and PrintLogger and everything seemed to >>> work. Just one comment. AlertLogger and PrintLogger (and, no doubt, >>> ConsoleLogger all work with text but AppendLogger is treating the >>> message as HTML. So, if the record is something like >>> <Sink.SinkInfo instance at 0x04C5CD28> it doesn't come out. Maybe >>> AppendHandler needs to call an escape function to turn things that are >>> special characters to HTML into their equivalent HTML entities. >>> >> That's strange: The message itself is not modified much, just that >> line feeds are replaced by br tags: >> >> (pyjamas/library/pyjamas/logging/handlers.py, class AppendHandler) >> def emit(self, record): >> msg = self.format(record) >> msg = msg.replace("\n", "<br/>\n") + "<br/>\n" >> self.output += msg >> self.__addLogElement() >> DOM.setInnerHTML(self.div, self.output) >> >> Peter > Peter, > Just to clarify what I said about AppendHandler, the whole > message is rendered as HTML, so if you have, say, <Sink.SinkInfo > instance at 0x04C5CD28>, it looks like an HTML tag but the renderer > can't make sense of it so it leaves it out. I have made my version work > by adding the two lines > msg = msg.replace("<","<") > msg = msg.replace(">",">")
err.... those are i believe in cgi.escape, already. or something like it. > before the line where you replace "\n" by "<br/>\n". > However, all those replace calls and any other ones deemed necessary, or > desirable, could be put into one escape routine, so that you had: > msg = format(record) > self.output += escape(msg) > > Another way would be to have a dictionary with keys being characters to > be replaced and values being the replacement character. Then something like: > def escape(text): > return "".join(escape_dict.get(c,c) for c in text) > will work in cPython. (not sure if it works in pyjs - would have to check) should do. if not, that's a bug in pyjs, and the above code-snippet should go into libtest. l.

