diff --git a/docs/processor.md b/docs/processor.md index e787055..6042ad6 100644 --- a/docs/processor.md +++ b/docs/processor.md @@ -140,11 +140,11 @@ ### 日志 -日志在标准异常流(`stderr`)输出,日志包含调试(`D`)、信息(`I`)、警告(`W`)、异常(`E`)、致命(`F`)五个等级,格式为时间、半回合号、等级和详细信息,随后尾随控制字符 LF(`\n`),即 `{year}-{month}-{day} {hour}:{minute}:{second} {halfturn_id} [{level}] {msg}\n`。例如 +日志在标准异常流(`stderr`)输出,日志包含调试(`D`)、信息(`I`)、警告(`W`)、异常(`E`)、致命(`F`)五个等级,格式为时间、等级和详细信息,随后尾随控制字符 LF(`\n`),即 `{year}-{month}-{day} {hour}:{minute}:{second} [{level}] {msg}\n`。例如 ```plaintext -2022-10-10 21:00:01 2 [W] discarded bad move(34 57E) from player 1: target is out of border. -2022-10-10 21:00:01 2 [W] 已丢弃非法移动 (34 57E) 来自玩家 1: 目标格在边界外. +2022-10-10 21:00:01 [W] discarded bad move(34 57E) from player 1: target is out of border. +2022-10-10 21:00:01 [W] 已丢弃非法移动 (34 57E) 来自玩家 1: 目标格在边界外. ``` #### 日志等级与编码 diff --git a/processor/utility/log.h b/processor/utility/log.h new file mode 100644 index 0000000..1611ac2 --- /dev/null +++ b/processor/utility/log.h @@ -0,0 +1,27 @@ +#ifndef OG_LOG_H_ +#define OG_LOG_H_ + +#include +#include +#include "pc/commcode.h" + +class Logger { +public: + Logger *getInstance() const; + + void debug(const std::string &) const; + void info(const std::string &) const; + void warn(const std::string &) const; + void error(const std::string &) const; + void fatal(const std::string &) const; + +private: + Logger(); + void _log(LogLevel v, const std::string &) const; + + LogLevel filter; +}; + +Logger *Log(); + +#endif