Catch LogMessages in MOGRE        

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

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

  • Show ogre messages in application

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. --Beauty

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

root = new Root(...);
 root.FrameStarted += new FrameListener.FrameStartedHandler(FrameStarted);
 // add this line here:
 LogManager.Singleton.DefaultLog.MessageLogged += new LogListener.MessageLoggedHandler(DefaultLog_MessageLogged);

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

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.

Add message to Ogre log

On the other hand you also can add entries to the original ogre.log file.