summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/logger.h7
-rwxr-xr-xmake/run-cc.pl4
-rw-r--r--src/filelogger.cpp14
-rw-r--r--src/helperfuncs.cpp11
-rw-r--r--src/inspircd.cpp9
-rw-r--r--src/logger.cpp47
-rw-r--r--src/modules/m_chanlog.cpp2
-rw-r--r--src/server.cpp3
8 files changed, 57 insertions, 40 deletions
diff --git a/include/logger.h b/include/logger.h
index c9e9f8c0e..121d9ff25 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -86,6 +86,8 @@ class CoreExport LogStream : public classbase
virtual ~LogStream() { }
+ void ChangeLevel(int lvl) { this->loglvl = lvl; } // For on-the-fly change of loglevel.
+
virtual void OnLog(int loglevel, const std::string &type, const std::string &msg) = 0;
};
@@ -95,6 +97,7 @@ class CoreExport LogManager : public classbase
{
private:
bool Logging; // true when logging, avoids recursion
+ LogStream* noforkstream; // LogStream for nofork.
InspIRCd *ServerInstance;
std::map<std::string, std::vector<LogStream *> > LogStreams;
std::map<LogStream *, int> AllLogStreams; // holds all logstreams
@@ -107,6 +110,8 @@ class CoreExport LogManager : public classbase
Logging = false;
}
+ void SetupNoFork();
+
void AddLoggerRef(FileWriter* fw)
{
FileLogMap::iterator i = FileLogs.find(fw);
@@ -134,7 +139,7 @@ class CoreExport LogManager : public classbase
void OpenSingleFile(FILE* f, const std::string& type, int loglevel);
void OpenFileLogs();
void CloseLogs();
- bool AddLogType(const std::string &type, LogStream *l);
+ bool AddLogType(const std::string &type, LogStream *l, bool autoclose);
void DelLogStream(LogStream* l);
bool DelLogType(const std::string &type, LogStream *l);
void Log(const std::string &type, int loglevel, const std::string &msg);
diff --git a/make/run-cc.pl b/make/run-cc.pl
index 71a921c61..0b0ac5bad 100755
--- a/make/run-cc.pl
+++ b/make/run-cc.pl
@@ -26,8 +26,10 @@ my $location = "";
my @msgfilters = (
[ qr/^(.*) warning: cannot pass objects of non-POD type `(.*)' through `\.\.\.'; call will abort at runtime/ => sub {
my ($msg, $where, $type) = @_;
+ print $location;
+ $location = "";
my $errstr = "$where error: cannot pass objects of non-POD type `$type' through `...'\n";
- if ($type =~ m/::string/) {
+ if ($type =~ m/::(basic_)?string/) {
$errstr .= "$where (Did you forget to call c_str()?)\n";
}
die $errstr;
diff --git a/src/filelogger.cpp b/src/filelogger.cpp
index b0eb77310..fd86e4594 100644
--- a/src/filelogger.cpp
+++ b/src/filelogger.cpp
@@ -42,7 +42,9 @@ void FileLogStream::OnLog(int loglevel, const std::string &type, const std::stri
/* If we were given -debug we output all messages, regardless of configured loglevel */
if ((loglevel < this->loglvl) && !ServerInstance->Config->forcedebug)
+ {
return;
+ }
if (ServerInstance->Time() != LAST)
{
@@ -54,14 +56,6 @@ void FileLogStream::OnLog(int loglevel, const std::string &type, const std::stri
LAST = ServerInstance->Time();
}
- if (ServerInstance->Config->log_file && ServerInstance->Config->writelog)
- {
- std::string out = std::string(TIMESTR) + " " + text.c_str() + "\n";
- this->f->WriteLogLine(out);
- }
-
- if (ServerInstance->Config->nofork)
- {
- printf("%s %s\n", TIMESTR, text.c_str());
- }
+ std::string out = std::string(TIMESTR) + " " + text.c_str() + "\n";
+ this->f->WriteLogLine(out);
}
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 8e9f4dfd5..8cb62e72f 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -303,6 +303,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)
@@ -325,9 +331,10 @@ bool InspIRCd::OpenLog(char**, int)
}
FileWriter* fw = new FileWriter(this, Config->log_file);
- FileLogStream *f = new FileLogStream(this, Config->LogLevel, fw);
+ FileLogStream *f = new FileLogStream(this, (Config->forcedebug ? DEBUG : Config->LogLevel), fw);
+
+ this->Logs->AddLogType("*", f, true);
- this->Logs->AddLogType("*", f);
return true;
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 209b7ddbc..501be3979 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -401,6 +401,11 @@ InspIRCd::InspIRCd(int argc, char** argv)
#endif
strlcpy(Config->MyExecutable,argv[0],MAXBUF);
+ /* Set the finished argument values */
+ Config->nofork = do_nofork;
+ Config->forcedebug = do_debug;
+ Config->writelog = !do_nolog;
+
if (!this->OpenLog(argv, argc))
{
printf("ERROR: Could not open logfile %s: %s\n\n", Config->logpath.c_str(), strerror(errno));
@@ -421,10 +426,6 @@ InspIRCd::InspIRCd(int argc, char** argv)
printf_c("\t\033[1;32mpippijn, peavey, aquanight, fez\033[0m\n\n");
printf_c("Others:\t\t\t\033[1;32mSee /INFO Output\033[0m\n");
- /* Set the finished argument values */
- Config->nofork = do_nofork;
- Config->forcedebug = do_debug;
- Config->writelog = !do_nolog;
Config->ClearStack();
this->Modes = new ModeParser(this);
diff --git a/src/logger.cpp b/src/logger.cpp
index 7b0fa1798..5c24a4451 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -44,8 +44,24 @@
*
*/
+void LogManager::SetupNoFork()
+{
+ if (!noforkstream)
+ {
+ FileWriter* fw = new FileWriter(ServerInstance, stdout);
+ noforkstream = new FileLogStream(ServerInstance, ServerInstance->Config->forcedebug ? DEBUG : ServerInstance->Config->LogLevel, fw);
+ }
+ else
+ {
+ noforkstream->ChangeLevel(ServerInstance->Config->forcedebug ? DEBUG : ServerInstance->Config->LogLevel);
+ }
+ AddLogType("*", noforkstream, false);
+}
+
void LogManager::OpenFileLogs()
{
+ if (ServerInstance->Config->nofork) SetupNoFork(); // Call this to reregister the nofork stream.
+ if (!ServerInstance->Config->writelog) return; // Skip rest of logfile opening if we are running -nolog.
ConfigReader* Conf = new ConfigReader(ServerInstance);
std::map<std::string, FileWriter*> logmap;
std::map<std::string, FileWriter*>::iterator i;
@@ -56,7 +72,7 @@ void LogManager::OpenFileLogs()
std::string type = Conf->ReadValue("log", "type", index);
std::string level = Conf->ReadValue("log", "level", index);
int loglevel = DEFAULT;
- if (level == "debug")
+ if (level == "debug" || ServerInstance->Config->forcedebug)
{
loglevel = DEBUG;
ServerInstance->Config->debugging = true;
@@ -94,7 +110,7 @@ void LogManager::OpenFileLogs()
std::string tok;
while (css.GetToken(tok))
{
- AddLogType(tok, fls);
+ AddLogType(tok, fls, true);
}
}
}
@@ -108,17 +124,9 @@ void LogManager::CloseLogs()
delete i->first;
}
std::map<LogStream*, int>().swap(AllLogStreams); /* And clear it */
-
- /* Now close FileLoggers, for those logstreams that neglected to properly free their stuff. */
- for (FileLogMap::iterator it = FileLogs.begin(); it != FileLogs.end(); ++it)
- {
- delete it->first;
- }
-
- FileLogMap().swap(FileLogs);
}
-bool LogManager::AddLogType(const std::string &type, LogStream *l)
+bool LogManager::AddLogType(const std::string &type, LogStream *l, bool autoclose)
{
std::map<std::string, std::vector<LogStream *> >::iterator i = LogStreams.find(type);
@@ -134,14 +142,17 @@ bool LogManager::AddLogType(const std::string &type, LogStream *l)
if (type == "*")
GlobalLogStreams.push_back(l);
- std::map<LogStream*, int>::iterator ai = AllLogStreams.find(l);
- if (ai == AllLogStreams.end())
- {
- AllLogStreams.insert(std::make_pair(l, 1));
- }
- else
+ if (autoclose)
{
- ++ai->second;
+ std::map<LogStream*, int>::iterator ai = AllLogStreams.find(l);
+ if (ai == AllLogStreams.end())
+ {
+ AllLogStreams.insert(std::make_pair(l, 1));
+ }
+ else
+ {
+ ++ai->second;
+ }
}
return true;
diff --git a/src/modules/m_chanlog.cpp b/src/modules/m_chanlog.cpp
index 7d066a6ac..afc8c5225 100644
--- a/src/modules/m_chanlog.cpp
+++ b/src/modules/m_chanlog.cpp
@@ -98,7 +98,7 @@ class ModuleChanLog : public Module
std::string tok;
while (css.GetToken(tok))
{
- ServerInstance->Logs->AddLogType(tok, c);
+ ServerInstance->Logs->AddLogType(tok, c, true);
}
cls.push_back(c);
}
diff --git a/src/server.cpp b/src/server.cpp
index 191c84ce0..102fb35d3 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -47,9 +47,6 @@ void InspIRCd::Exit(int status)
void InspIRCd::Rehash()
{
this->SNO->WriteToSnoMask('A', "Rehashing config file %s due to SIGHUP",ServerConfig::CleanFilename(this->ConfigFileName));
- this->Logs->CloseLogs();
- if (!this->OpenLog(this->Config->argv, this->Config->argc))
- this->SNO->WriteToSnoMask('A', "ERROR: Could not open logfile %s: %s", Config->logpath.c_str(), strerror(errno));
this->RehashUsersAndChans();
FOREACH_MOD_I(this, I_OnGarbageCollect, OnGarbageCollect());
/*this->Config->Read(false,NULL);*/