26#include <kiwano/core/Common.h> 
   27#include <kiwano/core/Time.h> 
   28#include <kiwano/base/ObjectBase.h> 
   32#define KGE_DEBUG_LOG(...) ::kiwano::Logger::GetInstance().Log(::kiwano::LogLevel::Debug, __VA_ARGS__) 
   34#define KGE_DEBUG_LOG __noop 
   39#define KGE_LOG(...) ::kiwano::Logger::GetInstance().Log(::kiwano::LogLevel::Info, __VA_ARGS__) 
   43#define KGE_NOTICE(...) ::kiwano::Logger::GetInstance().Log(::kiwano::LogLevel::Notice, __VA_ARGS__) 
   47#define KGE_WARN(...) ::kiwano::Logger::GetInstance().Log(::kiwano::LogLevel::Warning, __VA_ARGS__) 
   51#define KGE_ERROR(...) ::kiwano::Logger::GetInstance().Log(::kiwano::LogLevel::Error, __VA_ARGS__) 
   56#define KGE_DEBUG_LOGF(FORMAT, ...) ::kiwano::Logger::GetInstance().Logf(::kiwano::LogLevel::Debug, FORMAT, __VA_ARGS__) 
   58#define KGE_DEBUG_LOGF __noop 
   63#define KGE_LOGF(FORMAT, ...) ::kiwano::Logger::GetInstance().Logf(::kiwano::LogLevel::Info, FORMAT, __VA_ARGS__) 
   67#define KGE_NOTICEF(FORMAT, ...) ::kiwano::Logger::GetInstance().Logf(::kiwano::LogLevel::Notice, FORMAT, __VA_ARGS__) 
   71#define KGE_WARNF(FORMAT, ...) ::kiwano::Logger::GetInstance().Logf(::kiwano::LogLevel::Warning, FORMAT, __VA_ARGS__) 
   75#define KGE_ERRORF(FORMAT, ...) ::kiwano::Logger::GetInstance().Logf(::kiwano::LogLevel::Error, FORMAT, __VA_ARGS__) 
   79#define KGE_THROW(MESSAGE)                                \ 
   82        KGE_ERRORF("An exception occurred: %s", MESSAGE); \
 
   83        kiwano::StackTracer().Print();                    \
 
   84        throw kiwano::RuntimeError(MESSAGE);              \
 
   89#define KGE_THROW_IF(EXPRESSION, MESSAGE) \ 
   96#ifndef KGE_THROW_SYSTEM_ERROR 
   97#define KGE_THROW_SYSTEM_ERROR(ERRCODE, MESSAGE)                                          \ 
  100        KGE_ERRORF("An exception occurred (%#x): %s", ERRCODE, MESSAGE);                  \
 
  101        kiwano::StackTracer().Print();                                                    \
 
  102        throw kiwano::SystemError(std::error_code(kiwano::error_enum(ERRCODE)), MESSAGE); \
 
  106#ifdef KGE_PLATFORM_WINDOWS 
  107#ifndef KGE_THROW_IF_FAILED 
  108#define KGE_THROW_IF_FAILED(HR, MESSAGE)     \ 
  111        KGE_THROW_SYSTEM_ERROR(HR, MESSAGE); \ 
  139    virtual void FormatHeader(std::ostream& out, LogLevel level, 
ClockTime time) = 0;
 
  141    virtual void FormatFooter(std::ostream& out, LogLevel level) = 0;
 
  143    String GetLevelLabel(LogLevel level) 
const;
 
  155    void Resize(
size_t size);
 
  159    const char* GetRaw() 
const;
 
  166    int_type overflow(int_type ch) 
override;
 
  168    int_type underflow() 
override;
 
  170    pos_type seekpos(pos_type sp, std::ios_base::openmode which) 
override;
 
  172    pos_type seekoff(off_type off, std::ios_base::seekdir dir,
 
  173                     std::ios_base::openmode which = std::ios_base::in) 
override;
 
  176    Vector<char_type> buf_;
 
  177    char_type*        seek_high_;
 
  191    virtual void Flush();
 
  193    void Write(LogLevel level, 
const char* msg);
 
  195    void SetLevel(LogLevel level);
 
  200    virtual void WriteMessage(LogLevel level, 
const char* msg) = 0;
 
  217    void Init() 
override;
 
  219    void Flush() 
override;
 
  222    void WriteMessage(LogLevel level, 
const char* msg) 
override;
 
  225    typedef std::ostream& (*ConsoleColor)(std::ostream&);
 
  227    ConsoleColor GetColor(LogLevel level);
 
  241    void Init() 
override;
 
  243    void Flush() 
override;
 
  246    void WriteMessage(LogLevel level, 
const char* msg) 
override;
 
  265    void Logf(LogLevel level, 
const char* format, ...);
 
  271    template <
typename... _Args>
 
  272    void Log(LogLevel level, _Args&&... args);
 
  288    void SetLevel(LogLevel level);
 
  308    void ResizeBuffer(
size_t buffer_size);
 
  312    void ShowConsole(
bool show);
 
  319    std::iostream& GetFormatedStream(LogLevel level, 
LogBuffer* buffer);
 
  321    void WriteToProviders(LogLevel level, 
LogBuffer* buffer);
 
  328    std::iostream               stream_;
 
  329    Vector<RefPtr<LogProvider>> providers_;
 
  345    formater_ = formater;
 
  348template <
typename... _Args>
 
  357    std::lock_guard<std::mutex> lock(mutex_);
 
  360    auto& stream = this->GetFormatedStream(level, &this->buffer_);
 
  361    (void)std::initializer_list<int>{ ((stream << 
' ' << args), 0)... };
 
  364    this->WriteToProviders(level, &this->buffer_);
 
控制台日志生产者
Definition: Logger.h:211
文件日志生产者
Definition: Logger.h:235
日志流缓冲
Definition: Logger.h:151
日志生产者
Definition: Logger.h:185
日志记录器
Definition: Logger.h:257
void Enable()
启用日志
Definition: Logger.h:333
void SetFormater(RefPtr< LogFormater > formater)
设置日志格式
Definition: Logger.h:343
void Disable()
禁用日志
Definition: Logger.h:338
void Log(LogLevel level, _Args &&... args)
打印日志
Definition: Logger.h:349
基础对象
Definition: ObjectBase.h:138
引用计数智能指针
Definition: RefBasePtr.hpp:35
Definition: Singleton.h:28
时钟时间
Definition: Time.h:74