76 lines
1.7 KiB
C++
76 lines
1.7 KiB
C++
#include "Log.h"
|
|
#include <ctime>
|
|
|
|
namespace BlueCore
|
|
{
|
|
//--------------------------------------------------------------------------
|
|
Log::Log() :
|
|
_LogFilename( "log.txt" )
|
|
{
|
|
reset();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void Log::reset()
|
|
{
|
|
std::ifstream testfile( _LogFilename.c_str() );
|
|
if( testfile.is_open() )
|
|
{
|
|
testfile.close();
|
|
_LogFile.open( _LogFilename.c_str(), std::ios::trunc );
|
|
_LogFile.close();
|
|
}
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
void Log::setFilename( const std::string &name )
|
|
{
|
|
_LogFilename = name;
|
|
reset();
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
Log &Log::operator << (const EndLine &e)
|
|
{
|
|
_LogFile << '\n';
|
|
std::cout << '\n';
|
|
return *this;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
Log &Log::operator << (const EndLog &e)
|
|
{
|
|
_LogFile << '\n';
|
|
_LogFile.close();
|
|
std::cout << '\n';
|
|
std::cout.flush();
|
|
return *this;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
Log &Log::operator << (const Time &t)
|
|
{
|
|
std::time_t rawtime;
|
|
std::time ( &rawtime );
|
|
char *tc = std::ctime( &rawtime );
|
|
_LogFile << tc;
|
|
std::cout << tc;
|
|
return *this;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
Log &Log::operator << (const Flush &f)
|
|
{
|
|
_LogFile.close();
|
|
std::cout.flush();
|
|
return *this;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------
|
|
Log::EndLine endline;
|
|
Log::EndLog endlog;
|
|
Log::Time time;
|
|
Log::Flush flush;
|
|
Log clog;
|
|
}
|