From 2dfba8ee3a04ef8173c5f975c4daf1575c04f342 Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 2 Aug 2018 14:17:28 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E8=AF=8D=E8=BF=87=E6=BB=A4=E5=8A=9F=E8=83=BD=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E8=BF=87=E6=BB=A4=E8=84=8F=E6=95=B0=E6=8D=AE=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: armink --- easylogger/inc/elog.h | 2 +- easylogger/src/elog.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/easylogger/inc/elog.h b/easylogger/inc/elog.h index 593c9d2..77522f0 100644 --- a/easylogger/inc/elog.h +++ b/easylogger/inc/elog.h @@ -50,7 +50,7 @@ extern "C" { #define ELOG_LVL_TOTAL_NUM 6 /* EasyLogger software version number */ -#define ELOG_SW_VERSION "2.0.1" +#define ELOG_SW_VERSION "2.0.2" /* EasyLogger assert for developer. */ #ifdef ELOG_ASSERT_ENABLE diff --git a/easylogger/src/elog.c b/easylogger/src/elog.c index 0a93155..8998a71 100644 --- a/easylogger/src/elog.c +++ b/easylogger/src/elog.c @@ -1,7 +1,7 @@ /* * This file is part of the EasyLogger Library. * - * Copyright (c) 2015-2017, Armink, + * Copyright (c) 2015-2016, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -497,11 +497,19 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f #endif /* keyword filter */ - if (!strstr(log_buf, elog.filter.keyword)) { - //TODO 可以考虑采用KMP及朴素模式匹配字符串,提升性能 - /* unlock output */ - elog_output_unlock(); - return; + if (elog.filter.keyword[0] != '\0') { + /* add string end sign */ + if (fmt_result > -1) + { + log_buf[log_len + fmt_result] = '\0'; + } + + if (!strstr(log_buf, elog.filter.keyword)) + { + /* unlock output */ + elog_output_unlock(); + return; + } } /* package newline sign */ if ((fmt_result > -1) && (fmt_result + log_len + newline_len <= ELOG_LINE_BUF_SIZE)) {