+ /* 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 (!stdalgo::string::equalsci(method, "file"))
+ {
+ continue;
+ }
+ std::string type = tag->getString("type");
+ std::string level = tag->getString("level");
+ LogLevel loglevel = LOG_DEFAULT;
+ if (stdalgo::string::equalsci(level, "rawio"))
+ {
+ loglevel = LOG_RAWIO;
+ ServerInstance->Config->RawLog = true;
+ }
+ else if (stdalgo::string::equalsci(level, "debug"))
+ {
+ loglevel = LOG_DEBUG;
+ }
+ else if (stdalgo::string::equalsci(level, "verbose"))
+ {
+ loglevel = LOG_VERBOSE;
+ }
+ else if (stdalgo::string::equalsci(level, "default"))
+ {
+ loglevel = LOG_DEFAULT;
+ }
+ else if (stdalgo::string::equalsci(level, "sparse"))
+ {
+ loglevel = LOG_SPARSE;
+ }
+ else if (stdalgo::string::equalsci(level, "none"))
+ {
+ loglevel = LOG_NONE;
+ }
+ FileWriter* fw;
+ std::string target = ServerInstance->Config->Paths.PrependLog(tag->getString("target"));
+ std::map<std::string, FileWriter*>::iterator fwi = logmap.find(target);
+ if (fwi == logmap.end())
+ {
+ char realtarget[256];
+ time_t time = ServerInstance->Time();
+ struct tm *mytime = gmtime(&time);
+ strftime(realtarget, sizeof(realtarget), target.c_str(), mytime);
+ FILE* f = fopen(realtarget, "a");
+ fw = new FileWriter(f, tag->getUInt("flush", 20, 1, UINT_MAX));
+ logmap.insert(std::make_pair(target, fw));
+ }
+ else
+ {
+ fw = fwi->second;
+ }
+ FileLogStream* fls = new FileLogStream(loglevel, fw);
+ fls->OnLog(LOG_SPARSE, "HEADER", LogStream::LogHeader);
+ AddLogTypes(type, fls, true);
+ }
+}
+
+void LogManager::CloseLogs()
+{
+ if (ServerInstance->Config && ServerInstance->Config->cmdline.forcedebug)
+ return;
+
+ LogStreams.clear();
+ GlobalLogStreams.clear();
+
+ for (std::map<LogStream*, int>::iterator i = AllLogStreams.begin(); i != AllLogStreams.end(); ++i)
+ {
+ delete i->first;
+ }
+
+ AllLogStreams.clear();
+}
+
+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)
+{
+ LogStreams[type].push_back(l);
+
+ if (type == "*")
+ GlobalLogStreams.insert(std::make_pair(l, std::vector<std::string>()));
+
+ if (autoclose)
+ AllLogStreams[l]++;