summaryrefslogtreecommitdiff
path: root/logd.cpp
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2013-04-06 13:14:44 +0200
committerPaul Buetow <paul@buetow.org>2013-04-06 13:14:44 +0200
commitca28c0e618890330d429c0dc12429255b20f0c90 (patch)
treeecc02da0184cf4e8bdba94dcdd831abdd1e51b3c /logd.cpp
parentb3a99e6e15af3be25394e66d1138bb2682f565c3 (diff)
tagging ychat-0.5.0ychat-0.5.0
Diffstat (limited to 'logd.cpp')
-rw-r--r--logd.cpp83
1 files changed, 33 insertions, 50 deletions
diff --git a/logd.cpp b/logd.cpp
index 5a7fa82..cfdc7c6 100644
--- a/logd.cpp
+++ b/logd.cpp
@@ -1,78 +1,61 @@
#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;
+ 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"));
+ 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);
- }
+ 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());
+ 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();
+ }
+ s_output.close();
}
void logd::log( map_string request )
{
- struct tm *t_m;
- time_t t_cur=time(NULL);
- t_m=gmtime(&t_cur);
+ 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";
+ 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);
+ s_queue.push(s_logstr);
- if(s_queue.size()>=i_lines)
- flush();
+ if(s_queue.size()>=i_lines)
+ flush();
}
logd::~logd()
{
- flush();
+ flush();
}