]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/log.cpp
Document zoom_fov in settingtypes.txt and minetest.conf.example
[dragonfireclient.git] / src / log.cpp
index 3ffd66673413a367e5acbbb1f86a2d0bbb0f7184..589cfd909806ee7ba6be55d720c6f06ba486a6bf 100644 (file)
@@ -34,9 +34,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <cerrno>
 #include <cstring>
 
+const int BUFFER_LENGTH = 256;
+
 class StringBuffer : public std::streambuf {
 public:
-       StringBuffer() {}
+       StringBuffer() {
+               buffer_index = 0;
+       }
 
        int overflow(int c);
        virtual void flush(const std::string &buf) = 0;
@@ -44,7 +48,8 @@ class StringBuffer : public std::streambuf {
        void push_back(char c);
 
 private:
-       std::string buffer;
+       char buffer[BUFFER_LENGTH];
+       int buffer_index;
 };
 
 
@@ -135,7 +140,8 @@ class AndroidSystemLogOutput : public ICombinedLogOutput {
                }
                void logRaw(LogLevel lev, const std::string &line)
                {
-                       assert(ARRLEN(g_level_to_android) == LL_MAX);
+                       STATIC_ASSERT(ARRLEN(g_level_to_android) == LL_MAX,
+                               mismatch_between_android_and_internal_loglevels);
                        __android_log_print(g_level_to_android[lev],
                                PROJECT_NAME_C, "%s", line.c_str());
                }
@@ -180,6 +186,14 @@ void Logger::addOutput(ILogOutput *out, LogLevel lev)
        m_outputs[lev].push_back(out);
 }
 
+void Logger::addOutputMasked(ILogOutput *out, LogLevelMask mask)
+{
+       for (size_t i = 0; i < LL_MAX; i++) {
+               if (mask & LOGLEVEL_TO_MASKLEVEL(i))
+                       m_outputs[i].push_back(out);
+       }
+}
+
 void Logger::addOutputMaxLevel(ILogOutput *out, LogLevel lev)
 {
        assert(lev < LL_MAX);
@@ -187,15 +201,19 @@ void Logger::addOutputMaxLevel(ILogOutput *out, LogLevel lev)
                m_outputs[i].push_back(out);
 }
 
-void Logger::removeOutput(ILogOutput *out)
+LogLevelMask Logger::removeOutput(ILogOutput *out)
 {
+       LogLevelMask ret_mask = 0;
        for (size_t i = 0; i < LL_MAX; i++) {
                std::vector<ILogOutput *>::iterator it;
 
                it = std::find(m_outputs[i].begin(), m_outputs[i].end(), out);
-               if (it != m_outputs[i].end())
+               if (it != m_outputs[i].end()) {
+                       ret_mask |= LOGLEVEL_TO_MASKLEVEL(i);
                        m_outputs[i].erase(it);
+               }
        }
+       return ret_mask;
 }
 
 void Logger::setLevelSilenced(LogLevel lev, bool silenced)
@@ -228,7 +246,8 @@ const std::string Logger::getLevelLabel(LogLevel lev)
                "VERBOSE",
        };
        assert(lev < LL_MAX && lev >= 0);
-       assert(ARRLEN(names) == LL_MAX);
+       STATIC_ASSERT(ARRLEN(names) == LL_MAX,
+               mismatch_between_loglevel_names_and_enum);
        return names[lev];
 }
 
@@ -324,11 +343,18 @@ std::streamsize StringBuffer::xsputn(const char *s, std::streamsize n)
 void StringBuffer::push_back(char c)
 {
        if (c == '\n' || c == '\r') {
-               if (!buffer.empty())
-                       flush(buffer);
-               buffer.clear();
+               if (buffer_index)
+                       flush(std::string(buffer, buffer_index));
+               buffer_index = 0;
        } else {
-               buffer.push_back(c);
+               int index = buffer_index;
+               buffer[index++] = c;
+               if (index >= BUFFER_LENGTH) {
+                       flush(std::string(buffer, buffer_index));
+                       buffer_index = 0;
+               } else {
+                       buffer_index = index;
+               }
        }
 }