Skip to content

Commit

Permalink
Create DebugLogger.h
Browse files Browse the repository at this point in the history
I've implemented a new class to handle the debugging file so that we don't have the messy "cout" statements everywhere.
  • Loading branch information
Interlocked committed Apr 12, 2013
1 parent 2c19792 commit 2249dc0
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/DebugLogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#if !defined( _DEBUG_LOGGER_H )
#define _DEBUG_LOGGER_H

#if defined _DEBUG

#include <fstream>

namespace chesspp
{
/////////////////////////////////////////////////////////////////////////////
// Name: DebugLogFile
// Desc: A simple class that's used to output debugging information so that
// we can avoid using the console.
/////////////////////////////////////////////////////////////////////////////
class DebugLogFile
{
public:
DebugLogFile( const char *FileName = "DebugOutput.txt" );
~DebugLogFile( );

void LogMessage( const char *Message );

private:
// Disallow copying because we only need a single debug file. Objections?
DebugLogFile( DebugLogFile & );
DebugLogFile &operator = ( DebugLogFile & );

std::ofstream OutFile_;
};

inline DebugLogFile::DebugLogFile( const char *FileName )
: OutFile_( ( FileName ) ? FileName : "DefaultDebugFile.txt" )
{
}

inline DebugLogFile::~DebugLogFile( )
{
OutFile_.close( );
}

inline void DebugLogFile::LogMessage( const char *Message )
{
if( ( OutFile_.is_open( ) ) && ( Message ) )
{
OutFile_ << Message << '\n';
}
}
}

#endif

#endif

0 comments on commit 2249dc0

Please sign in to comment.