* #feat 增强Fatal级别的底色,修改logging类的方法

* 更新版本号

* 加入test脚本

* fix:conanfile

* test action

* 修复错别字

* add test on windows action

* fix test on windows action

* fix action on windows

* fix

* fix 内存分配错误

* fix msvc 不支持中文注释,删除中文注释

* test on windows and test  chinese char

* ersion 0.2.4

* feature:根据文件大小分割日志

* fix:内存泄露

* fix:使用char偏移单位
This commit is contained in:
youmetme
2024-11-20 11:56:47 +08:00
committed by GitHub
parent 650ce0dc3f
commit d0bfc31563
13 changed files with 231 additions and 93 deletions

View File

@@ -11,6 +11,15 @@ logging是一个轻量级的简单易用C语言日志库支持日志级别、
- 支持日志输出:控制台、文件
- 支持日志文件:自动创建、自动滚动、自动删除(未完成)
## 安装
- conan安装使用
```shell
conan create . --build=missing
```
- cmake安装使用
```shell
```
## 使用方法
### 控制台日志
@@ -18,16 +27,15 @@ logging是一个轻量级的简单易用C语言日志库支持日志级别、
#include "logging.h"
int main() {
Logging *log = newLogging();
Logger *logger = log->getLogger("testLogger", LOG_DEBUG);
Logger *logger = newLogger("testLogger", LOG_DEBUG);
logger->info("This is an info message");
logger->error("你好,这是一个错误消息%s", "123");
logger->error("This is an error message%s", "123");
logger->fatal("This is an fatal message");
logger->debug("This is a debug message");
logger->warning("This is a warning message%s", "123");
log->destroyLogging(log);
destroyLogger();
return 0;
}
```
@@ -35,20 +43,19 @@ int main() {
### 文件日志
```c
#include "logging.h"
#include "logging/logging-handler.h"
int main() {
Logging *log = newLogging();
Logger *logger = log->getLogger("testLogger",LOG_DEBUG);
logger->addHandler(loggingFileHandler("test")); //为日志对象添加文件处理器
Logger *logger = newLogger("testLogger", LOG_DEBUG);
logger->addHandler(loggingFileHandler("test1", 1024*1024));
logger->info("This is an info message");
logger->error("你好,这是一个错误消息%s", "123");
logger->error("This is an error message%s", "123");
logger->fatal("This is an fatal message");
logger->debug("This is a debug message");
logger->warning("This is a warning message%s", "123");
log->destroyLogging(log);
destroyLogger();
return 0;
}
```
@@ -66,19 +73,21 @@ int main() {
#include <stdio.h>
int main() {
Logging *log = newLogging();
Logger *logger = log->getLogger("testLogger", LOG_DEBUG);
Logger *logger = newLogger("testLogger", LOG_DEBUG);
logger->info("This is an info message");
logger->error("你好,这是一个错误消息%s", "123");
logger->error("This is an error message%s", "123");
logger->fatal("This is an fatal message");
logger->debug("This is a debug message");
logger->warning("This is a warning message%s", "123");
char *test1[] = {"123", "你好"}; // 要拦截的字符串
// 添加拦截器,将拦截到的日志重定向到拦截器的专属处理器中
log_Interceptor *tint =
loggingSubStringInterceptor(test1, 2, LOG_DEBUG, loggingFileHandler("被拦截"));
char *test1[] = {"123", "tt"};
log_Interceptor *tint = loggingSubStringInterceptor(
test1,
2,
LOG_DEBUG,
loggingFileHandler("test_interceptor", 1024 * 1024));
logger->addInterceptor(tint);
@@ -87,20 +96,15 @@ int main() {
printf("\n");
logger->info("This is an info message");
logger->error("你好,这是一个错误消息%s", "123");
logger->error("This is an error message%s", "123");
logger->fatal("This is an fatal message");
logger->debug("This is a debug message");
logger->warning("This is a warning message%s", "123");
log->destroyLogging(log);
destroyLogger();
return 0;
}
```
![](docs/img/2024-09-21-11-44-25.png)
![](docs/img/2024-09-21-11-44-06.png)
# build
```shell
conan create . --build=missing
```