How to change wx.Log formatter?

I’ve tried following solution, but it exited with “segmentation fault”.What’s the correct way of setting log formatter ?

wxPython version: 4.0.6
Python version: 3.7.5

class MyLogFormatter(wx.LogFormatter):
    def Format(self, level, msg, info):
        return "[%d] %s(%d) : %s" % (info.threadId, info.filename, info.line, msg)

if __name__ == "__main__":
    app = wx.App()
    
    frame = wx.Frame(None, title="hello")
    frame.Show()

    log = wx.LogStderr()
    log.SetFormatter(MyLogFormatter())
    wx.Log.SetActiveTarget(log)

    wx.LogMessage('hello')

    app.MainLoop()

There’s probably an object ownership transfer that’s not being handled correctly in the wrappers. I’ll need to do some digging to figure this one out.

In the meantime, if you hold a reference to your formatter class then it doesn’t crash.

See https://github.com/wxWidgets/Phoenix/issues/1456