Files
winix/core/log.cpp
Tomasz Sowa 60fccea703 fixed: dots in url-es (now only one dot is available in the whole name and it cannot be only one dot ".")
added:   cmslu can act as an authorizer (fast cgi authorize role)
added:   Item::static_auth we can have additional static content on the file system
         this content is authorized through cmslu (fastcgi authorizer mode)
changed: some changes in config
changed: the way how the www server is using cmslu
         added new virtuals: static static_auth
changed: cmslu returns correct http headers (200, 404, 403)
changed: in cookie parser: we get the last cookie (if the server has more than one cookie with the same name)



git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@540 e52654a7-88a9-db11-a3e9-0013d4bc506e
2009-12-30 20:46:12 +00:00

202 lines
2.4 KiB
C++
Executable File

/*
* This file is a part of CMSLU -- Content Management System like Unix
* and is not publicly distributed
*
* Copyright (c) 2008-2009, Tomasz Sowa
* All rights reserved.
*
*/
#include "log.h"
#include <ctime>
Log::Log()
{
log_level = 3;
current_level = 4; // nothing to log (call Init() first)
}
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;
}
void Log::PutDate(Manipulators m)
{
time_t t = std::time(0);
std::tm * loct = std::localtime(&t);
char buffer[70];
sprintf(buffer, "%d.%02d.%02d %02d:%02d:%02d ", int(loct->tm_year + 1900),
int(loct->tm_mon + 1),
int(loct->tm_mday),
int(loct->tm_hour),
int(loct->tm_min),
int(loct->tm_sec));
(*this) << m << buffer;
}
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<<(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<<(char s)
{
buffer << s;
return *this;
}
Log & Log::operator<<(size_t s)
{
buffer << s;
return *this;
}
Log & Log::operator<<(double 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;
if( log_file.empty() )
return;
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;
}