Files
XCEngine/docs/api/XCEngine/Debug/Logger/Log.md

78 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Logger::Log
构造一条 `LogEntry` 并把它分发给所有已注册 sink。
```cpp
void Log(
LogLevel level,
LogCategory category,
const Containers::String& message,
const char* file = nullptr,
int32_t line = 0,
const char* function = nullptr
);
```
## 行为说明
当前实现依次执行以下步骤:
1. 如果 `Logger` 尚未初始化,先调用 `Initialize()`
2. 如果 `level < m_minimumLevel`,直接丢弃日志。
3. 如果 category 对应的启用位为关闭状态,直接丢弃日志。
4. 构造 `LogEntry`,填充:
- `level`
- `category`
- `message`
- `file`
- `line`
- `function`
- 当前秒级时间戳
- 当前线程哈希值
5. 在互斥区内遍历所有 sink 并调用其 `Log(entry)`
需要注意:
- 如果没有注册任何 sink日志会被静默丢弃。
- 当前时间戳粒度是“秒”,不是毫秒或微秒。
- 当前线程 ID 是哈希结果,不保证与系统线程号一致。
## 参数
- `level` - 日志级别。
- `category` - 日志分类。
- `message` - 日志文本。
- `file` - 可选的源文件路径。
- `line` - 可选的源码行号。
- `function` - 可选的函数名。
## 返回值
- 无。
## 线程语义
- sink 分发过程在互斥区内执行。
- `SetMinimumLevel``SetCategoryEnabled` 当前无锁,因此在高并发日志期间动态修改配置时要自行承担竞争风险。
## 示例
```cpp
using namespace XCEngine::Debug;
Logger::Get().Log(
LogLevel::Warning,
LogCategory::General,
"Fallback code path selected",
__FILE__,
__LINE__,
__FUNCTION__
);
```
## 相关文档
- [返回类型总览](Logger.md)
- [Verbose](Verbose.md)
- [XE_LOG 宏所在类型页](Logger.md)