]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/log.h
Merge pull request #35 from arydevy/patch-1
[dragonfireclient.git] / src / log.h
index 9fe5aa291381068950ed14adce35a5186bb0d0de..6ed6b1fb710b272ae66a8e81614850cdad14ba63 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -25,26 +25,24 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <fstream>
 #include <thread>
 #include <mutex>
-#if !defined(_WIN32) // POSIX
-#include <unistd.h>
+#if !defined(_WIN32)  // POSIX
+       #include <unistd.h>
 #endif
 #include "irrlichttypes.h"
 
 class ILogOutput;
 
-enum LogLevel
-{
+enum LogLevel {
        LL_NONE, // Special level that is always printed
        LL_ERROR,
        LL_WARNING,
-       LL_ACTION, // In-game actions
+       LL_ACTION,  // In-game actions
        LL_INFO,
        LL_VERBOSE,
        LL_MAX,
 };
 
-enum LogColor
-{
+enum LogColor {
        LOG_COLOR_NEVER,
        LOG_COLOR_ALWAYS,
        LOG_COLOR_AUTO,
@@ -53,8 +51,7 @@ enum LogColor
 typedef u8 LogLevelMask;
 #define LOGLEVEL_TO_MASKLEVEL(x) (1 << x)
 
-class Logger
-{
+class Logger {
 public:
        void addOutput(ILogOutput *out);
        void addOutput(ILogOutput *out, LogLevel lev);
@@ -80,8 +77,9 @@ class Logger
 
 private:
        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);
+       void logToOutputs(LogLevel, const std::string &combined,
+               const std::string &time, const std::string &thread_name,
+               const std::string &payload_text);
 
        const std::string getThreadName();
 
@@ -96,29 +94,28 @@ class Logger
        bool m_trace_enabled;
 };
 
-class ILogOutput
-{
+class ILogOutput {
 public:
        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;
+       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
-{
+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)
+       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 ICombinedLogOutput
-{
+class StreamLogOutput : public ICombinedLogOutput {
 public:
-       StreamLogOutput(std::ostream &stream) : m_stream(stream)
+       StreamLogOutput(std::ostream &stream) :
+               m_stream(stream)
        {
 #if !defined(_WIN32)
                is_tty = isatty(fileno(stdout));
@@ -134,8 +131,7 @@ class StreamLogOutput : public ICombinedLogOutput
        bool is_tty;
 };
 
-class FileLogOutput : public ICombinedLogOutput
-{
+class FileLogOutput : public ICombinedLogOutput {
 public:
        void setFile(const std::string &filename, s64 file_size_max);
 
@@ -148,20 +144,32 @@ class FileLogOutput : public ICombinedLogOutput
        std::ofstream m_stream;
 };
 
-class LogOutputBuffer : public ICombinedLogOutput
-{
+class LogOutputBuffer : public ICombinedLogOutput {
 public:
-       LogOutputBuffer(Logger &logger) : m_logger(logger) { updateLogLevel(); };
+       LogOutputBuffer(Logger &logger) :
+               m_logger(logger)
+       {
+               updateLogLevel();
+       };
 
-       virtual ~LogOutputBuffer() { m_logger.removeOutput(this); }
+       virtual ~LogOutputBuffer()
+       {
+               m_logger.removeOutput(this);
+       }
 
        void updateLogLevel();
 
        void logRaw(LogLevel lev, const std::string &line);
 
-       void clear() { m_buffer = std::queue<std::string>(); }
+       void clear()
+       {
+               m_buffer = std::queue<std::string>();
+       }
 
-       bool empty() const { return m_buffer.empty(); }
+       bool empty() const
+       {
+               return m_buffer.empty();
+       }
 
        std::string get()
        {
@@ -177,20 +185,15 @@ class LogOutputBuffer : public ICombinedLogOutput
        Logger &m_logger;
 };
 
+
 extern StreamLogOutput stdout_output;
 extern StreamLogOutput stderr_output;
 extern std::ostream null_stream;
 
 extern std::ostream *dout_con_ptr;
 extern std::ostream *derr_con_ptr;
-extern std::ostream *dout_server_ptr;
 extern std::ostream *derr_server_ptr;
 
-#ifndef SERVER
-extern std::ostream *dout_client_ptr;
-extern std::ostream *derr_client_ptr;
-#endif
-
 extern Logger g_logger;
 
 // Writes directly to all LL_NONE log outputs for g_logger with no prefix.
@@ -203,19 +206,14 @@ extern std::ostream infostream;
 extern std::ostream verbosestream;
 extern std::ostream dstream;
 
-#define TRACEDO(x)                                                                       \
-       do {                                                                             \
-               if (g_logger.getTraceEnabled()) {                                        \
-                       x;                                                               \
-               }                                                                        \
-       } while (0)
+#define TRACEDO(x) do {               \
+       if (g_logger.getTraceEnabled()) { \
+               x;                            \
+       }                                 \
+} while (0)
 
 #define TRACESTREAM(x) TRACEDO(verbosestream x)
 
 #define dout_con (*dout_con_ptr)
 #define derr_con (*derr_con_ptr)
-#define dout_server (*dout_server_ptr)
 
-#ifndef SERVER
-#define dout_client (*dout_client_ptr)
-#endif