+LogManager::LogManager()
+{
+ Logging = false;
+}
+
+LogManager::~LogManager()
+{
+}
+
+void LogManager::OpenFileLogs()
+{
+ if (ServerInstance->Config->cmdline.forcedebug)
+ {
+ ServerInstance->Config->RawLog = true;
+ return;
+ }
+ /* Skip rest of logfile opening if we are running -nolog. */
+ if (!ServerInstance->Config->cmdline.writelog)
+ return;
+ std::map<std::string, FileWriter*> logmap;
+ ConfigTagList tags = ServerInstance->Config->ConfTags("log");
+ for(ConfigIter i = tags.first; i != tags.second; ++i)
+ {
+ ConfigTag* tag = i->second;
+ std::string method = tag->getString("method");
+ if (method != "file")
+ {
+ continue;
+ }
+ std::string type = tag->getString("type");
+ std::string level = tag->getString("level");
+ int loglevel = DEFAULT;
+ if (level == "rawio")
+ {
+ loglevel = RAWIO;
+ ServerInstance->Config->RawLog = true;
+ }
+ else if (level == "debug")
+ {
+ loglevel = DEBUG;
+ }
+ else if (level == "verbose")
+ {
+ loglevel = VERBOSE;
+ }
+ else if (level == "default")
+ {
+ loglevel = DEFAULT;
+ }
+ else if (level == "sparse")
+ {
+ loglevel = SPARSE;
+ }
+ else if (level == "none")
+ {
+ loglevel = NONE;
+ }
+ FileWriter* fw;
+ std::string target = tag->getString("target");
+ std::map<std::string, FileWriter*>::iterator fwi = logmap.find(target);
+ if (fwi == logmap.end())
+ {
+ char realtarget[MAXBUF];
+ time_t time = ServerInstance->Time();
+ struct tm *mytime = gmtime(&time);
+ strftime(realtarget, MAXBUF, target.c_str(), mytime);
+ FILE* f = fopen(realtarget, "a");
+ fw = new FileWriter(f);
+ logmap.insert(std::make_pair(target, fw));
+ }
+ else
+ {
+ fw = fwi->second;
+ }
+ FileLogStream* fls = new FileLogStream(loglevel, fw);
+ fls->OnLog(SPARSE, "HEADER", InspIRCd::LogHeader);
+ AddLogTypes(type, fls, true);
+ }
+}
+
+void LogManager::CloseLogs()
+{
+ if (ServerInstance->Config && ServerInstance->Config->cmdline.forcedebug)
+ return;
+ std::map<std::string, std::vector<LogStream*> >().swap(LogStreams); /* Clear it */
+ std::map<LogStream*, std::vector<std::string> >().swap(GlobalLogStreams); /* Clear it */
+ for (std::map<LogStream*, int>::iterator i = AllLogStreams.begin(); i != AllLogStreams.end(); ++i)
+ {
+ delete i->first;
+ }
+ std::map<LogStream*, int>().swap(AllLogStreams); /* And clear it */
+}
+
+void LogManager::AddLogTypes(const std::string &types, LogStream* l, bool autoclose)
+{
+ irc::spacesepstream css(types);
+ std::string tok;
+ std::vector<std::string> excludes;
+ while (css.GetToken(tok))
+ {
+ if (tok.empty())
+ {
+ continue;
+ }
+ if (tok.at(0) == '-')
+ {
+ /* Exclude! */
+ excludes.push_back(tok.substr(1));
+ }
+ else
+ {
+ AddLogType(tok, l, autoclose);
+ }
+ }
+ // Handle doing things like: USERINPUT USEROUTPUT -USERINPUT should be the same as saying just USEROUTPUT.
+ // (This is so modules could, for example, inject exclusions for logtypes they can't handle.)
+ for (std::vector<std::string>::iterator i = excludes.begin(); i != excludes.end(); ++i)
+ {
+ if (*i == "*")
+ {
+ /* -* == Exclude all. Why someone would do this, I dunno. */
+ DelLogStream(l);
+ return;
+ }
+ DelLogType(*i, l);
+ }
+ // Now if it's registered as a global, add the exclusions there too.
+ std::map<LogStream *, std::vector<std::string> >::iterator gi = GlobalLogStreams.find(l);
+ if (gi != GlobalLogStreams.end())
+ {
+ gi->second.swap(excludes); // Swap with the vector in the hash.
+ }
+}
+
+bool LogManager::AddLogType(const std::string &type, LogStream *l, bool autoclose)