1
0
mirror of https://github.com/armink/EasyLogger.git synced 2025-01-19 07:42:52 +08:00

1、【增加】两个读取Flash Log的方法。

Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
armink 2015-06-10 15:02:26 +08:00
parent 3cabe220bb
commit 9a728efc5e
3 changed files with 45 additions and 10 deletions

View File

@ -19,7 +19,7 @@ EasyLogger是一款超轻量级(ROM<1.6K, RAM<0.3k)、高性能的C日志库
1、RAW格式未经过格式化的原始日志。
2、标签在软件中可以按照文件、模块、功能等方面对需要打印的日志设定标签实现日志分类。
## 1.2 支持的插件
## 1.2 插件
- 1. Flash Log: 使用[EasyFlash](https://github.com/armink/EasyFlash)库提供的无缝接口可以把日志直接存储在Flash中。

View File

@ -34,11 +34,13 @@ extern "C" {
/* EasyLogger flash save plugin's RAM buffer size */
#define ELOG_FLASH_BUF_SIZE 1024
/* 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 */
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_recent(size_t size);
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_clean(void);

View File

@ -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 */
uint32_t buf[32] = { 0 };
size_t log_total_size = flash_log_get_used_size();
size_t buf_szie = sizeof(buf);
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 */
ELOG_ASSERT(init_ok);
/* lock flash log buffer */
elog_flash_port_lock();
/* Output all flash saved log. It will use filter */
while (true) {
if (read_size + buf_szie < log_total_size) {
flash_log_read(read_size, buf, buf_szie);
if (index + read_size + buf_szie < log_total_size) {
flash_log_read(index + read_size, buf, buf_szie);
elog_flash_port_output((const char*)buf, buf_szie);
read_size += buf_szie;
} else {
/* 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;
} 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);
elog_flash_port_output((const char*)buf, log_total_size - read_size);
flash_log_read(index + read_size - read_overage_size, buf,
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>
elog_flash_port_output("\r\n", 2);
break;
@ -103,6 +115,27 @@ void elog_flash_outout_all(void) {
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.
*