X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flog.h;h=6ed6b1fb710b272ae66a8e81614850cdad14ba63;hb=623f0a8613bd8677e259366a1d540deedb9d2302;hp=c017d127e6c21d9305c3c545b728117fa3e8d3ed;hpb=d4c0f91275fe70fef73b316c36abfb989dfd55b1;p=dragonfireclient.git diff --git a/src/log.h b/src/log.h index c017d127e..6ed6b1fb7 100644 --- a/src/log.h +++ b/src/log.h @@ -17,15 +17,17 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef LOG_HEADER -#define LOG_HEADER +#pragma once #include #include #include #include +#include #include -#include "threads.h" +#if !defined(_WIN32) // POSIX + #include +#endif #include "irrlichttypes.h" class ILogOutput; @@ -40,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) @@ -65,6 +73,8 @@ class Logger { 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, @@ -79,7 +89,7 @@ class Logger { // written to when one thread has access currently). // Works on all known architectures (x86, ARM, MIPS). volatile bool m_silenced_levels[LL_MAX]; - std::map m_thread_names; + std::map m_thread_names; mutable std::mutex m_mutex; bool m_trace_enabled; }; @@ -107,20 +117,23 @@ class StreamLogOutput : public ICombinedLogOutput { 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) { @@ -133,23 +146,27 @@ class FileLogOutput : public ICombinedLogOutput { 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(); } - bool empty() + bool empty() const { return m_buffer.empty(); } @@ -175,14 +192,8 @@ 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. @@ -205,13 +216,4 @@ 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 - - -#endif