wxPyLog and filtering

I tried using wxPyLog to filter out verbose logs (ie all non-verbose logs should go to all active loggers, but the verbose messages should only go to one log). I tried with the following, but this lets everything through. Am I going about this the right way? Or perhaps this is not even possible in wxwidgets.

class SpecialGUILog(wx.PyLog):
def init(self, winLog):
wx.PyLog.init(self)
self.winLog = winLog

def DoLog(self, level, msg, timestamp):
    print level
    if level < 5:
        self.winLog.PassMessages(True)
    else:
        self.winLog.PassMessages(False)

class MyApp(wx.App):

def OnInit(self):
        wx.InitAllImageHandlers()

        guiLog = wx.LogGui()
        winLog = wx.LogWindow(None, "TEST")
        specLog = SpecialGUILog(winLog)

        wx.Log_SetActiveTarget(guiLog)
        chain1 = wx.LogChain(winLog)
        chain2 = wx.LogChain(specLog)

        wx.LogMessage("Log message")
        wx.Log_SetVerbose()

        # following message should show up only in winLog:
        wx.LogVerbose("Verbose message")

Thanks,

Oliver

···

Oliver Schoenborn wrote:

I tried using wxPyLog to filter out verbose logs (ie all non-verbose logs should go to all active loggers, but the verbose messages should only go to one log). I tried with the following, but this lets everything through. Am I going about this the right way? Or perhaps this is not even possible in wxwidgets.
class SpecialGUILog(wx.PyLog):
    def __init__(self, winLog):
        wx.PyLog.__init__(self)
        self.winLog = winLog
           def DoLog(self, level, msg, timestamp):
        print level
        if level < 5:
            self.winLog.PassMessages(True)
        else:
            self.winLog.PassMessages(False)
           
        def OnInit(self):
            wx.InitAllImageHandlers()
            guiLog = wx.LogGui()
            winLog = wx.LogWindow(None, "TEST")
            specLog = SpecialGUILog(winLog)
            wx.Log_SetActiveTarget(guiLog)
            chain1 = wx.LogChain(winLog)
            chain2 = wx.LogChain(specLog)
            wx.LogMessage("Log message")
            wx.Log_SetVerbose()
            # following message should show up only in winLog:
            wx.LogVerbose("Verbose message")

The wx.LogWindow chains itself to the log that is active at the time it is created, so you want to set the active log target before creating it. Also I think that the PassMessages method only affects subsequent messages, not the current one. Try it like this and see what kind of difference you get:

         guiLog = wx.LogGui()
         wx.Log_SetActiveTarget(guiLog)
         winLog = wx.LogWindow(None, "TEST")
         specLog = SpecialGUILog(winLog)
         #chain1 = wx.LogChain(winLog)
         chain2 = wx.LogChain(specLog)
         wx.LogMessage("Log message")
         wx.Log_SetVerbose()
         # following message should show up only in winLog:
         wx.LogVerbose("Verbose message")
         wx.LogVerbose("Verbose message 2")
         wx.LogMessage("Log message 2")

···

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

Robin,

From: Robin Dunn [mailto:robin@alldunn.com]
Sent: February 3, 2006 1:25 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] wxPyLog and filtering

Oliver Schoenborn wrote:
> I tried using wxPyLog to filter out verbose logs (ie all non-verbose
> logs should go to all active loggers, but the verbose messages should
> only go to one log). I tried with the following, but this lets
> everything through. Am I going about this the right way? Or perhaps
> this is not even possible in wxwidgets.
>
> ...

The wx.LogWindow chains itself to the log that is active at
the time it is created, so you want to set the active log
target before creating it.
  Also I think that the PassMessages method only affects
subsequent messages, not the current one.

Correct, so the below code failed too.

Try it like this
and see what kind of difference you get:

         guiLog = wx.LogGui()
         wx.Log_SetActiveTarget(guiLog)
         winLog = wx.LogWindow(None, "TEST")
         specLog = SpecialGUILog(winLog)
         chain2 = wx.LogChain(specLog)
         wx.LogMessage("Log message")
         wx.Log_SetVerbose()
         # following message should show up only in winLog:
         wx.LogVerbose("Verbose message")
         wx.LogVerbose("Verbose message 2")
         wx.LogMessage("Log message 2")

