From 3fee41c061bb1d18ca20d233db7613b099aeda2f Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 24 Nov 2016 11:47:14 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91?= =?UTF-8?q?=E8=BD=AF=E4=BB=B6=E8=BF=90=E8=A1=8C=E6=97=B6=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E4=BD=BF=E8=83=BD=E5=8F=8A=E5=A4=B1=E8=83=BD=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E5=8F=8A=E7=BC=93=E5=86=B2=E8=BE=93=E5=87=BA=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E3=80=82=E4=BD=BF=E5=BE=97=E8=BD=AF=E4=BB=B6?= =?UTF-8?q?=E5=9C=A8=E5=87=BA=E7=8E=B0=E5=BC=82=E5=B8=B8=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=97=A5=E5=BF=97=E5=8F=AF=E4=BB=A5=E5=9C=A8?= =?UTF-8?q?=E8=A2=AB=E6=AD=A3=E5=B8=B8=E8=BE=93=E5=87=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: armink --- .../os/rt-thread/stm32f10x/app/src/app_task.c | 12 ++++++++++ easylogger/inc/elog.h | 4 +++- easylogger/inc/elog_cfg.h | 2 +- easylogger/src/elog.c | 12 +++++++--- easylogger/src/elog_async.c | 24 +++++++++++++++---- easylogger/src/elog_buf.c | 17 +++++++++++++ 6 files changed, 62 insertions(+), 9 deletions(-) diff --git a/demo/os/rt-thread/stm32f10x/app/src/app_task.c b/demo/os/rt-thread/stm32f10x/app/src/app_task.c index 0110e65..f32dcfa 100644 --- a/demo/os/rt-thread/stm32f10x/app/src/app_task.c +++ b/demo/os/rt-thread/stm32f10x/app/src/app_task.c @@ -121,6 +121,12 @@ void sys_init_thread(void* parameter){ } static void elog_user_assert_hook(const char* ex, const char* func, size_t line) { + +#ifdef ELOG_ASYNC_OUTPUT_ENABLE + /* disable async output */ + elog_async_enabled(false); +#endif + /* disable logger output lock */ elog_output_lock_enabled(false); /* disable flash plugin lock */ @@ -133,6 +139,12 @@ static void elog_user_assert_hook(const char* ex, const char* func, size_t line) } static void rtt_user_assert_hook(const char* ex, const char* func, rt_size_t line) { + +#ifdef ELOG_ASYNC_OUTPUT_ENABLE + /* disable async output */ + elog_async_enabled(false); +#endif + /* disable logger output lock */ elog_output_lock_enabled(false); /* disable flash plugin lock */ diff --git a/easylogger/inc/elog.h b/easylogger/inc/elog.h index 1dcf5ba..13a8e9e 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 "1.11.13" +#define ELOG_SW_VERSION "1.11.22" /* EasyLogger assert for developer. */ #ifdef ELOG_ASSERT_ENABLE @@ -190,9 +190,11 @@ void elog_assert_set_hook(void (*hook)(const char* expr, const char* func, size_ /* elog_buf.c */ void elog_flush(void); +void elog_buf_enabled(bool enabled); /* elog_async.c */ size_t elog_async_get_log(char *log, size_t size); +void elog_async_enabled(bool enabled); /* elog_utils.c */ size_t elog_strcpy(size_t cur_len, char *dst, const char *src); diff --git a/easylogger/inc/elog_cfg.h b/easylogger/inc/elog_cfg.h index 1e399bc..2757789 100644 --- a/easylogger/inc/elog_cfg.h +++ b/easylogger/inc/elog_cfg.h @@ -61,7 +61,7 @@ #define ELOG_ASYNC_OUTPUT_USING_PTHREAD /* enable buffered output mode */ -#define ELOG_BUFF_OUTPUT_ENABLE +#define ELOG_BUF_OUTPUT_ENABLE /* buffer size for buffered output mode */ #define ELOG_BUF_OUTPUT_BUF_SIZE (ELOG_LINE_BUF_SIZE * 10) diff --git a/easylogger/src/elog.c b/easylogger/src/elog.c index 72458b5..8276efc 100644 --- a/easylogger/src/elog.c +++ b/easylogger/src/elog.c @@ -173,7 +173,6 @@ ElogErrCode elog_init(void) { /* set level is ELOG_LVL_VERBOSE */ elog_set_filter_lvl(ELOG_LVL_VERBOSE); - return result; } @@ -183,6 +182,13 @@ ElogErrCode elog_init(void) { void elog_start(void) { /* enable output */ elog_set_output_enabled(true); + +#if defined(ELOG_ASYNC_OUTPUT_ENABLE) + elog_async_enabled(true); +#elif defined(ELOG_BUF_OUTPUT_ENABLE) + elog_buf_enabled(true); +#endif + /* show version */ elog_i(log_tag, "EasyLogger V%s is initialize success.", ELOG_SW_VERSION); elog_i(log_tag, "You can get the latest version on https://github.com/armink/EasyLogger ."); @@ -341,7 +347,7 @@ void elog_raw(const char *format, ...) { #if defined(ELOG_ASYNC_OUTPUT_ENABLE) extern void elog_async_output(const char *log, size_t size); elog_async_output(log_buf, log_len); -#elif defined(ELOG_BUFF_OUTPUT_ENABLE) +#elif defined(ELOG_BUF_OUTPUT_ENABLE) extern void elog_buf_output(const char *log, size_t size); elog_buf_output(log_buf, log_len); #else @@ -491,7 +497,7 @@ void elog_output(uint8_t level, const char *tag, const char *file, const char *f #if defined(ELOG_ASYNC_OUTPUT_ENABLE) extern void elog_async_output(const char *log, size_t size); elog_async_output(log_buf, log_len); -#elif defined(ELOG_BUFF_OUTPUT_ENABLE) +#elif defined(ELOG_BUF_OUTPUT_ENABLE) extern void elog_buf_output(const char *log, size_t size); elog_buf_output(log_buf, log_len); #else diff --git a/easylogger/src/elog_async.c b/easylogger/src/elog_async.c index 038ccfa..86d23e0 100644 --- a/easylogger/src/elog_async.c +++ b/easylogger/src/elog_async.c @@ -63,6 +63,8 @@ static pthread_t async_output_thread; /* Initialize OK flag */ static bool init_ok = false; +/* asynchronous output mode enabled flag */ +static bool is_enabled = false; /* asynchronous output mode's ring buffer */ static char log_buf[ELOG_ASYNC_OUTPUT_BUF_SIZE] = { 0 }; /* log ring buffer write index */ @@ -193,10 +195,14 @@ void elog_async_output(const char *log, size_t size) { extern void elog_async_output_notice(void); size_t put_size; - put_size = async_put_log(log, size); - /* notify output log thread */ - if (put_size > 0) { - elog_async_output_notice(); + if (is_enabled) { + put_size = async_put_log(log, size); + /* notify output log thread */ + if (put_size > 0) { + elog_async_output_notice(); + } + } else { + elog_port_output(log, size); } } @@ -228,6 +234,16 @@ static void *async_output(void *arg) { } #endif +/** + * enable or disable asynchronous output mode + * the log will be output directly when mode is disabled + * + * @param enabled true: enabled, false: disabled + */ +void elog_async_enabled(bool enabled) { + is_enabled = enabled; +} + /** * asynchronous output mode initialize * diff --git a/easylogger/src/elog_buf.c b/easylogger/src/elog_buf.c index b3e3ea2..b4a8f10 100644 --- a/easylogger/src/elog_buf.c +++ b/easylogger/src/elog_buf.c @@ -38,6 +38,8 @@ static char log_buf[ELOG_BUF_OUTPUT_BUF_SIZE] = { 0 }; /* log buffer current write size */ static size_t buf_write_size = 0; +/* buffered output mode enabled flag */ +static bool is_enabled = false; extern void elog_port_output(const char *log, size_t size); extern void elog_output_lock(void); @@ -52,6 +54,11 @@ extern void elog_output_unlock(void); void elog_buf_output(const char *log, size_t size) { size_t write_size = 0, write_index = 0; + if (!is_enabled) { + elog_port_output(log, size); + return; + } + while (true) { if (buf_write_size + size > ELOG_BUF_OUTPUT_BUF_SIZE) { write_size = ELOG_BUF_OUTPUT_BUF_SIZE - buf_write_size; @@ -84,4 +91,14 @@ void elog_flush(void) { /* unlock output */ elog_output_unlock(); } + +/** + * enable or disable buffered output mode + * the log will be output directly when mode is disabled + * + * @param enabled true: enabled, false: disabled + */ +void elog_buf_enabled(bool enabled) { + is_enabled = enabled; +} #endif /* ELOG_BUF_OUTPUT_ENABLE */