00001
00006 #ifndef LOGGER_H_
00007 #define LOGGER_H_
00008
00009 #include <string>
00010 #include <queue>
00011 #include <fstream>
00012 #include <iostream>
00013 #include <pthread.h>
00014
00015 #include "Settings.h"
00016 #include "functions.h"
00017
00018 using namespace std;
00019
00023 enum logType {
00024 GET,
00025 SET,
00026 SET_NUMERIC,
00027 INCREMENT,
00028 SAVE_SPACE,
00029 LOAD_SPACE,
00030 DESTROY_SPACE,
00031 CREATE_SPACE,
00032 CLEAN_SPACE,
00033 SELECT_SPACE,
00034 INITIALIZE,
00035 FINALIZE,
00036 LOGIN,
00037 SOFT_QUOTA_EXCEEDED,
00038 HARD_QUOTA_REACHED,
00039 LRU_ENTRY_REMOVED,
00040 ENTRY_TIMED_OUT,
00041 QUOTA_USED_BY_USER,
00042 QUOTA_USED_BY_SPACE,
00043 BUFFER_OVERFLOW,
00044 LOAD_CONFIG,
00045 ERROR,
00046 CLEAR_STATS,
00047 GC_START_RUN,
00048 GC_END_RUN,
00049 GC_START_COLLECTING_FROM_SPACE,
00050 SET_PARAMETERS,
00051 GC_WALK,
00052 TIME_RECORD
00053 };
00054
00058 const int logTypeLevel[] = { 3, 3, 3, 3, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 3, 3, 2, 2, 1, 1, 2, 3, 3, 3, 3, 1, 1, 1 };
00059
00063 struct Log {
00064
00068 logType type;
00069
00073 time_t time;
00074
00078 string firstSParam;
00079
00083 string secondSParam;
00084
00088 unsigned firstUParam;
00089
00093 unsigned secondUParam;
00094
00098 Log(logType type, const string& firstSParam, const string& secondSParam, unsigned firstUParam,
00099 unsigned secondUParam);
00100 };
00101
00109 class Logger {
00110
00111 public:
00115 static bool stop;
00116
00117 private:
00118 unsigned bufferLength;
00119 unsigned interval;
00120 int logLevel;
00121 bool dumpToFile;
00122 queue<Log> logBuffer;
00123 string directory;
00124 string fileName;
00125 ostream * output;
00126
00127 pthread_t threadID;
00128 pthread_mutex_t mutex;
00129 bool isNotFullAndSatisfactoryLevel(int level);
00130 void logBufferOverflow();
00131 void push(Log log);
00132
00133 public:
00134
00138 Logger();
00139
00147 void setParameters(Settings config);
00148
00152 ~Logger();
00153
00157 void saveLogs();
00158
00162 void operator()();
00163
00171 void logGet(const string& key, const string& spaceName);
00175 void logSet(const string& key, const string& spaceName, unsigned timeout);
00179 void logSetNumeric(const string& key, const string& spaceName, unsigned timeout);
00183 void logIncrement(const string& key, const string& spaceName, unsigned step, unsigned timeout);
00187 void logSaveSpace(const string& spaceName, const string& fileName);
00191 void logLoadSpace(const string& spaceName, const string& fileName);
00195 void logDestroySpace(const string& spaceName);
00199 void logCreateSpace(const string& spaceName, const string& userName, unsigned softQuota, unsigned hardQuota);
00203 void logCleanSpace(const string& spaceName);
00207 void logSelectSpace(const string& spaceName);
00211 void logInitialize();
00215 void logFinalize();
00219 void logLogin(const string& userName);
00223 void logSoftQuotaExceeded(const string& spaceName);
00227 void logHardQuotaReached(const string& spaceName);
00231 void logLRUEntryRemoved(const string& key, const string& spaceName);
00235 void logEntryTimedOut(const string& key, const string& spaceName);
00239 void logQuotaUsedByUser(const string& userName, unsigned quota);
00243 void logQuotaUsedBySpace(const string& spaceName, unsigned quota);
00247 void logLoadConfig(const string& confDir, unsigned logLevel);
00251 void logError(const string& error);
00255 void logClearStats(const string &spaceName);
00259 void logGCStartRun();
00263 void logGCEndRun();
00267 void logGCStartCollectingFromSpace(const string &spaceName);
00271 void logGCWalk(const string & message);
00275 void logTimeRecord(const string & discipline, unsigned int miliseconds);
00276
00277 };
00278
00282 void * loggerThread(void * arg);
00283
00287 void loggerHandler(int n);
00288
00289 #endif