From abbf1e0f19ca78e89ff47f8fdcf1824b014a05aa Mon Sep 17 00:00:00 2001 From: armink Date: Thu, 9 Feb 2017 11:12:15 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91l?= =?UTF-8?q?og=5Fx=20=E5=8F=8A=20assert=20API=EF=BC=8C=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9A=84=E4=B9=A6=E5=86=99=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=EF=BC=9B=202=E3=80=81=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91?= =?UTF-8?q?=E6=8C=89=E4=BA=A7=E5=93=81=E6=A8=A1=E5=9D=97=E5=8F=AF=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=E4=BC=98=E5=85=88?= =?UTF-8?q?=E7=BA=A7=E7=9A=84=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: armink --- demo/non_os/stm32f10x/app/src/app.c | 17 +- demo/os/linux/main.c | 15 +- .../os/rt-thread/stm32f10x/app/src/app_task.c | 29 ++-- .../components/easyflash/inc/easyflash.h | 2 +- .../components/easyflash/src/ef_env.c | 9 + .../components/easyflash/src/ef_env_wl.c | 8 + demo/os/windows/main.c | 15 +- docs/zh/api/kernel.md | 83 +++++---- easylogger/inc/elog.h | 162 +++++++++++------- easylogger/plugins/flash/elog_flash.c | 11 +- easylogger/plugins/flash/elog_flash.h | 4 +- easylogger/src/elog.c | 63 ++++--- easylogger/src/elog_utils.c | 15 +- 13 files changed, 233 insertions(+), 200 deletions(-) diff --git a/demo/non_os/stm32f10x/app/src/app.c b/demo/non_os/stm32f10x/app/src/app.c index eacae2a..508ba0c 100644 --- a/demo/non_os/stm32f10x/app/src/app.c +++ b/demo/non_os/stm32f10x/app/src/app.c @@ -25,20 +25,13 @@ * Function: non-os stm32f10x demo. * Created on: 2015-07-31 */ - -#include "bsp.h" -#include -#include -#include "elog.h" #define LOG_TAG "main" -#define assert ELOG_ASSERT -#define log_a(...) elog_a(LOG_TAG, __VA_ARGS__) -#define log_e(...) elog_e(LOG_TAG, __VA_ARGS__) -#define log_w(...) elog_w(LOG_TAG, __VA_ARGS__) -#define log_i(...) elog_i(LOG_TAG, __VA_ARGS__) -#define log_d(...) elog_d(LOG_TAG, __VA_ARGS__) -#define log_v(...) elog_v(LOG_TAG, __VA_ARGS__) + +#include +#include +#include +#include static void test_elog(void); diff --git a/demo/os/linux/main.c b/demo/os/linux/main.c index df06a1d..f3eb6ac 100644 --- a/demo/os/linux/main.c +++ b/demo/os/linux/main.c @@ -1,7 +1,7 @@ /* * This file is part of the EasyLogger Library. * - * Copyright (c) 2015, Armink, + * Copyright (c) 2015-2017, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -26,19 +26,12 @@ * Created on: 2015-07-30 */ +#define LOG_TAG "main" + +#include #include #include #include -#include "elog.h" - -#define LOG_TAG "main" -#define assert ELOG_ASSERT -#define log_a(...) elog_a(LOG_TAG, __VA_ARGS__) -#define log_e(...) elog_e(LOG_TAG, __VA_ARGS__) -#define log_w(...) elog_w(LOG_TAG, __VA_ARGS__) -#define log_i(...) elog_i(LOG_TAG, __VA_ARGS__) -#define log_d(...) elog_d(LOG_TAG, __VA_ARGS__) -#define log_v(...) elog_v(LOG_TAG, __VA_ARGS__) static void test_elog(void); 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 f32dcfa..4e5418e 100644 --- a/demo/os/rt-thread/stm32f10x/app/src/app_task.c +++ b/demo/os/rt-thread/stm32f10x/app/src/app_task.c @@ -1,14 +1,16 @@ -#include "app_task.h" +#define LOG_TAG "main" + +#include #include #include -#include "bsp.h" -#include "elog_flash.h" -#include "easyflash.h" -#include "finsh.h" -#include "shell.h" -#include "cpuusage.h" -#include "delay_conf.h" -#include "utils.h" +#include +#include +#include +#include +#include +#include +#include +#include #ifdef __CC_ARM extern int Image$$RW_IRAM1$$ZI$$Limit; @@ -18,15 +20,6 @@ extern int Image$$RW_IRAM1$$ZI$$Limit; extern int __bss_end; #endif -#define LOG_TAG "main" -#define assert ELOG_ASSERT -#define log_a(...) elog_a(LOG_TAG, __VA_ARGS__) -#define log_e(...) elog_e(LOG_TAG, __VA_ARGS__) -#define log_w(...) elog_w(LOG_TAG, __VA_ARGS__) -#define log_i(...) elog_i(LOG_TAG, __VA_ARGS__) -#define log_d(...) elog_d(LOG_TAG, __VA_ARGS__) -#define log_v(...) elog_v(LOG_TAG, __VA_ARGS__) - #define thread_sys_monitor_prio 30 ALIGN(RT_ALIGN_SIZE) diff --git a/demo/os/rt-thread/stm32f10x/components/easyflash/inc/easyflash.h b/demo/os/rt-thread/stm32f10x/components/easyflash/inc/easyflash.h index a02671c..1efdc93 100644 --- a/demo/os/rt-thread/stm32f10x/components/easyflash/inc/easyflash.h +++ b/demo/os/rt-thread/stm32f10x/components/easyflash/inc/easyflash.h @@ -67,7 +67,7 @@ if (!(EXPR)) \ while (1); \ } /* EasyFlash software version number */ -#define EF_SW_VERSION "2.11.24" +#define EF_SW_VERSION "2.12.08" typedef struct _ef_env{ char *key; diff --git a/demo/os/rt-thread/stm32f10x/components/easyflash/src/ef_env.c b/demo/os/rt-thread/stm32f10x/components/easyflash/src/ef_env.c index b1ce732..dbfc0c0 100644 --- a/demo/os/rt-thread/stm32f10x/components/easyflash/src/ef_env.c +++ b/demo/os/rt-thread/stm32f10x/components/easyflash/src/ef_env.c @@ -185,6 +185,15 @@ EfErrCode ef_env_set_default(void){ result = ef_save_env(); +#ifdef EF_ENV_USING_PFS_MODE + /* reset other PFS area's data */ + if (result == EF_NO_ERR) { + env_cache_changed = true; + result = ef_save_env(); + } +#endif + + return result; } diff --git a/demo/os/rt-thread/stm32f10x/components/easyflash/src/ef_env_wl.c b/demo/os/rt-thread/stm32f10x/components/easyflash/src/ef_env_wl.c index d02029c..512d5cb 100644 --- a/demo/os/rt-thread/stm32f10x/components/easyflash/src/ef_env_wl.c +++ b/demo/os/rt-thread/stm32f10x/components/easyflash/src/ef_env_wl.c @@ -189,6 +189,14 @@ EfErrCode ef_env_set_default(void){ result = ef_save_env(); +#ifdef EF_ENV_USING_PFS_MODE + /* reset other PFS area's data */ + if (result == EF_NO_ERR) { + env_cache_changed = true; + result = ef_save_env(); + } +#endif + return result; } diff --git a/demo/os/windows/main.c b/demo/os/windows/main.c index eba6356..7bfbd40 100644 --- a/demo/os/windows/main.c +++ b/demo/os/windows/main.c @@ -1,7 +1,7 @@ /* * This file is part of the EasyLogger Library. * - * Copyright (c) 2015, Armink, + * Copyright (c) 2015-2017, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -26,19 +26,12 @@ * Created on: 2015-07-30 */ +#define LOG_TAG "main" + +#include #include #include #include -#include "elog.h" - -#define LOG_TAG "main" -#define assert ELOG_ASSERT -#define log_a(...) elog_a(LOG_TAG, __VA_ARGS__) -#define log_e(...) elog_e(LOG_TAG, __VA_ARGS__) -#define log_w(...) elog_w(LOG_TAG, __VA_ARGS__) -#define log_i(...) elog_i(LOG_TAG, __VA_ARGS__) -#define log_d(...) elog_d(LOG_TAG, __VA_ARGS__) -#define log_v(...) elog_v(LOG_TAG, __VA_ARGS__) static void test_elog(void); diff --git a/docs/zh/api/kernel.md b/docs/zh/api/kernel.md index 6b3003f..0b02b27 100644 --- a/docs/zh/api/kernel.md +++ b/docs/zh/api/kernel.md @@ -10,7 +10,7 @@ ### 1.1 初始化 -初始化的EasyLogger的核心功能,初始化后才可以使用下面的API。 +初始化的 EasyLogger 的核心功能,初始化后才可以使用下面的API。 ``` ElogErrCode elog_init(void) @@ -40,26 +40,32 @@ void elog_start(void) #### 1.3.1 输出基本日志 -所有级别的日志输出方法如下,每种级别都有一种简写方式,用户可以自行选择。 +所有级别的日志输出方法如下,每种级别都有两种简化方式,用户可以自行选择。 ```c #define elog_assert(tag, ...) -#define elog_a(tag, ...) //简写 +#define elog_a(tag, ...) //简化方式1,每次需填写 LOG_TAG +#define log_a(...) //简化方式2,LOG_TAG 已经在文件顶部定义,使用前无需填写 LOG_TAG #define elog_error(tag, ...) #define elog_e(tag, ...) +#define log_a(...) #define elog_warn(tag, ...) #define elog_w(tag, ...) +#define log_a(...) #define elog_info(tag, ...) #define elog_i(tag, ...) +#define log_a(...) #define elog_debug(tag, ...) #define elog_d(tag, ...) +#define log_a(...) #define elog_verbose(tag, ...) #define elog_v(tag, ...) +#define log_a(...) ``` |参数 |描述| @@ -67,43 +73,55 @@ void elog_start(void) |tag |日志标签| |... |不定参格式,与`printf`入参一致,放入将要输出日志| -**建议**:对于每个文件或者每个模块,可以重新覆盖定义上述日志输出宏定义,如下所示。这样的优点就是降低代码书写量,统一日志书写格式,代码可以做到尽可能少的依赖某个日志库,同时部分复用代码无需修改日志输出方法,可直接拷贝至其他模块或者其他项目,提高软件的可重用性。 +**技巧一** :对于每个源代码文件,可以在引用 `elog.h` 上方,根据模块的不同功能,定义不同的日志标签,如下所示,这样既可直接使用 `log_x` 这类无需输入标签的简化方式 API 。 ```c -//WiFi协议处理(/wifi/proto.c) +//WiFi 协议处理(位于 /wifi/proto.c 源代码文件) #define LOG_TAG "wifi.proto" -#define log_e(...) elog_e(LOG_TAG, __VA_ARGS__) -#define log_w(...) elog_w(LOG_TAG, __VA_ARGS__) -#define log_i(...) elog_i(LOG_TAG, __VA_ARGS__) - -#if WIFI_DEBUG - #define log_d(...) elog_d(LOG_TAG, __VA_ARGS__) -#else - #define log_d(...) -#endif -//WiFi数据打包处理(/wifi/package.c) +#include + +log_e("我是 wifi.proto 日志"); +``` + +```C +//WiFi 数据打包处理(位于 /wifi/package.c 源代码文件) #define LOG_TAG "wifi.package" -#if WIFI_DEBUG - #define log_d(...) elog_d(LOG_TAG, __VA_ARGS__) -#else - #define log_d(...) -#endif +#include + +log_w("我是 wifi.package 日志"); +``` -//CAN命令解析(/can/disp.c) +```C +//CAN 命令解析(位于 /can/disp.c 源代码文件) #define LOG_TAG "can.disp" -#define log_e(...) elog_e(LOG_TAG, __VA_ARGS__) -#if CAN_DEBUG - #define log_d(...) elog_d(LOG_TAG, __VA_ARGS__) -#else - #define log_d(...) -#endif +#include + +log_w("我是 can.disp 日志"); +``` + +**技巧二** :为了实现按照模块、子模块作用域来限制日志输出级别的功能,可以按照下面的方式,在模块的头文件中定义以下宏定义: +```C +/** + * Log default configuration for EasyLogger. + * NOTE: Must defined before including the + */ +#if !defined(LOG_TAG) + #define LOG_TAG "xx" +#endif +#undef LOG_LVL +#if defined(XX_LOG_LVL) + #define LOG_LVL XX_LOG_LVL +#endif ``` -#### 1.3.2 输出RAW格式日志 +XX 是模块名称的缩写,该段内容务必定义在 `elog.h` 之前,否则失效;这样做的 **好处** 是,如果模块内的源文件没有定义 TAG ,则会自动引用该段内容中的定义的 TAG 。同时可以在 头文件中可以配置 `XX_LOG_LVL` ,这样只会输出比这个优先级高或相等级别的日志。当然 XX_LOG_LVL 这个宏也可以不定义,此时会输出全部级别的日志,定义为 ASSERT 级别,就只剩断言信息了。 +此时我们就能够实现 **源文件->子模块->模块->EasyLogger全局** 对于其中任何环节的日志配置及控制。调试时想要查看其中任何环节的日志,或者调整其中的某个环节日志级别,都会非常轻松,极大的提高了调试的灵活性及效率。 + +#### 1.3.2 输出 RAW 格式日志 ``` void elog_raw(const char *format, ...) @@ -121,6 +139,7 @@ EasyLogger自带的断言,可以直接用户软件,在断言表达式不成 ``` #define ELOG_ASSERT(EXPR) +#define assert(EXPR) //简化形式 ``` |参数 |描述| @@ -173,13 +192,15 @@ void elog_output_lock_enabled(bool enabled) ```c /* EasyLogger断言钩子方法 */ static void elog_user_assert_hook(const char* ex, const char* func, size_t line) { + /* 失能异步输出方式(异步输出模块自带方法) */ + elog_async_enabled(false); /* 失能日志输出锁 */ elog_output_lock_enabled(false); - /* 失能EasyLogger的Flash插件自带同步锁(Flash插件自带方法) */ + /* 失能 EasyLogger 的 Flash 插件自带同步锁(Flash 插件自带方法) */ elog_flash_lock_enabled(false); /* 输出断言信息 */ elog_a("elog", "(%s) has assert failed at %s:%ld.\n", ex, func, line); - /* 将缓冲区中所有日志保存至Flash(Flash插件自带方法) */ + /* 将缓冲区中所有日志保存至 Flash (Flash 插件自带方法) */ elog_flash_flush(); while(1); } @@ -363,7 +384,7 @@ size_t elog_async_get_log(char *log, size_t size) #### 1.9.3 在异步输出模式下获取行日志(以换行符结尾) -异步模式下获取行日志与 1.9.2 中的直接获取日志功能类似,只不过这里所获取到的日志内容,必须为为 **行日志** (以换行符结尾)格式,为后续的日志按行分析功能提供便利。如果设定日志长度小于日志缓冲区中已存在日志长度,将只会返回日志缓冲区中行日志的长度。如果缓冲区中不存在行日志,将不能保证返回的日志格式是行日志。 +异步模式下获取行日志与 1.9.2 中的直接获取日志功能类似,只不过这里所获取到的日志内容,必须为 **行日志** (以换行符结尾)格式,为后续的日志按行分析功能提供便利。如果设定日志长度小于日志缓冲区中已存在日志长度,将只会返回日志缓冲区中行日志的长度。如果缓冲区中不存在行日志,将不能保证返回的日志格式是行日志。 ```C size_t elog_async_get_line_log(char *log, size_t size) diff --git a/easylogger/inc/elog.h b/easylogger/inc/elog.h index fd81886..e17ed55 100644 --- a/easylogger/inc/elog.h +++ b/easylogger/inc/elog.h @@ -1,7 +1,7 @@ /* * This file is part of the EasyLogger Library. * - * Copyright (c) 2015, Armink, + * Copyright (c) 2015-2017, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -50,24 +50,75 @@ extern "C" { #define ELOG_LVL_TOTAL_NUM 6 /* EasyLogger software version number */ -#define ELOG_SW_VERSION "1.12.19" +#define ELOG_SW_VERSION "2.0.0" /* EasyLogger assert for developer. */ #ifdef ELOG_ASSERT_ENABLE -#define ELOG_ASSERT(EXPR) \ -if (!(EXPR)) \ -{ \ - if (elog_assert_hook == NULL) { \ - elog_a("elog", "(%s) has assert failed at %s:%ld.", #EXPR, __FUNCTION__, __LINE__); \ - while (1); \ - } else { \ - elog_assert_hook(#EXPR, __FUNCTION__, __LINE__); \ - } \ -} + #define ELOG_ASSERT(EXPR) \ + if (!(EXPR)) \ + { \ + if (elog_assert_hook == NULL) { \ + elog_a("elog", "(%s) has assert failed at %s:%ld.", #EXPR, __FUNCTION__, __LINE__); \ + while (1); \ + } else { \ + elog_assert_hook(#EXPR, __FUNCTION__, __LINE__); \ + } \ + } #else -#define ELOG_ASSERT(EXPR) ((void)0); + #define ELOG_ASSERT(EXPR) ((void)0); #endif +#ifndef ELOG_OUTPUT_ENABLE + #define elog_a(tag, ...) + #define elog_e(tag, ...) + #define elog_w(tag, ...) + #define elog_i(tag, ...) + #define elog_d(tag, ...) + #define elog_v(tag, ...) +#else /* ELOG_OUTPUT_ENABLE */ + #if ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT + #define elog_assert(tag, ...) \ + elog_output(ELOG_LVL_ASSERT, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) + #else + #define elog_assert(tag, ...) + #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT */ + + #if ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR + #define elog_error(tag, ...) \ + elog_output(ELOG_LVL_ERROR, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) + #else + #define elog_error(tag, ...) + #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR */ + + #if ELOG_OUTPUT_LVL >= ELOG_LVL_WARN + #define elog_warn(tag, ...) \ + elog_output(ELOG_LVL_WARN, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) + #else + #define elog_warn(tag, ...) + #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_WARN */ + + #if ELOG_OUTPUT_LVL >= ELOG_LVL_INFO + #define elog_info(tag, ...) \ + elog_output(ELOG_LVL_INFO, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) + #else + #define elog_info(tag, ...) + #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_INFO */ + + #if ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG + #define elog_debug(tag, ...) \ + elog_output(ELOG_LVL_DEBUG, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) + #else + #define elog_debug(tag, ...) + #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG */ + + #if ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE + #define elog_verbose(tag, ...) \ + elog_output(ELOG_LVL_VERBOSE, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) + #else + #define elog_verbose(tag, ...) + #endif /* ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE */ +#endif /* ELOG_OUTPUT_ENABLE */ + /* all formats index */ typedef enum { ELOG_FMT_LVL = 1 << 0, /**< level */ @@ -132,67 +183,58 @@ void elog_assert_set_hook(void (*hook)(const char* expr, const char* func, size_ int8_t elog_find_lvl(const char *log); const char *elog_find_tag(const char *log, uint8_t lvl, size_t *tag_len); -#ifndef ELOG_OUTPUT_ENABLE - -#define elog_a(tag, ...) -#define elog_e(tag, ...) -#define elog_w(tag, ...) -#define elog_i(tag, ...) -#define elog_d(tag, ...) -#define elog_v(tag, ...) +#define elog_a(tag, ...) elog_assert(tag, __VA_ARGS__) +#define elog_e(tag, ...) elog_error(tag, __VA_ARGS__) +#define elog_w(tag, ...) elog_warn(tag, __VA_ARGS__) +#define elog_i(tag, ...) elog_info(tag, __VA_ARGS__) +#define elog_d(tag, ...) elog_debug(tag, __VA_ARGS__) +#define elog_v(tag, ...) elog_verbose(tag, __VA_ARGS__) -#else /* ELOG_OUTPUT_ENABLE */ - -#if ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT -#define elog_assert(tag, ...) \ - elog_output(ELOG_LVL_ASSERT, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) +/** + * log API short definition + * NOTE: The `LOG_TAG` and `LOG_LVL` must defined before including the when you want to use log_x API. + */ +#if !defined(LOG_TAG) + #define LOG_TAG "NO_TAG" +#endif +#if !defined(LOG_LVL) + #define LOG_LVL ELOG_LVL_VERBOSE +#endif +#if LOG_LVL >= ELOG_LVL_ASSERT + #define log_a(...) elog_a(LOG_TAG, __VA_ARGS__) #else -#define elog_assert(tag, ...) + #define log_a(...) ((void)0); #endif - -#if ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR -#define elog_error(tag, ...) \ - elog_output(ELOG_LVL_ERROR, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) +#if LOG_LVL >= ELOG_LVL_ERROR + #define log_e(...) elog_e(LOG_TAG, __VA_ARGS__) #else -#define elog_error(tag, ...) + #define log_e(...) ((void)0); #endif - -#if ELOG_OUTPUT_LVL >= ELOG_LVL_WARN -#define elog_warn(tag, ...) \ - elog_output(ELOG_LVL_WARN, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) +#if LOG_LVL >= ELOG_LVL_WARN + #define log_w(...) elog_w(LOG_TAG, __VA_ARGS__) #else -#define elog_warn(tag, ...) + #define log_w(...) ((void)0); #endif - -#if ELOG_OUTPUT_LVL >= ELOG_LVL_INFO -#define elog_info(tag, ...) \ - elog_output(ELOG_LVL_INFO, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) +#if LOG_LVL >= ELOG_LVL_INFO + #define log_i(...) elog_i(LOG_TAG, __VA_ARGS__) #else -#define elog_info(tag, ...) + #define log_i(...) ((void)0); #endif - -#if ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG -#define elog_debug(tag, ...) \ - elog_output(ELOG_LVL_DEBUG, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) +#if LOG_LVL >= ELOG_LVL_DEBUG + #define log_d(...) elog_d(LOG_TAG, __VA_ARGS__) #else -#define elog_debug(tag, ...) + #define log_d(...) ((void)0); #endif - -#if ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE -#define elog_verbose(tag, ...) \ - elog_output(ELOG_LVL_VERBOSE, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) +#if LOG_LVL >= ELOG_LVL_VERBOSE + #define log_v(...) elog_v(LOG_TAG, __VA_ARGS__) #else -#define elog_verbose(tag, ...) + #define log_v(...) ((void)0); #endif -#endif /* ELOG_OUTPUT_ENABLE */ - -#define elog_a(tag, ...) elog_assert(tag, __VA_ARGS__) -#define elog_e(tag, ...) elog_error(tag, __VA_ARGS__) -#define elog_w(tag, ...) elog_warn(tag, __VA_ARGS__) -#define elog_i(tag, ...) elog_info(tag, __VA_ARGS__) -#define elog_d(tag, ...) elog_debug(tag, __VA_ARGS__) -#define elog_v(tag, ...) elog_verbose(tag, __VA_ARGS__) +/* assert API short definition */ +#if !defined(assert) + #define assert ELOG_ASSERT +#endif /* elog_buf.c */ void elog_buf_enabled(bool enabled); diff --git a/easylogger/plugins/flash/elog_flash.c b/easylogger/plugins/flash/elog_flash.c index a75bda1..9e50171 100644 --- a/easylogger/plugins/flash/elog_flash.c +++ b/easylogger/plugins/flash/elog_flash.c @@ -1,7 +1,7 @@ /* * This file is part of the EasyLogger Library. * - * Copyright (c) 2015, Armink, + * Copyright (c) 2015-2017, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -26,19 +26,14 @@ * Created on: 2015-06-05 */ +#define LOG_TAG "elog.flash" + #include "elog_flash.h" #include #include #include #include -#define log_a(...) elog_a("elog.flash", __VA_ARGS__) -#define log_e(...) elog_e("elog.flash", __VA_ARGS__) -#define log_w(...) elog_w("elog.flash", __VA_ARGS__) -#define log_i(...) elog_i("elog.flash", __VA_ARGS__) -#define log_d(...) elog_d("elog.flash", __VA_ARGS__) -#define log_v(...) elog_v("elog.flash", __VA_ARGS__) - #ifdef ELOG_FLASH_USING_BUF_MODE /* flash log buffer */ static char log_buf[ELOG_FLASH_BUF_SIZE] = { 0 }; diff --git a/easylogger/plugins/flash/elog_flash.h b/easylogger/plugins/flash/elog_flash.h index 5300b22..878fdcc 100644 --- a/easylogger/plugins/flash/elog_flash.h +++ b/easylogger/plugins/flash/elog_flash.h @@ -1,7 +1,7 @@ /* * This file is part of the EasyLogger Library. * - * Copyright (c) 2015, Armink, + * Copyright (c) 2015-2017, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -41,7 +41,7 @@ extern "C" { #endif /* EasyLogger flash log plugin's software version number */ -#define ELOG_FLASH_SW_VERSION "1.12.19" +#define ELOG_FLASH_SW_VERSION "V2.0.0" /* elog_flash.c */ ElogErrCode elog_flash_init(void); diff --git a/easylogger/src/elog.c b/easylogger/src/elog.c index 954095f..18c8fb6 100644 --- a/easylogger/src/elog.c +++ b/easylogger/src/elog.c @@ -26,6 +26,8 @@ * Created on: 2015-04-28 */ +#define LOG_TAG "elog" + #include #include #include @@ -60,50 +62,50 @@ * CSI(Control Sequence Introducer/Initiator) sign * more information on https://en.wikipedia.org/wiki/ANSI_escape_code */ -#define CSI_START "\033[" -#define CSI_END "\033[0m" +#define CSI_START "\033[" +#define CSI_END "\033[0m" /* output log front color */ -#define F_BLACK "30;" -#define F_RED "31;" -#define F_GREEN "32;" -#define F_YELLOW "33;" -#define F_BLUE "34;" -#define F_MAGENTA "35;" -#define F_CYAN "36;" -#define F_WHITE "37;" +#define F_BLACK "30;" +#define F_RED "31;" +#define F_GREEN "32;" +#define F_YELLOW "33;" +#define F_BLUE "34;" +#define F_MAGENTA "35;" +#define F_CYAN "36;" +#define F_WHITE "37;" /* output log background color */ #define B_NULL -#define B_BLACK "40;" -#define B_RED "41;" -#define B_GREEN "42;" -#define B_YELLOW "43;" -#define B_BLUE "44;" -#define B_MAGENTA "45;" -#define B_CYAN "46;" -#define B_WHITE "47;" +#define B_BLACK "40;" +#define B_RED "41;" +#define B_GREEN "42;" +#define B_YELLOW "43;" +#define B_BLUE "44;" +#define B_MAGENTA "45;" +#define B_CYAN "46;" +#define B_WHITE "47;" /* output log fonts style */ -#define S_BOLD "1m" -#define S_UNDERLINE "4m" -#define S_BLINK "5m" -#define S_NORMAL "22m" +#define S_BOLD "1m" +#define S_UNDERLINE "4m" +#define S_BLINK "5m" +#define S_NORMAL "22m" /* output log default color definition: [front color] + [background color] + [show style] */ #ifndef ELOG_COLOR_ASSERT -#define ELOG_COLOR_ASSERT (F_MAGENTA B_NULL S_NORMAL) +#define ELOG_COLOR_ASSERT (F_MAGENTA B_NULL S_NORMAL) #endif #ifndef ELOG_COLOR_ERROR -#define ELOG_COLOR_ERROR (F_RED B_NULL S_NORMAL) +#define ELOG_COLOR_ERROR (F_RED B_NULL S_NORMAL) #endif #ifndef ELOG_COLOR_WARN -#define ELOG_COLOR_WARN (F_YELLOW B_NULL S_NORMAL) +#define ELOG_COLOR_WARN (F_YELLOW B_NULL S_NORMAL) #endif #ifndef ELOG_COLOR_INFO -#define ELOG_COLOR_INFO (F_CYAN B_NULL S_NORMAL) +#define ELOG_COLOR_INFO (F_CYAN B_NULL S_NORMAL) #endif #ifndef ELOG_COLOR_DEBUG -#define ELOG_COLOR_DEBUG (F_GREEN B_NULL S_NORMAL) +#define ELOG_COLOR_DEBUG (F_GREEN B_NULL S_NORMAL) #endif #ifndef ELOG_COLOR_VERBOSE -#define ELOG_COLOR_VERBOSE (F_BLUE B_NULL S_NORMAL) +#define ELOG_COLOR_VERBOSE (F_BLUE B_NULL S_NORMAL) #endif #endif /* ELOG_COLOR_ENABLE */ @@ -111,8 +113,6 @@ static EasyLogger elog; /* every line log's buffer */ static char log_buf[ELOG_LINE_BUF_SIZE] = { 0 }; -/* log tag */ -static const char *log_tag = "elog"; /* level output info */ static const char *level_output_info[] = { [ELOG_LVL_ASSERT] = "A/", @@ -199,8 +199,7 @@ void elog_start(void) { #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 ."); + log_i("EasyLogger V%s is initialize success.", ELOG_SW_VERSION); } /** diff --git a/easylogger/src/elog_utils.c b/easylogger/src/elog_utils.c index 3817d7e..d33573f 100644 --- a/easylogger/src/elog_utils.c +++ b/easylogger/src/elog_utils.c @@ -1,7 +1,7 @@ /* * This file is part of the EasyLogger Library. * - * Copyright (c) 2015, Armink, + * Copyright (c) 2015-2017, Armink, * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -29,19 +29,6 @@ #include #include -#define LOG_TAG "elog.utils" -#define assert ELOG_ASSERT -#define log_e(...) elog_e(LOG_TAG, __VA_ARGS__) -#define log_w(...) elog_w(LOG_TAG, __VA_ARGS__) - -#ifdef ELOG_DEBUG - #define log_d(...) elog_d(LOG_TAG, __VA_ARGS__) - #define log_v(...) elog_v(LOG_TAG, __VA_ARGS__) -#else - #define log_d(...) - #define log_v(...) -#endif - /** * another copy string function *