import the first version of cmslu

git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@460 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2008-12-10 04:42:49 +00:00
parent d4a5f1f963
commit c53e985a92
37 changed files with 4944 additions and 0 deletions

177
core/log.cpp Executable file
View File

@@ -0,0 +1,177 @@
/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008, Tomasz Sowa
* All rights reserved.
*
*/
#include "log.h"
Log::Log()
{
log_level = 1;
current_level = 2;
log_file = "cmslu.log";
log_stdout = true;
}
void Log::Init(int log_l, const std::string & log_f, bool log_std)
{
log_level = log_l;
log_file = log_f;
log_stdout = log_std;
}
// zrobic templeta z tych metod
// i dla const char * zrobic specjalizacje
Log & Log::operator<<(const char * s)
{
if( !s )
return *this;
buffer << s;
return *this;
}
Log & Log::operator<<(const std::string & s)
{
buffer << s;
return *this;
}
Log & Log::operator<<(int s)
{
buffer << s;
return *this;
}
Log & Log::operator<<(long s)
{
buffer << s;
return *this;
}
/*
Log & Log::operator<<(void * s)
{
buffer << s;
return *this;
}
*/
Log & Log::operator<<(char s)
{
buffer << s;
return *this;
}
Log & Log::operator<<(size_t s)
{
buffer << s;
return *this;
}
Log & Log::operator<<(Manipulators m)
{
switch(m)
{
case logend:
SaveLog();
buffer.str( "" );
break;
case log1:
current_level = 1;
break;
case log2:
current_level = 2;
break;
case log3:
current_level = 3;
break;
}
return *this;
}
void Log::SaveLog()
{
int attempt = 2;
if( current_level > log_level )
return;
if( log_stdout )
std::cout << buffer.str() << std::endl;
std::ofstream file;
do
{
file.open( log_file.c_str(), std::ios_base::out | std::ios_base::app );
// if( !file )
// sleep(1);
}
while( --attempt > 0 && !file );
if( !file )
return;
file << buffer.str() << std::endl;
}