设置级别颜色 - LogSetLevelColor
函数简介
设置指定日志级别的控制台输出颜色。
接口名称
LogSetLevelColor
DLL调用
int32_t LogSetLevelColor(int64_t instance, int64_t loggerHandle, int32_t level, int32_t color)
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | int64_t | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成 |
| loggerHandle | int64_t | 日志实例句柄(0 表示默认实例) |
| level | int32_t | 日志级别,见 LogLevel 枚举 |
| color | int32_t | 控制台颜色,见 LogConsoleColor 枚举 |
LogConsoleColor 枚举值
| 枚举值 | 值 | 说明 |
|---|---|---|
| OLA_LOG_COLOR_BLACK | 0x00 | 黑色 |
| OLA_LOG_COLOR_DARK_BLUE | 0x01 | 深蓝色 |
| OLA_LOG_COLOR_DARK_GREEN | 0x02 | 深绿色 |
| OLA_LOG_COLOR_DARK_CYAN | 0x03 | 深青色 |
| OLA_LOG_COLOR_DARK_RED | 0x04 | 深红色 |
| OLA_LOG_COLOR_DARK_MAGENTA | 0x05 | 深洋红色 |
| OLA_LOG_COLOR_DARK_YELLOW | 0x06 | 深黄色 |
| OLA_LOG_COLOR_GRAY | 0x07 | 灰色 |
| OLA_LOG_COLOR_DARK_GRAY | 0x08 | 深灰色 |
| OLA_LOG_COLOR_BLUE | 0x09 | 蓝色 |
| OLA_LOG_COLOR_GREEN | 0x0A | 绿色 |
| OLA_LOG_COLOR_CYAN | 0x0B | 青色 |
| OLA_LOG_COLOR_RED | 0x0C | 红色 |
| OLA_LOG_COLOR_MAGENTA | 0x0D | 洋红色 |
| OLA_LOG_COLOR_YELLOW | 0x0E | 黄色 |
| OLA_LOG_COLOR_WHITE | 0x0F | 白色 |
示例
// 设置INFO级别为青色
int result = LogSetLevelColor(instance, 0, OLA_LOG_LEVEL_INFO, OLA_LOG_COLOR_CYAN);
// 设置ERROR级别为红色
int result = LogSetLevelColor(instance, 0, OLA_LOG_LEVEL_ERROR, OLA_LOG_COLOR_RED);
// 设置WARN级别为黄色
int result = LogSetLevelColor(instance, 0, OLA_LOG_LEVEL_WARN, OLA_LOG_COLOR_YELLOW);
// 自定义颜色方案
LogSetLevelColor(instance, 0, OLA_LOG_LEVEL_TRACE, OLA_LOG_COLOR_GRAY);
LogSetLevelColor(instance, 0, OLA_LOG_LEVEL_DEBUG, OLA_LOG_COLOR_CYAN);
LogSetLevelColor(instance, 0, OLA_LOG_LEVEL_INFO, OLA_LOG_COLOR_GREEN);
LogSetLevelColor(instance, 0, OLA_LOG_LEVEL_WARN, OLA_LOG_COLOR_YELLOW);
LogSetLevelColor(instance, 0, OLA_LOG_LEVEL_ERROR, OLA_LOG_COLOR_RED);
LogSetLevelColor(instance, 0, OLA_LOG_LEVEL_CRITICAL, OLA_LOG_COLOR_MAGENTA);
返回值
| 返回值 | 说明 |
|---|---|
| 0 | 失败 |
| 1 | 成功 |
注意事项
- 仅在控制台输出启用且颜色模式不为 NEVER 时生效
- 修改后立即生效,如果日志系统已初始化,会自动重新初始化
- 可以使用位或运算组合颜色,例如:
OLA_LOG_COLOR_FOREGROUND_RED | OLA_LOG_COLOR_FOREGROUND_GREEN= 黄色 - 添加
OLA_LOG_COLOR_FOREGROUND_INTENSITY(0x08) 可以使颜色变亮
