Wx.log attach custom PyLog, but warnings go to default LogGui, display modal

Hello users,
With wxpython 3.0.2 and py27 I am trying to send log messages to my own handler. However after attaching my handler, messages to wx.log create modal error dialogs anyway (as if I had not set a custom log target).

import os, sys

import time

import wx

class CustLogHandler(wx.PyLog):

“”" Custom log target. My understanding is only one of DoLogRecord

and DoLogTextAtLevel are needed. But for debug, I have tried with both

“”"

def DoLogRecord(self, level, msg, info=None):

print(’=] dologrecord processing record: %s’ % msg)

def DoLogTextAtLevel(self, level, msg, info=None):

print(’=] dologtext processing text: %s’ % msg)

if name == ‘main’:

Setup logging options

wx.Log.SetActiveTarget(CustLogHandler())

wx.Log.SetTimestamp(’%Y-%m-%d %H:%M:%S’)

wx.Log.SetLogLevel(wx.LOG_Debug)

APP = wx.App(False)

frame = wx.Frame(None, title=“Some frame. Close me.”)

Create dummy warning log entry.

wx.LogWarning(‘Some warning log. Should go to CustLogHandler.’)

Above call will cause gui “error” dialog to be shown and CustLogHandler does not receive message.

frame.Show()

APP.MainLoop()

print(‘Main exiting.’)

If you run the above(/attached) demo code, you will see the dummy log message pops up in a gui “error” dialog. I would expect the message to go to the CustLogHandler I have attached with SetActiveTarget, but this does not happen.

Where have I gone wrong here?

Thanks,

Colin

wx_logtarget_dbg.py (995 Bytes)

My way is to disable the wx log at all, and to use ‘logging’, which is the default python library

The subtle problem here is that the logging is not initialized until you
create the app. The wx.App call sets up the initial logging, overriding
your setup. If you move the wx.App constructor to be first, your
example works as you expect.

···

wammoth.mooly@gmail.com wrote:

With wxpython 3.0.2 and py27 I am trying to send log messages to my
own handler. However after attaching my handler, messages to wx.log
create modal error dialogs anyway (as if I had not set a custom log
target).

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.