Translated using Weblate (Italian)
[oweals/minetest.git] / src / log.h
index d02d85a4b6a348fb43f0e1f9296d3c9d7d24ab89..856d3479b94d44cfd8187591440ee859ca0b5520 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -25,6 +25,9 @@ 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>
+#endif
 #include "irrlichttypes.h"
 
 class ILogOutput;
@@ -39,6 +42,12 @@ enum LogLevel {
        LL_MAX,
 };
 
+enum LogColor {
+       LOG_COLOR_NEVER,
+       LOG_COLOR_ALWAYS,
+       LOG_COLOR_AUTO,
+};
+
 typedef u8 LogLevelMask;
 #define LOGLEVEL_TO_MASKLEVEL(x) (1 << x)
 
@@ -64,6 +73,8 @@ public:
        static LogLevel stringToLevel(const std::string &name);
        static const std::string getLevelLabel(LogLevel lev);
 
+       static LogColor color_mode;
+
 private:
        void logToOutputsRaw(LogLevel, const std::string &line);
        void logToOutputs(LogLevel, const std::string &combined,
@@ -106,20 +117,23 @@ public:
        StreamLogOutput(std::ostream &stream) :
                m_stream(stream)
        {
+#if !defined(_WIN32)
+               is_tty = isatty(fileno(stdout));
+#else
+               is_tty = false;
+#endif
        }
 
-       void logRaw(LogLevel lev, const std::string &line)
-       {
-               m_stream << line << std::endl;
-       }
+       void logRaw(LogLevel lev, const std::string &line);
 
 private:
        std::ostream &m_stream;
+       bool is_tty;
 };
 
 class FileLogOutput : public ICombinedLogOutput {
 public:
-       void open(const std::string &filename);
+       void setFile(const std::string &filename, s64 file_size_max);
 
        void logRaw(LogLevel lev, const std::string &line)
        {
@@ -132,23 +146,27 @@ private:
 
 class LogOutputBuffer : public ICombinedLogOutput {
 public:
-       LogOutputBuffer(Logger &logger, LogLevel lev) :
+       LogOutputBuffer(Logger &logger) :
                m_logger(logger)
        {
-               m_logger.addOutput(this, lev);
-       }
+               updateLogLevel();
+       };
 
-       ~LogOutputBuffer()
+       virtual ~LogOutputBuffer()
        {
                m_logger.removeOutput(this);
        }
 
-       void logRaw(LogLevel lev, const std::string &line)
+       void updateLogLevel();
+
+       void logRaw(LogLevel lev, const std::string &line);
+
+       void clear()
        {
-               m_buffer.push(line);
+               m_buffer = std::queue<std::string>();
        }
 
-       bool empty()
+       bool empty() const
        {
                return m_buffer.empty();
        }
@@ -205,9 +223,7 @@ extern std::ostream dstream;
 #define dout_con (*dout_con_ptr)
 #define derr_con (*derr_con_ptr)
 #define dout_server (*dout_server_ptr)
-#define derr_server (*derr_server_ptr)
 
 #ifndef SERVER
        #define dout_client (*dout_client_ptr)
-       #define derr_client (*derr_client_ptr)
 #endif