X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fhelperfuncs.cpp;h=67faee8f54371fd77dc814cf56c5c8e79ac413ab;hb=6d6f0ef3c67974e14cc226a442e09b2d0cb37146;hp=3f60cac80419acc443aab3e34f4bef9fe4bc03e8;hpb=dd98d56cabcd08a3d5207454e002b187af98d28a;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 3f60cac80..67faee8f5 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -18,65 +18,6 @@ #include "xline.h" #include "exitcodes.h" -static char TIMESTR[26]; -static time_t LAST = 0; - -/** Log() - * Write a line of text `text' to the logfile (and stdout, if in nofork) if the level `level' - * is greater than the configured loglevel. - */ -void InspIRCd::Log(int level, const char* text, ...) -{ - /* sanity check, just in case */ - if (!this->Config || !this->Logger) - return; - - /* Do this check again here so that we save pointless vsnprintf calls */ - if ((level < Config->LogLevel) && !Config->forcedebug) - return; - - va_list argsPtr; - char textbuffer[65536]; - - va_start(argsPtr, text); - vsnprintf(textbuffer, 65536, text, argsPtr); - va_end(argsPtr); - - this->Log(level, std::string(textbuffer)); -} - -void InspIRCd::Log(int level, const std::string &text) -{ - /* sanity check, just in case */ - if (!this->Config || !this->Logger) - return; - - /* If we were given -debug we output all messages, regardless of configured loglevel */ - if ((level < Config->LogLevel) && !Config->forcedebug) - return; - - if (Time() != LAST) - { - time_t local = Time(); - struct tm *timeinfo = localtime(&local); - - strlcpy(TIMESTR,asctime(timeinfo),26); - TIMESTR[24] = ':'; - LAST = Time(); - } - - if (Config->log_file && Config->writelog) - { - std::string out = std::string(TIMESTR) + " " + text.c_str() + "\n"; - this->Logger->WriteLogLine(out); - } - - if (Config->nofork) - { - printf("%s %s\n", TIMESTR, text.c_str()); - } -} - std::string InspIRCd::GetServerDescription(const char* servername) { std::string description; @@ -340,6 +281,12 @@ bool InspIRCd::IsSID(const std::string &str) /* open the proper logfile */ bool InspIRCd::OpenLog(char**, int) { + /* This function only happens at startup now (log reopening is done at OnReadConfig stage now instead of rehash) */ + if (Config->nofork) + { + this->Logs->SetupNoFork(); + } + if (!Config->writelog) return true; // Skip opening default log if -nolog Config->MyDir = Config->GetFullProgDir(); if (!*this->LogFileName) @@ -358,11 +305,14 @@ bool InspIRCd::OpenLog(char**, int) if (!Config->log_file) { - this->Logger = NULL; return false; } - this->Logger = new FileLogger(this, Config->log_file); + FileWriter* fw = new FileWriter(this, Config->log_file); + FileLogStream *f = new FileLogStream(this, (Config->forcedebug ? DEBUG : Config->LogLevel), fw); + + this->Logs->AddLogType("*", f, true); + return true; } @@ -371,7 +321,7 @@ void InspIRCd::CheckRoot() if (geteuid() == 0) { printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n"); - this->Log(DEFAULT,"Cant start as root"); + this->Logs->Log("STARTUP",DEFAULT,"Cant start as root"); Exit(EXIT_STATUS_ROOT); } } @@ -381,7 +331,7 @@ void InspIRCd::CheckDie() if (*Config->DieValue) { printf("WARNING: %s\n\n",Config->DieValue); - this->Log(DEFAULT,"Died because of tag: %s",Config->DieValue); + this->Logs->Log("CONFIG",DEFAULT,"Died because of tag: %s",Config->DieValue); Exit(EXIT_STATUS_DIETAG); } } @@ -451,19 +401,19 @@ long InspIRCd::Duration(const std::string &str) return total + subtotal; } -bool InspIRCd::ULine(const char* server) +bool InspIRCd::ULine(const char* sserver) { - if (!server) + if (!sserver) return false; - if (!*server) + if (!*sserver) return true; - return (Config->ulines.find(server) != Config->ulines.end()); + return (Config->ulines.find(sserver) != Config->ulines.end()); } -bool InspIRCd::SilentULine(const char* server) +bool InspIRCd::SilentULine(const char* sserver) { - std::map::iterator n = Config->ulines.find(server); + std::map::iterator n = Config->ulines.find(sserver); if (n != Config->ulines.end()) return n->second; else return false;