完成拦截器设计
This commit is contained in:
45
README.md
45
README.md
@@ -55,4 +55,47 @@ int main() {
|
||||
destroyLogging(log);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
### 日志拦截器
|
||||
> 支持添加自定义的拦截器, 目前内置了子串拦截器
|
||||
|
||||
> 拦截器的作用:可以将拦截到的日志重定向到拦截器的专属处理器中
|
||||
|
||||
|
||||
#### 例子
|
||||
将拦截到的日志重定向到专属文件处理器中
|
||||
```c
|
||||
#include "logging.h"
|
||||
|
||||
|
||||
int main() {
|
||||
Logging *log = createLogging();
|
||||
Logger *logger = log->getLogger("testLogger",LOG_DEBUG);
|
||||
logger->addHandler(consoleHandler("test"));
|
||||
|
||||
logger->info("This is an info message");
|
||||
logger->error("你好,这是一个错误消息%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 = substringInterceptor(test1,2,LOG_DEBUG,fileHandler("被拦截"));
|
||||
logger->addInterceptor(tint);
|
||||
printf("Interceptor added\n");
|
||||
|
||||
logger->info("This is an info message");
|
||||
logger->error("你好,这是一个错误消息%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");
|
||||
|
||||
destroyLogging(log);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
.png)
|
||||

|
||||
|
||||
Reference in New Issue
Block a user