Skip to main content

History: Catch LogMessages in MOGRE

Source of version: 3 (current)

Copy to clipboard
            This snippet shows, how to catch entries of the logfile.

So it's possible to process all log entries of the Ogre engine.

Usage examples:
* Create a second logfile where only errors and warnings will be logged
* Create a second logfile with HTML style where all entries are marked up 

{DL()}
(Somewhere in the forum was a C++ code to do this job. If somebody find it, pleas add it here.)
{DL}

* Show ogre messages in application

((MOGRE|Mogre)) is partially diffrent to Ogre. The result is looking easy, but the way to get it was stony. I lost much time to find out how to do. So I show the code. Maybe it can help other Mogre users. --((User:Beauty|Beauty))

Look for the line of creating root and add the event handler after this

{CODE(wrap="1", colors="c#")} root = new Root(...);
 root.FrameStarted += new FrameListener.FrameStartedHandler(FrameStarted);
 
 // add this line here:
 LogManager.Singleton.DefaultLog.MessageLogged += new LogListener.MessageLoggedHandler(DefaultLog_MessageLogged);{CODE}

Then add this method somewhere in the same class. It will be called for every log entry.

{CODE(wrap="1", colors="c#")} void DefaultLog_MessageLogged(string message, LogMessageLevel lml, bool maskDebug, string logName)
 {
     // do something
     // e.g. add messages to an ArrayList or show special messages in a window.
 }{CODE}

!!Add message to Ogre log
On the other hand you also can add entries to the original ''ogre.log'' file.

{CODE(wrap="1", colors="c#")} LogManager.Singleton.DefaultLog.LogMessage(...);{CODE}