Add log.h
Signed-off-by: szdytom <szdytom@qq.com>
This commit is contained in:
parent
399e6f38c8
commit
836908765f
@ -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: 目标格在边界外.
|
||||
```
|
||||
|
||||
#### 日志等级与编码
|
||||
|
27
processor/utility/log.h
Normal file
27
processor/utility/log.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef OG_LOG_H_
|
||||
#define OG_LOG_H_
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#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
|
Loading…
x
Reference in New Issue
Block a user