logger.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __LOGMANAGER_H
00015 #define __LOGMANAGER_H
00016
00029 class CoreExport FileWriter : public EventHandler
00030 {
00031 protected:
00034 InspIRCd* ServerInstance;
00035
00039 FILE* log;
00040
00043 int writeops;
00044
00045 public:
00048 FileWriter(InspIRCd* Instance, FILE* logfile);
00049
00056 virtual void HandleEvent(EventType et, int errornum = 0);
00057
00065 void WriteLogLine(const std::string &line);
00066
00069 virtual void Close();
00070
00074 virtual ~FileWriter();
00075 };
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00097 class CoreExport LogStream : public classbase
00098 {
00099 protected:
00100 InspIRCd *ServerInstance;
00101 int loglvl;
00102 public:
00103 LogStream(InspIRCd *Instance, int loglevel) : ServerInstance(Instance), loglvl(loglevel)
00104 {
00105 }
00106
00107
00108
00109
00110 virtual ~LogStream() { }
00111
00115 void ChangeLevel(int lvl) { this->loglvl = lvl; }
00116
00121 virtual void OnLog(int loglevel, const std::string &type, const std::string &msg) = 0;
00122 };
00123
00124 typedef std::map<FileWriter*, int> FileLogMap;
00125
00126 class CoreExport LogManager : public classbase
00127 {
00128 private:
00131 bool Logging;
00132
00135 LogStream* noforkstream;
00136
00137 InspIRCd *ServerInstance;
00138
00141 std::map<std::string, std::vector<LogStream *> > LogStreams;
00142
00146 std::map<LogStream *, int> AllLogStreams;
00147
00150 std::map<LogStream *, std::vector<std::string> > GlobalLogStreams;
00151
00154 FileLogMap FileLogs;
00155
00156 public:
00157
00158 LogManager(InspIRCd *Instance)
00159 {
00160 noforkstream = NULL;
00161 ServerInstance = Instance;
00162 Logging = false;
00163 }
00164
00169 void SetupNoFork();
00170
00174 void AddLoggerRef(FileWriter* fw)
00175 {
00176 FileLogMap::iterator i = FileLogs.find(fw);
00177 if (i == FileLogs.end())
00178 {
00179 FileLogs.insert(std::make_pair(fw, 1));
00180 }
00181 else
00182 {
00183 ++i->second;
00184 }
00185 }
00186
00189 void DelLoggerRef(FileWriter* fw)
00190 {
00191 FileLogMap::iterator i = FileLogs.find(fw);
00192 if (i == FileLogs.end()) return;
00193 if (--i->second < 1)
00194 {
00195 delete i->first;
00196 FileLogs.erase(i);
00197 }
00198 }
00199
00202 void OpenFileLogs();
00203
00207 void CloseLogs();
00208
00216 void AddLogTypes(const std::string &type, LogStream *l, bool autoclose);
00217
00225 bool AddLogType(const std::string &type, LogStream *l, bool autoclose);
00226
00230 void DelLogStream(LogStream* l);
00231
00235 bool DelLogType(const std::string &type, LogStream *l);
00236
00242 void Log(const std::string &type, int loglevel, const std::string &msg);
00243
00249 void Log(const std::string &type, int loglevel, const char *fmt, ...) CUSTOM_PRINTF(4, 5);
00250 };
00251
00252 #endif