summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoraquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7>2008-02-15 13:30:46 +0000
committeraquanight <aquanight@e03df62e-2008-0410-955e-edbf42e46eb7>2008-02-15 13:30:46 +0000
commit11f1f2126c3e1f1cb91f5d6e273eba2850ca61a8 (patch)
tree8bd6949852d761fe8976d4195af26653c3e702b8 /src
parent7bd02d8a5dbac685d53a3f2aac9052c6ab5efa6e (diff)
Make -nofork work properly with logging now.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8944 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-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
6 files changed, 48 insertions, 38 deletions
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);*/