]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/log.h
Mgfractal: Move julia set selection into formula parameter
[dragonfireclient.git] / src / log.h
index 0e63041ccdbd215d82ae6cade0b1e0e5bb04989c..219255d9abfd6af92f042efa32ea0df3946d56e2 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <string>
 #include <fstream>
 #include "threads.h"
+#include "irrlichttypes.h"
 
 class ILogOutput;
 
@@ -38,12 +39,16 @@ enum LogLevel {
        LL_MAX,
 };
 
+typedef u8 LogLevelMask;
+#define LOGLEVEL_TO_MASKLEVEL(x) (1 << x)
+
 class Logger {
 public:
        void addOutput(ILogOutput *out);
        void addOutput(ILogOutput *out, LogLevel lev);
+       void addOutputMasked(ILogOutput *out, LogLevelMask mask);
        void addOutputMaxLevel(ILogOutput *out, LogLevel lev);
-       void removeOutput(ILogOutput *out);
+       LogLevelMask removeOutput(ILogOutput *out);
        void setLevelSilenced(LogLevel lev, bool silenced);
 
        void registerThread(const std::string &name);
@@ -57,12 +62,14 @@ class Logger {
        bool getTraceEnabled() { return m_trace_enabled; }
 
        static LogLevel stringToLevel(const std::string &name);
+       static const std::string getLevelLabel(LogLevel lev);
 
 private:
-       void logToSystem(LogLevel, const std::string &text);
-       void logToOutputs(LogLevel, const std::string &text);
+       void logToOutputsRaw(LogLevel, const std::string &line);
+       void logToOutputs(LogLevel, const std::string &combined,
+               const std::string &time, const std::string &thread_name,
+               const std::string &payload_text);
 
-       const std::string getLevelLabel(LogLevel lev);
        const std::string getThreadName();
 
        std::vector<ILogOutput *> m_outputs[LL_MAX];
@@ -78,73 +85,86 @@ class Logger {
 
 class ILogOutput {
 public:
-       virtual void log(const std::string &line) = 0;
+       virtual void logRaw(LogLevel, const std::string &line) = 0;
+       virtual void log(LogLevel, const std::string &combined,
+               const std::string &time, const std::string &thread_name,
+               const std::string &payload_text) = 0;
+};
+
+class ICombinedLogOutput : public ILogOutput {
+public:
+       void log(LogLevel lev, const std::string &combined,
+               const std::string &time, const std::string &thread_name,
+               const std::string &payload_text)
+       {
+               logRaw(lev, combined);
+       }
 };
 
-class StreamLogOutput : public ILogOutput {
+class StreamLogOutput : public ICombinedLogOutput {
 public:
        StreamLogOutput(std::ostream &stream) :
-               stream(stream)
+               m_stream(stream)
        {
        }
 
-       void log(const std::string &line)
+       void logRaw(LogLevel lev, const std::string &line)
        {
-               stream << line << std::endl;
+               m_stream << line << std::endl;
        }
 
 private:
-       std::ostream &stream;
+       std::ostream &m_stream;
 };
 
-class FileLogOutput : public ILogOutput {
+class FileLogOutput : public ICombinedLogOutput {
 public:
        void open(const std::string &filename);
 
-       void log(const std::string &line)
+       void logRaw(LogLevel lev, const std::string &line)
        {
-               stream << line << std::endl;
+               m_stream << line << std::endl;
        }
 
 private:
-       std::ofstream stream;
+       std::ofstream m_stream;
 };
 
-class LogOutputBuffer : public ILogOutput {
+class LogOutputBuffer : public ICombinedLogOutput {
 public:
        LogOutputBuffer(Logger &logger, LogLevel lev) :
-               logger(logger)
+               m_logger(logger)
        {
-               logger.addOutput(this, lev);
+               m_logger.addOutput(this, lev);
        }
 
        ~LogOutputBuffer()
        {
-               logger.removeOutput(this);
+               m_logger.removeOutput(this);
        }
 
-       virtual void log(const std::string &line)
+       void logRaw(LogLevel lev, const std::string &line)
        {
-               buffer.push(line);
+               m_buffer.push(line);
        }
 
        bool empty()
        {
-               return buffer.empty();
+               return m_buffer.empty();
        }
 
        std::string get()
        {
                if (empty())
                        return "";
-               std::string s = buffer.front();
-               buffer.pop();
+               std::string s = m_buffer.front();
+               m_buffer.pop();
                return s;
        }
 
 private:
-       std::queue<std::string> buffer;
-       Logger &logger;
+       std::queue<std::string> m_buffer;
+       Logger &m_logger;
 };