However, it's almost working with the following code:

class SpecialGUILog(wx.PyLog):
    def DoLog(self, level, msg, timestamp):
        if level < 5:
            oldAct = wx.Log_SetActiveTarget(self.guiLog)
            wx.LogGeneric(level, msg)
            wx.Log_SetActiveTarget(oldAct)

specLog = SpecialGUILog(True)
wx.Log_SetActiveTarget(specLog)
winLog = wx.LogWindow(None, "TEST")
guiLog = wx.LogGui()
specLog.guiLog = guiLog
wx.Log_SetVerbose()
# only the LogMessage msgs should appear in guiLog:
wx.LogVerbose("Verbose message 1")
wx.LogMessage("Log message 1")
wx.LogVerbose("Verbose message 2")
wx.LogMessage("Log message 2")

The only problem is that the above sequence of messages would normally (i.e.
without filtering) cause guiLog to show the last message only, and a
"Details->" button to become available to see all four messages, but with
the above filtering technique this does not happen: four separate guiLog
windows will open, in sequence, beacause guiLog gets Flush()'d at each call
to SetActiveTarget().

I tried having DoLogString save the messages in a list, and override
SpecialGUILog.Flush(self), but this method doesn't seem to ever get called.
Perhaps wxPyLog doesn't properly handle Flush() override.

The only other way I can think of would be for you Robin to create a
wxPyLogGui so that its DoLog() could be overriden (e.g., to not forward to
DoLogString() if verbose message).

Oliver

···

-----Original Message-----

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

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org

Oliver Schoenborn wrote:

The only problem is that the above sequence of messages would normally (i.e.
without filtering) cause guiLog to show the last message only, and a
"Details->" button to become available to see all four messages, but with
the above filtering technique this does not happen: four separate guiLog
windows will open, in sequence, beacause guiLog gets Flush()'d at each call
to SetActiveTarget().

I tried having DoLogString save the messages in a list, and override
SpecialGUILog.Flush(self), but this method doesn't seem to ever get called.
Perhaps wxPyLog doesn't properly handle Flush() override.

No, it doesn't virtualize it.

The only other way I can think of would be for you Robin to create a
wxPyLogGui so that its DoLog() could be overriden (e.g., to not forward to
DoLogString() if verbose message).

Or you could create your own class derived from wx.PyLog that behaves like wx.LogGui.

···

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

From: Robin Dunn [mailto:robin@alldunn.com]

Oliver Schoenborn wrote:

>
> The only problem is that the above sequence of messages would normally

(i.e.

> without filtering) cause guiLog to show the last message only, and a
> "Details->" button to become available to see all four messages, but
> with the above filtering technique this does not happen: four separate
> guiLog windows will open, in sequence, beacause guiLog gets Flush()'d
> at each call to SetActiveTarget().
>
> I tried having DoLogString save the messages in a list, and override
> SpecialGUILog.Flush(self), but this method doesn't seem to ever get

called.

> Perhaps wxPyLog doesn't properly handle Flush() override.

No, it doesn't virtualize it.

>
> The only other way I can think of would be for you Robin to create a
> wxPyLogGui so that its DoLog() could be overriden (e.g., to not forward

to

> DoLogString() if verbose message).

Or you could create your own class derived from wx.PyLog that
behaves like wx.LogGui.

No, because that would require properly virtualized Flush(). I guess I could
take a look at the source and figure out where you do this, but wouldn't it
be a matter of a minute for you to the patch? Is there any reason why you
wouldn't virtualize it?

Oliver

···

-----Original Message-----

Oliver Schoenborn wrote:

Or you could create your own class derived from wx.PyLog that behaves like wx.LogGui.

No, because that would require properly virtualized Flush(). I guess I could
take a look at the source and figure out where you do this, but wouldn't it
be a matter of a minute for you to the patch? Is there any reason why you
wouldn't virtualize it?

I'll check into it.

···

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