Problem logging with variable placeholders

Robin Dunn <robin@alldunn.com> writes:

Are you sure?

I'm not. I've been looking at my SVN logs and tracing back to when I
updated wxPython... I added this after the upgrade. :-\ I think that
since everything was working I hadn't seen that befor.

The % character is significant to the log functions because they will
try to C-style printf expansion on them too, so since there is a %s or
a %d still in the string passed to wx.LogVerbose it is going to take
whatever garbage is on the stack and substitute it into the output.

So there are no means to make it different? I'm thinking about using
Python's logging module instead of wxPython's wx.Log... It works there,
and it looks to me that it is easier to make a few customizations I was
thinking about.

Is it easy to make wx.Log* receive data from a stream? I could, then,
make errors and other stuff appears on dialog boxes with wxPython's
classes and write to sys.stderr/syslog with Python's classes...

···

--
Godoy. <godoy@ieee.org>

Jorge Godoy wrote:

Robin Dunn <robin@alldunn.com> writes:

Are you sure?

I'm not. I've been looking at my SVN logs and tracing back to when I
updated wxPython... I added this after the upgrade. :-\ I think that
since everything was working I hadn't seen that befor.

The % character is significant to the log functions because they will
try to C-style printf expansion on them too, so since there is a %s or
a %d still in the string passed to wx.LogVerbose it is going to take
whatever garbage is on the stack and substitute it into the output.

So there are no means to make it different? I'm thinking about using
Python's logging module instead of wxPython's wx.Log... It works there,
and it looks to me that it is easier to make a few customizations I was
thinking about.

I'm tweaking the wx.Log* function wrappers to double any '%' characters found in the message string. That should correct the problem. You could temporarily do the same thing yourself before passing the string to wx.LogVerbose.

Is it easy to make wx.Log* receive data from a stream? I could, then,
make errors and other stuff appears on dialog boxes with wxPython's
classes and write to sys.stderr/syslog with Python's classes...

It may be possible, but it would probably be easier (and certainly more pythonic) to create a handler for the Python logging framework that is able to put deal with the error dialogs like the wxLog framework does.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!