blob: 5a7fa8299fed97d4685e9725e3b64545f06acb20 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#ifndef LOGD_CXX
#define LOGD_CXX
#include "s_ncur.h"
#include "glob.h"
#include "logd.h"
logd::logd( string filename )
{
if(filename.empty())
{
#ifdef NCURSES
s_ncur::get
().print( LOGERR2 );
#endif
#ifdef SERVMSG
cerr << LOGERR2 << endl;
#endif
exit(1);
}
s_logfile=filename;
i_lines=s_tool::string2int( s_conf::get
().get_val("LOG_LINES"));
}
void logd::flush()
{
s_output.open(s_logfile.c_str(), ios::app);
if(s_output==NULL)
{
#ifdef NCURSES
string s_tmp( LOGERR1 );
s_tmp.append( s_logfile );
s_ncur::get
().print( s_tmp.c_str() );
#endif
#ifdef SERVMSG
cerr << LOGERR1 << s_logfile << endl;
#endif
exit(1);
}
while(!s_queue.empty())
{
string s_l=s_queue.front();
s_queue.pop();
s_output.write(s_l.c_str(), s_l.size());
}
s_output.close();
}
void logd::log( map_string request )
{
struct tm *t_m;
time_t t_cur=time(NULL);
t_m=gmtime(&t_cur);
char buffer[100];
strftime(buffer, 100, "[%d/%b/%Y:%H:%M:%S %z]", t_m);
string s_time=buffer;
string s_logstr = request["REMOTE_ADDR"] + " - - "+s_time+" \"" + request["QUERY_STRING"]+"\" 200 0 \""+request["request"]+"\" \""+request["User-Agent"]+"\"\n";
s_queue.push(s_logstr);
if(s_queue.size()>=i_lines)
flush();
}
logd::~logd()
{
flush();
}
#endif
|