summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2017-03-05 21:32:11 +0100
committerGitHub <noreply@github.com>2017-03-05 21:32:11 +0100
commit5583d8dc5ff202d411d7985b6bbfb240beeacddd (patch)
tree5e698c3b99e9c3addf516a2dcd7b3b2686fc15cb
parent51ff3d67ed1b6f1594373d3745293ef155a26f44 (diff)
parent7c301149883e038a4bf3ce4a7a9a6a91b3e1ce97 (diff)
Merge pull request #1292 from SaberUK/master+flush
Allow <log> tags to specify how often logs should be flushed.
-rw-r--r--docs/conf/inspircd.conf.example5
-rw-r--r--include/logger.h8
-rw-r--r--src/inspircd.cpp2
-rw-r--r--src/logger.cpp10
4 files changed, 18 insertions, 7 deletions
diff --git a/docs/conf/inspircd.conf.example b/docs/conf/inspircd.conf.example
index 79a127d5a..7ba324e47 100644
--- a/docs/conf/inspircd.conf.example
+++ b/docs/conf/inspircd.conf.example
@@ -838,6 +838,11 @@
# - USERINPUT
# - USEROUTPUT
#
+# If your server is producing a high levels of log messages you can also set the
+# flush="[positive number]" attribute to specify how many log messages should be
+# buffered before flushing to disk. You should probably not specify this unless
+# you are having problems.
+#
# The following log tag is highly default and uncustomised. It is recommended you
# sort out your own log tags. This is just here so you get some output.
diff --git a/include/logger.h b/include/logger.h
index c56859a62..5d4a80d9f 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -41,14 +41,18 @@ class CoreExport FileWriter
*/
FILE* log;
+ /** The number of write operations after which we should flush.
+ */
+ unsigned int flush;
+
/** Number of write operations that have occured
*/
- int writeops;
+ unsigned int writeops;
public:
/** The constructor takes an already opened logfile.
*/
- FileWriter(FILE* logfile);
+ FileWriter(FILE* logfile, unsigned int flushcount);
/** Write one or more preformatted log lines.
* If the data cannot be written immediately,
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 5fe2ef076..0c9b67910 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -343,7 +343,7 @@ InspIRCd::InspIRCd(int argc, char** argv) :
if (do_debug)
{
- FileWriter* fw = new FileWriter(stdout);
+ FileWriter* fw = new FileWriter(stdout, 1);
FileLogStream* fls = new FileLogStream(LOG_RAWIO, fw);
Logs->AddLogTypes("*", fls, true);
}
diff --git a/src/logger.cpp b/src/logger.cpp
index 5b4a948ee..e3e956325 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -120,7 +120,7 @@ void LogManager::OpenFileLogs()
struct tm *mytime = gmtime(&time);
strftime(realtarget, sizeof(realtarget), target.c_str(), mytime);
FILE* f = fopen(realtarget, "a");
- fw = new FileWriter(f);
+ fw = new FileWriter(f, static_cast<unsigned int>(tag->getInt("flush", 20, 1, INT_MAX)));
logmap.insert(std::make_pair(target, fw));
}
else
@@ -309,8 +309,10 @@ void LogManager::Log(const std::string &type, LogLevel loglevel, const std::stri
}
-FileWriter::FileWriter(FILE* logfile)
-: log(logfile), writeops(0)
+FileWriter::FileWriter(FILE* logfile, unsigned int flushcount)
+ : log(logfile)
+ , flush(flushcount)
+ , writeops(0)
{
}
@@ -322,7 +324,7 @@ void FileWriter::WriteLogLine(const std::string &line)
// throw CoreException("FileWriter::WriteLogLine called with a closed logfile");
fputs(line.c_str(), log);
- if (++writeops % 20 == 0)
+ if (++writeops % flush == 0)
{
fflush(log);
}