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(); } ...

Get OpenSceneGraph 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.