]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/logger.cpp
Convert the ISO 8859-2 nationalchars files to codepage configs.
[user/henk/code/inspircd.git] / src / logger.cpp
index bf4ef582a5d7dede6fb424ae6e33bf21120eb6e5..5ebcf4b00d782f0b5903a38c1d092ca94413c017 100644 (file)
@@ -1,10 +1,16 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2008 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2013-2014 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2013, 2017-2018, 2020 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
+ *   Copyright (C) 2012 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
+ *   Copyright (C) 2010 Adam <Adam@anope.org>
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
+ *   Copyright (C) 2008-2009 Robin Burchell <robin+git@viroteck.net>
  *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
- *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
@@ -50,8 +56,7 @@
  */
 
 const char LogStream::LogHeader[] =
-       "Log started for " INSPIRCD_VERSION " (" INSPIRCD_REVISION ", " MODULE_INIT_STR ")"
-       " - compiled on " INSPIRCD_SYSTEM;
+       "Log started for " INSPIRCD_VERSION;
 
 LogManager::LogManager()
        : Logging(false)
@@ -78,35 +83,35 @@ void LogManager::OpenFileLogs()
        {
                ConfigTag* tag = i->second;
                std::string method = tag->getString("method");
-               if (method != "file")
+               if (!stdalgo::string::equalsci(method, "file"))
                {
                        continue;
                }
                std::string type = tag->getString("type");
                std::string level = tag->getString("level");
                LogLevel loglevel = LOG_DEFAULT;
-               if (level == "rawio")
+               if (stdalgo::string::equalsci(level, "rawio"))
                {
                        loglevel = LOG_RAWIO;
                        ServerInstance->Config->RawLog = true;
                }
-               else if (level == "debug")
+               else if (stdalgo::string::equalsci(level, "debug"))
                {
                        loglevel = LOG_DEBUG;
                }
-               else if (level == "verbose")
+               else if (stdalgo::string::equalsci(level, "verbose"))
                {
                        loglevel = LOG_VERBOSE;
                }
-               else if (level == "default")
+               else if (stdalgo::string::equalsci(level, "default"))
                {
                        loglevel = LOG_DEFAULT;
                }
-               else if (level == "sparse")
+               else if (stdalgo::string::equalsci(level, "sparse"))
                {
                        loglevel = LOG_SPARSE;
                }
-               else if (level == "none")
+               else if (stdalgo::string::equalsci(level, "none"))
                {
                        loglevel = LOG_NONE;
                }
@@ -120,7 +125,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, tag->getUInt("flush", 20, 1, UINT_MAX));
                        logmap.insert(std::make_pair(target, fw));
                }
                else
@@ -207,10 +212,9 @@ void LogManager::DelLogStream(LogStream* l)
 {
        for (std::map<std::string, std::vector<LogStream*> >::iterator i = LogStreams.begin(); i != LogStreams.end(); ++i)
        {
-               std::vector<LogStream*>::iterator it;
-               while ((it = std::find(i->second.begin(), i->second.end(), l)) != i->second.end())
+               while (stdalgo::erase(i->second, l))
                {
-                       i->second.erase(it);
+                       // Keep erasing while it exists
                }
        }
 
@@ -236,11 +240,8 @@ bool LogManager::DelLogType(const std::string &type, LogStream *l)
 
        if (i != LogStreams.end())
        {
-               std::vector<LogStream *>::iterator it = std::find(i->second.begin(), i->second.end(), l);
-
-               if (it != i->second.end())
+               if (stdalgo::erase(i->second, l))
                {
-                       i->second.erase(it);
                        if (i->second.size() == 0)
                        {
                                LogStreams.erase(i);
@@ -292,7 +293,7 @@ void LogManager::Log(const std::string &type, LogLevel loglevel, const std::stri
 
        for (std::map<LogStream *, std::vector<std::string> >::iterator gi = GlobalLogStreams.begin(); gi != GlobalLogStreams.end(); ++gi)
        {
-               if (std::find(gi->second.begin(), gi->second.end(), type) != gi->second.end())
+               if (stdalgo::isin(gi->second, type))
                {
                        continue;
                }
@@ -313,8 +314,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)
 {
 }
 
@@ -326,7 +329,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);
        }