00001
00006 #ifndef SERVERLOGGER_H_
00007 #define SERVERLOGGER_H_
00008
00009 #include <string>
00010 #include <vector>
00011 #include <queue>
00012
00013 #include <iostream>
00014 #include <pthread.h>
00015
00019 class ServerLogger {
00020
00021 private:
00022 std::string fileName;
00023 std::string directory;
00024 std::ostream * output;
00025 pthread_t threadID;
00026 pthread_mutex_t mutex;
00027 unsigned interval;
00028 bool dumpToFile;
00029 std::queue<std::string> logBuffer;
00030 long long reqId;
00031
00032 public:
00033
00040 ServerLogger(unsigned interval = 1, std::string directory = "server_logs");
00041
00045 ~ServerLogger();
00046
00050 void saveLogs();
00051
00055 void operator()();
00056
00064 void logNewConnection(const std::string& ip, unsigned port);
00068 void logConnectionRemoved(const std::string& ip, unsigned port);
00072 void logWaitingForNewRequest();
00076 long long logRequestStart(std::vector<std::string> fields);
00080 long long logRequestStart(std::vector<std::string> fields, std::string object);
00084 void logRequestPerformed(long long id);
00088 void logReplySent(long long id);
00092 void logConnectionTimeout();
00096 void logSocketError();
00097
00098 };
00099
00103 void * ServerLoggerThread(void * arg);
00104
00105 #endif