TerraForge3D  2.3.1
3D Terrain And Landscape Generator
LogHandler.cpp
1#include "Base/Logging/LogHandler.h"
2
3
4int LoggingOutputStreambuf::overflow( int ch )
5{
6 //myLogFile.sputc( ch ); // ignores errors...
7 myLogFile << (char)( ch ); // ignores errors...
8 return myDest->sputc( ch );
9}
10
11LoggingOutputStreambuf::LoggingOutputStreambuf(
12 std::streambuf *dest,
13 std::string const &filename )
14 : myDest( dest )
15 , myOwner( nullptr )
16{
17 myLogFile.open(filename);
18 myLogFile <<"Logging Started\n";
19
20 if ( !myLogFile.is_open() )
21 {
22 // Some error handling...
23 }
24}
25
26LoggingOutputStreambuf::LoggingOutputStreambuf(
27 std::ostream &dest,
28 std::string const &logfileName )
29 : LoggingOutputStreambuf( dest.rdbuf(), logfileName )
30{
31 dest.rdbuf( this );
32 dest << "Starting Logger " << logfileName << "\n";
33 myOwner = &dest;
34}
35
36LoggingOutputStreambuf::~LoggingOutputStreambuf()
37{
38 if ( myOwner != nullptr )
39 {
40 myOwner->rdbuf( myDest );
41 }
42
43 myLogFile.close();
44}