mirror of
https://github.com/armink/EasyLogger.git
synced 2025-02-07 16:44:09 +08:00
commit
8585ed801d
@ -43,8 +43,6 @@ extern osSemaphoreId_t elog_dma_lockHandle;
|
|||||||
ElogErrCode elog_port_init(void) {
|
ElogErrCode elog_port_init(void) {
|
||||||
ElogErrCode result = ELOG_NO_ERR;
|
ElogErrCode result = ELOG_NO_ERR;
|
||||||
|
|
||||||
osSemaphoreRelease(elog_dma_lockHandle);
|
|
||||||
osSemaphoreRelease(elog_lockHandle);
|
|
||||||
/* add your code here */
|
/* add your code here */
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -65,6 +63,7 @@ void elog_port_deinit(void) {
|
|||||||
*/
|
*/
|
||||||
void elog_port_output(const char *log, size_t size) {
|
void elog_port_output(const char *log, size_t size) {
|
||||||
HAL_UART_Transmit_DMA(&huart2, (uint8_t *) log, size);
|
HAL_UART_Transmit_DMA(&huart2, (uint8_t *) log, size);
|
||||||
|
osSemaphoreAcquire(elog_dma_lockHandle, osWaitForever);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,30 +115,28 @@ void elog_async_output_notice(void) {
|
|||||||
|
|
||||||
void elog_entry(void *para) {
|
void elog_entry(void *para) {
|
||||||
size_t get_log_size = 0;
|
size_t get_log_size = 0;
|
||||||
|
#ifdef ELOG_ASYNC_LINE_OUTPUT
|
||||||
static char poll_get_buf[ELOG_LINE_BUF_SIZE - 4];
|
static char poll_get_buf[ELOG_LINE_BUF_SIZE - 4];
|
||||||
|
#else
|
||||||
|
static char poll_get_buf[ELOG_ASYNC_OUTPUT_BUF_SIZE - 4];
|
||||||
|
#endif
|
||||||
|
|
||||||
if (elog_port_init() != ELOG_NO_ERR) {
|
for(;;)
|
||||||
goto fail;
|
{
|
||||||
}
|
/* waiting log */
|
||||||
|
osSemaphoreAcquire(elog_asyncHandle, osWaitForever);
|
||||||
while (1) {
|
/* polling gets and outputs the log */
|
||||||
if (osOK ==
|
while (1) {
|
||||||
osSemaphoreAcquire(elog_asyncHandle, osWaitForever)) {
|
#ifdef ELOG_ASYNC_LINE_OUTPUT
|
||||||
while (1) {
|
get_log_size = elog_async_get_line_log(poll_get_buf, sizeof(poll_get_buf));
|
||||||
if (osOK ==
|
#else
|
||||||
osSemaphoreAcquire(elog_dma_lockHandle, osWaitForever)) {
|
get_log_size = elog_async_get_log(poll_get_buf, sizeof(poll_get_buf));
|
||||||
get_log_size = elog_async_get_line_log(poll_get_buf, sizeof(poll_get_buf));
|
#endif
|
||||||
if (get_log_size) {
|
if (get_log_size) {
|
||||||
elog_port_output(poll_get_buf, get_log_size);
|
elog_port_output(poll_get_buf, get_log_size);
|
||||||
} else {
|
} else {
|
||||||
osSemaphoreRelease(elog_dma_lockHandle);
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fail:
|
|
||||||
osThreadExit();
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ ElogErrCode elog_flash_port_init(void)
|
|||||||
|
|
||||||
### 3.2 Flash中的日志被读取后的输出接口
|
### 3.2 Flash中的日志被读取后的输出接口
|
||||||
|
|
||||||
将日志从Flash中读取后,调用`elog_flash_outout()`、`elog_flash_outout_all()`及`elog_flash_outout_recent()`进行输出展示时,将会调用此移植接口。可以在里面增加输出到终端、网络等功能。
|
将日志从Flash中读取后,调用`elog_flash_output()`、`elog_flash_output_all()`及`elog_flash_output_recent()`进行输出展示时,将会调用此移植接口。可以在里面增加输出到终端、网络等功能。
|
||||||
|
|
||||||
```C
|
```C
|
||||||
void elog_flash_port_output(const char *log, size_t size)
|
void elog_flash_port_output(const char *log, size_t size)
|
||||||
@ -75,7 +75,7 @@ void elog_flash_port_unlock(void)
|
|||||||
配置时需要修改项目中的`elog_flash_cfg.h`文件,开启、关闭、修改对应的宏即可。
|
配置时需要修改项目中的`elog_flash_cfg.h`文件,开启、关闭、修改对应的宏即可。
|
||||||
|
|
||||||
### 4.1 缓冲模式
|
### 4.1 缓冲模式
|
||||||
|
|
||||||
开启后,需要写入Flash的日志会先存储至RAM缓冲区,当缓冲区满时,缓冲区中的所有日志将自动写入Flash。如果关闭,所有日志在输出时会立刻写入Flash。
|
开启后,需要写入Flash的日志会先存储至RAM缓冲区,当缓冲区满时,缓冲区中的所有日志将自动写入Flash。如果关闭,所有日志在输出时会立刻写入Flash。
|
||||||
|
|
||||||
- 默认状态:开启
|
- 默认状态:开启
|
||||||
|
@ -73,6 +73,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ELOG_OUTPUT_ENABLE
|
#ifndef ELOG_OUTPUT_ENABLE
|
||||||
|
#define elog_raw(...)
|
||||||
#define elog_assert(tag, ...)
|
#define elog_assert(tag, ...)
|
||||||
#define elog_error(tag, ...)
|
#define elog_error(tag, ...)
|
||||||
#define elog_warn(tag, ...)
|
#define elog_warn(tag, ...)
|
||||||
@ -80,6 +81,7 @@ extern "C" {
|
|||||||
#define elog_debug(tag, ...)
|
#define elog_debug(tag, ...)
|
||||||
#define elog_verbose(tag, ...)
|
#define elog_verbose(tag, ...)
|
||||||
#else /* ELOG_OUTPUT_ENABLE */
|
#else /* ELOG_OUTPUT_ENABLE */
|
||||||
|
#define elog_raw(...) elog_raw_output(__VA_ARGS__)
|
||||||
#if ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT
|
#if ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT
|
||||||
#define elog_assert(tag, ...) \
|
#define elog_assert(tag, ...) \
|
||||||
elog_output(ELOG_LVL_ASSERT, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
elog_output(ELOG_LVL_ASSERT, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
|
||||||
@ -191,7 +193,7 @@ void elog_set_filter_tag(const char *tag);
|
|||||||
void elog_set_filter_kw(const char *keyword);
|
void elog_set_filter_kw(const char *keyword);
|
||||||
void elog_set_filter_tag_lvl(const char *tag, uint8_t level);
|
void elog_set_filter_tag_lvl(const char *tag, uint8_t level);
|
||||||
uint8_t elog_get_filter_tag_lvl(const char *tag);
|
uint8_t elog_get_filter_tag_lvl(const char *tag);
|
||||||
void elog_raw(const char *format, ...);
|
void elog_raw_output(const char *format, ...);
|
||||||
void elog_output(uint8_t level, const char *tag, const char *file, const char *func,
|
void elog_output(uint8_t level, const char *tag, const char *file, const char *func,
|
||||||
const long line, const char *format, ...);
|
const long line, const char *format, ...);
|
||||||
void elog_output_lock_enabled(bool enabled);
|
void elog_output_lock_enabled(bool enabled);
|
||||||
|
@ -503,7 +503,7 @@ uint8_t elog_get_filter_tag_lvl(const char *tag)
|
|||||||
* @param format output format
|
* @param format output format
|
||||||
* @param ... args
|
* @param ... args
|
||||||
*/
|
*/
|
||||||
void elog_raw(const char *format, ...) {
|
void elog_raw_output(const char *format, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
size_t log_len = 0;
|
size_t log_len = 0;
|
||||||
int fmt_result;
|
int fmt_result;
|
||||||
@ -915,7 +915,7 @@ void elog_hexdump(const char *name, uint8_t width, const void *buf, uint16_t siz
|
|||||||
elog_async_output(ELOG_LVL_DEBUG, log_buf, log_len);
|
elog_async_output(ELOG_LVL_DEBUG, log_buf, log_len);
|
||||||
#elif defined(ELOG_BUF_OUTPUT_ENABLE)
|
#elif defined(ELOG_BUF_OUTPUT_ENABLE)
|
||||||
extern void elog_buf_output(const char *log, size_t size);
|
extern void elog_buf_output(const char *log, size_t size);
|
||||||
elog_buf_output(log_buf, log_len);
|
elog_buf_output(log_buf, log_len);
|
||||||
#else
|
#else
|
||||||
elog_port_output(log_buf, log_len);
|
elog_port_output(log_buf, log_len);
|
||||||
#endif
|
#endif
|
||||||
|
@ -80,8 +80,10 @@ static pthread_t async_output_thread;
|
|||||||
|
|
||||||
/* Initialize OK flag */
|
/* Initialize OK flag */
|
||||||
static bool init_ok = false;
|
static bool init_ok = false;
|
||||||
|
#ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD
|
||||||
/* thread running flag */
|
/* thread running flag */
|
||||||
static bool thread_running = false;
|
static bool thread_running = false;
|
||||||
|
#endif
|
||||||
/* asynchronous output mode enabled flag */
|
/* asynchronous output mode enabled flag */
|
||||||
static bool is_enabled = false;
|
static bool is_enabled = false;
|
||||||
/* asynchronous output mode's ring buffer */
|
/* asynchronous output mode's ring buffer */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user