Time for action—saving the log file

We will make use of the std::ofstream class to redirect the OSG internal notify messages to an external log file. The virtual function notify() of the osg::NotifyHandler derived class should be overridden to apply standard file stream operations, and a global function osg::setNotifyHandler() is called before everything starts as well.

  1. Include the necessary headers:
    #include <osgDB/ReadFile>
    #include <osgViewer/Viewer>
    #include <fstream>
  2. Implement the derived class LogFileHandler, which will redirect notify messages to the file stream:
    class LogFileHandler : public osg::NotifyHandler { public: LogFileHandler( const std::string& file ) { _log.open( file.c_str() ); } virtual ~LogFileHandler() { _log.close(); } virtual ...

Get OpenSceneGraph 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.