mirror of
https://github.com/armink/EasyLogger.git
synced 2025-02-08 00:54:09 +08:00
1、【增加】两个读取Flash Log的方法。
Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
parent
3cabe220bb
commit
9a728efc5e
@ -19,7 +19,7 @@ EasyLogger是一款超轻量级(ROM<1.6K, RAM<0.3k)、高性能的C日志库,
|
|||||||
1、RAW格式:未经过格式化的原始日志。
|
1、RAW格式:未经过格式化的原始日志。
|
||||||
2、标签:在软件中可以按照文件、模块、功能等方面,对需要打印的日志设定标签,实现日志分类。
|
2、标签:在软件中可以按照文件、模块、功能等方面,对需要打印的日志设定标签,实现日志分类。
|
||||||
|
|
||||||
## 1.2 支持的插件
|
## 1.2 插件
|
||||||
|
|
||||||
- 1. Flash Log: 使用[EasyFlash](https://github.com/armink/EasyFlash)库提供的无缝接口,可以把日志直接存储在Flash中。
|
- 1. Flash Log: 使用[EasyFlash](https://github.com/armink/EasyFlash)库提供的无缝接口,可以把日志直接存储在Flash中。
|
||||||
|
|
||||||
|
@ -34,11 +34,13 @@ extern "C" {
|
|||||||
/* EasyLogger flash save plugin's RAM buffer size */
|
/* EasyLogger flash save plugin's RAM buffer size */
|
||||||
#define ELOG_FLASH_BUF_SIZE 1024
|
#define ELOG_FLASH_BUF_SIZE 1024
|
||||||
/* EasyLogger flash save plugin's software version number */
|
/* EasyLogger flash save plugin's software version number */
|
||||||
#define ELOG_FLASH_SW_VERSION "0.06.09"
|
#define ELOG_FLASH_SW_VERSION "0.06.10"
|
||||||
|
|
||||||
/* elog_flash.c */
|
/* elog_flash.c */
|
||||||
ElogErrCode elog_flash_init(void);
|
ElogErrCode elog_flash_init(void);
|
||||||
|
void elog_flash_outout(size_t pos, size_t size);
|
||||||
void elog_flash_outout_all(void);
|
void elog_flash_outout_all(void);
|
||||||
|
void elog_flash_outout_recent(size_t size);
|
||||||
void elog_flash_set_filter(uint8_t level,const char *tag,const char *keyword);
|
void elog_flash_set_filter(uint8_t level,const char *tag,const char *keyword);
|
||||||
void elog_flash_write(const char *log, size_t size);
|
void elog_flash_write(const char *log, size_t size);
|
||||||
void elog_flash_clean(void);
|
void elog_flash_clean(void);
|
||||||
|
@ -66,34 +66,46 @@ ElogErrCode elog_flash_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read and output all log which saved in flash. @note It will use filter. @see elog_flash_set_filter
|
* Read and output log which saved in flash.
|
||||||
|
*
|
||||||
|
* @param index index for saved log.
|
||||||
|
* Minimum index is 0.
|
||||||
|
* Maximum index is log used flash total size - 1.
|
||||||
|
* @param size
|
||||||
*/
|
*/
|
||||||
void elog_flash_outout_all(void) {
|
void elog_flash_outout(size_t index, size_t size) {
|
||||||
/* 128 bytes buffer */
|
/* 128 bytes buffer */
|
||||||
uint32_t buf[32] = { 0 };
|
uint32_t buf[32] = { 0 };
|
||||||
size_t log_total_size = flash_log_get_used_size();
|
size_t log_total_size = flash_log_get_used_size();
|
||||||
size_t buf_szie = sizeof(buf);
|
size_t buf_szie = sizeof(buf);
|
||||||
size_t read_size = 0, read_overage_size = 0;
|
size_t read_size = 0, read_overage_size = 0;
|
||||||
|
|
||||||
|
if (index + size > log_total_size) {
|
||||||
|
log_i("The output position and size is out of bound. The max size is %d.", log_total_size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* must be call this function after initialize OK */
|
/* must be call this function after initialize OK */
|
||||||
ELOG_ASSERT(init_ok);
|
ELOG_ASSERT(init_ok);
|
||||||
/* lock flash log buffer */
|
/* lock flash log buffer */
|
||||||
elog_flash_port_lock();
|
elog_flash_port_lock();
|
||||||
/* Output all flash saved log. It will use filter */
|
/* Output all flash saved log. It will use filter */
|
||||||
while (true) {
|
while (true) {
|
||||||
if (read_size + buf_szie < log_total_size) {
|
if (index + read_size + buf_szie < log_total_size) {
|
||||||
flash_log_read(read_size, buf, buf_szie);
|
flash_log_read(index + read_size, buf, buf_szie);
|
||||||
elog_flash_port_output((const char*)buf, buf_szie);
|
elog_flash_port_output((const char*)buf, buf_szie);
|
||||||
read_size += buf_szie;
|
read_size += buf_szie;
|
||||||
} else {
|
} else {
|
||||||
/* flash read is word alignment */
|
/* flash read is word alignment */
|
||||||
if ((log_total_size - read_size) % 4 == 0) {
|
if ((log_total_size - index - read_size) % 4 == 0) {
|
||||||
read_overage_size = 0;
|
read_overage_size = 0;
|
||||||
} else {
|
} else {
|
||||||
read_overage_size = 4 - ((log_total_size - read_size) % 4);
|
read_overage_size = 4 - ((log_total_size - index - read_size) % 4);
|
||||||
}
|
}
|
||||||
flash_log_read(read_size, buf, log_total_size - read_size + read_overage_size);
|
flash_log_read(index + read_size - read_overage_size, buf,
|
||||||
elog_flash_port_output((const char*)buf, log_total_size - read_size);
|
log_total_size - index - read_size + read_overage_size);
|
||||||
|
elog_flash_port_output((const char*) buf + read_overage_size,
|
||||||
|
log_total_size - index - read_size);
|
||||||
//TODO CRLF <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫͳһ<CDB3><D2BB>ͷ<EFBFBD>ļ<EFBFBD><C4BC>궨<EFBFBD><EAB6A8>
|
//TODO CRLF <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫͳһ<CDB3><D2BB>ͷ<EFBFBD>ļ<EFBFBD><C4BC>궨<EFBFBD><EAB6A8>
|
||||||
elog_flash_port_output("\r\n", 2);
|
elog_flash_port_output("\r\n", 2);
|
||||||
break;
|
break;
|
||||||
@ -103,6 +115,27 @@ void elog_flash_outout_all(void) {
|
|||||||
elog_flash_port_unlock();
|
elog_flash_port_unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read and output all log which saved in flash.
|
||||||
|
*/
|
||||||
|
void elog_flash_outout_all(void) {
|
||||||
|
elog_flash_outout(0, flash_log_get_used_size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read and output recent log which saved in flash.
|
||||||
|
*
|
||||||
|
* @param size recent log size
|
||||||
|
*/
|
||||||
|
void elog_flash_outout_recent(size_t size) {
|
||||||
|
size_t max_size = flash_log_get_used_size();
|
||||||
|
if (size > max_size) {
|
||||||
|
log_i("The output size is out of bound. The max size is %d.", max_size);
|
||||||
|
} else {
|
||||||
|
elog_flash_outout(max_size - size, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write log to flash. The flash write use buffer mode.
|
* Write log to flash. The flash write use buffer mode.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user