summaryrefslogtreecommitdiff
path: root/logd.cpp
diff options
context:
space:
mode:
authoradmin (centauri.fritz.box) <puppet@mx.buetow.org>2014-06-30 23:29:34 +0200
committeradmin (centauri.fritz.box) <puppet@mx.buetow.org>2014-06-30 23:29:34 +0200
commit813ee1984130c44f737f27426cc8414d19cf3bd9 (patch)
tree737daaeefa0ee1f2d66821821de489b70522db37 /logd.cpp
parent332d7b2107833018b3ef67b64ffe121bff1ef4fb (diff)
parent7ead5b7a9ea99a3e0f1459187b3262f7054f0126 (diff)
Merge remote-tracking branch 'remotes/github/0.5' into 0.50.5
Diffstat (limited to 'logd.cpp')
-rw-r--r--logd.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/logd.cpp b/logd.cpp
new file mode 100644
index 0000000..cfdc7c6
--- /dev/null
+++ b/logd.cpp
@@ -0,0 +1,65 @@
+#ifndef LOGD_CXX
+#define LOGD_CXX
+
+#include "logd.h"
+
+logd::logd( string filename )
+{
+ if(filename.empty())
+ {
+ cerr << "ycLog: No filename specified" << endl;
+ 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)
+ {
+ cerr << "ycLog: Could not open file: " << s_logfile << endl;
+ 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