新建项目
This commit is contained in:
1 parent
5e2e890cfc
commit
633d9b872b
1351 files changed
+730564
No files matched your search
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* This file is part of the EasyLogger Library.
|
||||
*
|
||||
* Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* 'Software'), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Function: Save log to file.
|
||||
* Created on: 2019-01-05
|
||||
*/
|
||||
|
||||
#define LOG_TAG "elog.file"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "elog_file.h"
|
||||
|
||||
/* initialize OK flag */
|
||||
static bool init_ok = false;
|
||||
static FILE *fp = NULL;
|
||||
static ElogFileCfg local_cfg;
|
||||
|
||||
ElogErrCode elog_file_init(void)
|
||||
{
|
||||
ElogErrCode result = ELOG_NO_ERR;
|
||||
ElogFileCfg cfg;
|
||||
|
||||
if (init_ok)
|
||||
goto __exit;
|
||||
|
||||
elog_file_port_init();
|
||||
|
||||
cfg.name = ELOG_FILE_NAME;
|
||||
cfg.max_size = ELOG_FILE_MAX_SIZE;
|
||||
cfg.max_rotate = ELOG_FILE_MAX_ROTATE;
|
||||
|
||||
elog_file_config(&cfg);
|
||||
|
||||
init_ok = true;
|
||||
__exit:
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* rotate the log file xxx.log.n-1 => xxx.log.n, and xxx.log => xxx.log.0
|
||||
*/
|
||||
static bool elog_file_rotate(void)
|
||||
{
|
||||
#define SUFFIX_LEN 10
|
||||
/* mv xxx.log.n-1 => xxx.log.n, and xxx.log => xxx.log.0 */
|
||||
int n, err = 0;
|
||||
char oldpath[256], newpath[256];
|
||||
size_t base = strlen(local_cfg.name);
|
||||
bool result = true;
|
||||
FILE *tmp_fp;
|
||||
|
||||
memcpy(oldpath, local_cfg.name, base);
|
||||
memcpy(newpath, local_cfg.name, base);
|
||||
|
||||
fclose(fp);
|
||||
|
||||
for (n = local_cfg.max_rotate - 1; n >= 0; --n) {
|
||||
snprintf(oldpath + base, SUFFIX_LEN, n ? ".%d" : "", n - 1);
|
||||
snprintf(newpath + base, SUFFIX_LEN, ".%d", n);
|
||||
/* remove the old file */
|
||||
if ((tmp_fp = fopen(newpath , "r")) != NULL) {
|
||||
fclose(tmp_fp);
|
||||
remove(newpath);
|
||||
}
|
||||
/* change the new log file to old file name */
|
||||
if ((tmp_fp = fopen(oldpath , "r")) != NULL) {
|
||||
fclose(tmp_fp);
|
||||
err = rename(oldpath, newpath);
|
||||
}
|
||||
|
||||
if (err < 0) {
|
||||
result = false;
|
||||
goto __exit;
|
||||
}
|
||||
}
|
||||
|
||||
__exit:
|
||||
/* reopen the file */
|
||||
fp = fopen(local_cfg.name, "a+");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void elog_file_write(const char *log, size_t size)
|
||||
{
|
||||
size_t file_size = 0;
|
||||
|
||||
ELOG_ASSERT(init_ok);
|
||||
ELOG_ASSERT(log);
|
||||
|
||||
elog_file_port_lock();
|
||||
|
||||
fseek(fp, 0L, SEEK_END);
|
||||
file_size = ftell(fp);
|
||||
|
||||
if (unlikely(file_size > local_cfg.max_size)) {
|
||||
#if ELOG_FILE_MAX_ROTATE > 0
|
||||
if (!elog_file_rotate()) {
|
||||
goto __exit;
|
||||
}
|
||||
#else
|
||||
goto __exit;
|
||||
#endif
|
||||
}
|
||||
|
||||
fwrite(log, size, 1, fp);
|
||||
|
||||
#ifdef ELOG_FILE_FLUSH_CACHE_ENABLE
|
||||
fflush(fp);
|
||||
#endif
|
||||
|
||||
__exit:
|
||||
elog_file_port_unlock();
|
||||
}
|
||||
|
||||
void elog_file_deinit(void)
|
||||
{
|
||||
ELOG_ASSERT(init_ok);
|
||||
|
||||
ElogFileCfg cfg = {NULL, 0, 0};
|
||||
|
||||
elog_file_config(&cfg);
|
||||
|
||||
elog_file_port_deinit();
|
||||
|
||||
init_ok = false;
|
||||
}
|
||||
|
||||
void elog_file_config(ElogFileCfg *cfg)
|
||||
{
|
||||
elog_file_port_lock();
|
||||
|
||||
if (fp) {
|
||||
fclose(fp);
|
||||
fp = NULL;
|
||||
}
|
||||
|
||||
if (cfg != NULL) {
|
||||
local_cfg.name = cfg->name;
|
||||
local_cfg.max_size = cfg->max_size;
|
||||
local_cfg.max_rotate = cfg->max_rotate;
|
||||
|
||||
if (local_cfg.name != NULL && strlen(local_cfg.name) > 0)
|
||||
fp = fopen(local_cfg.name, "a+");
|
||||
}
|
||||
|
||||
elog_file_port_unlock();
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of the EasyLogger Library.
|
||||
*
|
||||
* Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* 'Software'), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Function: It is an head file for file log plugin. You can see all be called functions.
|
||||
* Created on: 2019-01-05
|
||||
*/
|
||||
|
||||
#ifndef __ELOG_FILE__H__
|
||||
#define __ELOG_FILE__H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <elog.h>
|
||||
#include <elog_file_cfg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* EasyLogger file log plugin's software version number */
|
||||
#define ELOG_FILE_SW_VERSION "V1.0.0"
|
||||
#ifdef linux
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
#else
|
||||
#define likely(x) (x)
|
||||
#define unlikely(x) (x)
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char *name; /* file name */
|
||||
size_t max_size; /* file max size */
|
||||
int max_rotate; /* max rotate file count */
|
||||
} ElogFileCfg;
|
||||
|
||||
/* elog_file.c */
|
||||
ElogErrCode elog_file_init(void);
|
||||
void elog_file_write(const char *log, size_t size);
|
||||
void elog_file_config(ElogFileCfg *cfg);
|
||||
void elog_file_deinit(void);
|
||||
|
||||
/* elog_file_port.c */
|
||||
ElogErrCode elog_file_port_init(void);
|
||||
void elog_file_port_lock(void);
|
||||
void elog_file_port_unlock(void);
|
||||
void elog_file_port_deinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of the EasyLogger Library.
|
||||
*
|
||||
* Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* 'Software'), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Function: It is the configure head file for this flash log plugin.
|
||||
* Created on: 2019-01-05
|
||||
*/
|
||||
|
||||
#ifndef _ELOG_FILE_CFG_H_
|
||||
#define _ELOG_FILE_CFG_H_
|
||||
|
||||
/* EasyLogger file log plugin's using file name */
|
||||
#define ELOG_FILE_NAME /* @note you must define it for a value */
|
||||
|
||||
/* EasyLogger file log plugin's using file max size */
|
||||
#define ELOG_FILE_MAX_SIZE /* @note you must define it for a value */
|
||||
|
||||
/* EasyLogger file log plugin's using max rotate file count */
|
||||
#define ELOG_FILE_MAX_ROTATE /* @note you must define it for a value */
|
||||
|
||||
#endif /* _ELOG_FILE_CFG_H_ */
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of the EasyLogger Library.
|
||||
*
|
||||
* Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* 'Software'), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Function: Portable interface for EasyLogger's file log pulgin.
|
||||
* Created on: 2019-01-05
|
||||
*/
|
||||
|
||||
#include "elog_file.h"
|
||||
|
||||
/**
|
||||
* EasyLogger flile log pulgin port initialize
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
ElogErrCode elog_file_port_init(void)
|
||||
{
|
||||
ElogErrCode result = ELOG_NO_ERR;
|
||||
|
||||
/* add your code here */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* file log lock
|
||||
*/
|
||||
void elog_file_port_lock(void) {
|
||||
|
||||
/* add your code here */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* file log unlock
|
||||
*/
|
||||
void elog_file_port_unlock(void) {
|
||||
|
||||
/* add your code here */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* file log deinit
|
||||
*/
|
||||
void elog_file_port_deinit(void) {
|
||||
|
||||
/* add your code here */
|
||||
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
/*
|
||||
* This file is part of the EasyLogger Library.
|
||||
*
|
||||
* Copyright (c) 2015-2017, Armink, <armink.ztl@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* 'Software'), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Function: Save log to flash. Must use EasyFlash(https://github.com/armink/EasyFlash) library.
|
||||
* Created on: 2015-06-05
|
||||
*/
|
||||
|
||||
#define LOG_TAG "elog.flash"
|
||||
|
||||
#include "elog_flash.h"
|
||||
#include <easyflash.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef ELOG_FLASH_USING_BUF_MODE
|
||||
/* flash log buffer */
|
||||
static char log_buf[ELOG_FLASH_BUF_SIZE] = { 0 };
|
||||
/* current flash log buffer write position */
|
||||
static size_t cur_buf_size = 0;
|
||||
#endif
|
||||
|
||||
/* initialize OK flag */
|
||||
static bool init_ok = false;
|
||||
/* the flash log buffer lock enable or disable. default is enable */
|
||||
static bool log_buf_lock_enabled = true;
|
||||
/* the flash log buffer is locked before enable. */
|
||||
static bool log_buf_is_locked_before_enable = false;
|
||||
/* the flash log buffer is locked before disable. */
|
||||
static bool log_buf_is_locked_before_disable = false;
|
||||
static void log_buf_lock(void);
|
||||
static void log_buf_unlock(void);
|
||||
|
||||
/**
|
||||
* EasyLogger flash log plugin initialize.
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
ElogErrCode elog_flash_init(void) {
|
||||
ElogErrCode result = ELOG_NO_ERR;
|
||||
|
||||
/* buffer size must be word alignment */
|
||||
ELOG_ASSERT(ELOG_FLASH_BUF_SIZE % 4 == 0);
|
||||
|
||||
#ifdef ELOG_FLASH_USING_BUF_MODE
|
||||
/* initialize current flash log buffer write position */
|
||||
cur_buf_size = 0;
|
||||
#endif
|
||||
|
||||
/* port initialize */
|
||||
elog_flash_port_init();
|
||||
/* initialize OK */
|
||||
init_ok = true;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and output log which saved in flash.
|
||||
*
|
||||
* @param index index for saved log. @note It will auto word alignment.
|
||||
* Minimum index is 0.
|
||||
* Maximum index is log used flash total size - 1.
|
||||
* @param size
|
||||
*/
|
||||
void elog_flash_output(size_t index, size_t size) {
|
||||
/* 128 bytes buffer */
|
||||
uint32_t buf[32] = { 0 };
|
||||
size_t log_total_size = ef_log_get_used_size();
|
||||
size_t buf_size = sizeof(buf);
|
||||
size_t read_size = 0, read_overage_size = 0;
|
||||
|
||||
/* word alignment for index */
|
||||
index = index / 4 * 4;
|
||||
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 */
|
||||
log_buf_lock();
|
||||
/* output all flash saved log. It will use filter */
|
||||
while (true) {
|
||||
if (read_size + buf_size < size) {
|
||||
ef_log_read(index + read_size, buf, buf_size);
|
||||
elog_flash_port_output((const char*)buf, buf_size);
|
||||
read_size += buf_size;
|
||||
} else {
|
||||
/* flash read is word alignment */
|
||||
if ((size - read_size) % 4 == 0) {
|
||||
read_overage_size = 0;
|
||||
} else {
|
||||
read_overage_size = 4 - ((size - read_size) % 4);
|
||||
}
|
||||
ef_log_read(index + read_size, buf, size - read_size + read_overage_size);
|
||||
elog_flash_port_output((const char*) buf + read_overage_size, size - read_size);
|
||||
/* output newline sign */
|
||||
elog_flash_port_output(ELOG_NEWLINE_SIGN, strlen(ELOG_NEWLINE_SIGN));
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* unlock flash log buffer */
|
||||
log_buf_unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and output all log which saved in flash.
|
||||
*/
|
||||
void elog_flash_output_all(void) {
|
||||
elog_flash_output(0, ef_log_get_used_size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and output recent log which saved in flash.
|
||||
*
|
||||
* @param size recent log size
|
||||
*/
|
||||
void elog_flash_output_recent(size_t size) {
|
||||
size_t max_size = ef_log_get_used_size();
|
||||
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (size > max_size) {
|
||||
log_i("The output size is out of bound. The max size is %d.", max_size);
|
||||
} else {
|
||||
elog_flash_output(max_size - size, size);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write log to flash. The flash write use buffer mode.
|
||||
*
|
||||
* @param log log
|
||||
* @param size log size
|
||||
*/
|
||||
void elog_flash_write(const char *log, size_t size) {
|
||||
|
||||
#ifdef ELOG_FLASH_USING_BUF_MODE
|
||||
size_t write_size = 0, write_index = 0;
|
||||
#else
|
||||
size_t write_size_temp = 0;
|
||||
EfErrCode result = EF_NO_ERR;
|
||||
/* write some '\r' for word alignment */
|
||||
char write_overage_c[4] = { '\r', '\r', '\r', '\r' };
|
||||
#endif
|
||||
|
||||
/* must be call this function after initialize OK */
|
||||
ELOG_ASSERT(init_ok);
|
||||
|
||||
/* lock flash log buffer */
|
||||
log_buf_lock();
|
||||
|
||||
#ifdef ELOG_FLASH_USING_BUF_MODE
|
||||
while (true) {
|
||||
if (cur_buf_size + size > ELOG_FLASH_BUF_SIZE) {
|
||||
write_size = ELOG_FLASH_BUF_SIZE - cur_buf_size;
|
||||
elog_memcpy(log_buf + cur_buf_size, log + write_index, write_size);
|
||||
write_index += write_size;
|
||||
size -= write_size;
|
||||
cur_buf_size += write_size;
|
||||
/* unlock flash log buffer */
|
||||
log_buf_unlock();
|
||||
/* write all buffered log to flash, cur_buf_size will reset */
|
||||
elog_flash_flush();
|
||||
/* lock flash log buffer */
|
||||
log_buf_lock();
|
||||
} else {
|
||||
elog_memcpy(log_buf + cur_buf_size, log + write_index, size);
|
||||
cur_buf_size += size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* calculate the word alignment write size */
|
||||
write_size_temp = size / 4 * 4;
|
||||
/* write log to flash */
|
||||
result = ef_log_write((uint32_t *) log, write_size_temp);
|
||||
/* write last word alignment data */
|
||||
if ((result == EF_NO_ERR) && (write_size_temp != size)) {
|
||||
elog_memcpy(write_overage_c, log + write_size_temp, size - write_size_temp);
|
||||
ef_log_write((uint32_t *) write_overage_c, 4);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* unlock flash log buffer */
|
||||
log_buf_unlock();
|
||||
}
|
||||
|
||||
#ifdef ELOG_FLASH_USING_BUF_MODE
|
||||
/**
|
||||
* write all buffered log to flash
|
||||
*/
|
||||
void elog_flash_flush(void) {
|
||||
size_t write_overage_size = 0;
|
||||
|
||||
/* must be call this function after initialize OK */
|
||||
ELOG_ASSERT(init_ok);
|
||||
/* lock flash log buffer */
|
||||
log_buf_lock();
|
||||
/* flash write is word alignment */
|
||||
if (cur_buf_size % 4 != 0) {
|
||||
write_overage_size = 4 - (cur_buf_size % 4);
|
||||
}
|
||||
/* fill '\r' for word alignment */
|
||||
memset(log_buf + cur_buf_size, '\r', write_overage_size);
|
||||
/* write all buffered log to flash */
|
||||
ef_log_write((uint32_t *) log_buf, cur_buf_size + write_overage_size);
|
||||
/* reset position */
|
||||
cur_buf_size = 0;
|
||||
/* unlock flash log buffer */
|
||||
log_buf_unlock();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* clean all log which in flash and ram buffer
|
||||
*/
|
||||
void elog_flash_clean(void) {
|
||||
EfErrCode clean_result = EF_NO_ERR;
|
||||
|
||||
/* must be call this function after initialize OK */
|
||||
ELOG_ASSERT(init_ok);
|
||||
/* lock flash log buffer */
|
||||
log_buf_lock();
|
||||
/* clean all log which in flash */
|
||||
clean_result = ef_log_clean();
|
||||
|
||||
#ifdef ELOG_FLASH_USING_BUF_MODE
|
||||
/* reset position */
|
||||
cur_buf_size = 0;
|
||||
#endif
|
||||
|
||||
/* unlock flash log buffer */
|
||||
log_buf_unlock();
|
||||
|
||||
if(clean_result == EF_NO_ERR) {
|
||||
log_i("All logs which in flash is clean OK.");
|
||||
} else {
|
||||
log_e("Clean logs which in flash has an error!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* enable or disable flash plugin lock
|
||||
* @note disable this lock is not recommended except you want output system exception log
|
||||
*
|
||||
* @param enabled true: enable false: disable
|
||||
*/
|
||||
void elog_flash_lock_enabled(bool enabled) {
|
||||
log_buf_lock_enabled = enabled;
|
||||
/* it will re-lock or re-unlock before log buffer lock enable */
|
||||
if (log_buf_lock_enabled) {
|
||||
if (!log_buf_is_locked_before_disable && log_buf_is_locked_before_enable) {
|
||||
/* the log buffer lock is unlocked before disable, and the lock will unlocking after enable */
|
||||
elog_flash_port_lock();
|
||||
} else if (log_buf_is_locked_before_disable && !log_buf_is_locked_before_enable) {
|
||||
/* the log buffer lock is locked before disable, and the lock will locking after enable */
|
||||
elog_flash_port_unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* lock flash log buffer
|
||||
*/
|
||||
static void log_buf_lock(void) {
|
||||
if (log_buf_lock_enabled) {
|
||||
elog_flash_port_lock();
|
||||
log_buf_is_locked_before_disable = true;
|
||||
} else {
|
||||
log_buf_is_locked_before_enable = true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* unlock flash log buffer
|
||||
*/
|
||||
static void log_buf_unlock(void) {
|
||||
if (log_buf_lock_enabled) {
|
||||
elog_flash_port_unlock();
|
||||
log_buf_is_locked_before_disable = false;
|
||||
} else {
|
||||
log_buf_is_locked_before_enable = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of the EasyLogger Library.
|
||||
*
|
||||
* Copyright (c) 2015-2017, Armink, <armink.ztl@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* 'Software'), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Function: It is an head file for flash log plugin. You can see all be called functions.
|
||||
* Created on: 2015-06-05
|
||||
*/
|
||||
|
||||
#ifndef __ELOG_FLASH_H__
|
||||
#define __ELOG_FLASH_H__
|
||||
|
||||
#include <elog.h>
|
||||
#include <elog_flash_cfg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if !defined(ELOG_FLASH_BUF_SIZE)
|
||||
#error "Please configure RAM buffer size (in elog_flash_cfg.h)"
|
||||
#endif
|
||||
|
||||
/* EasyLogger flash log plugin's software version number */
|
||||
#define ELOG_FLASH_SW_VERSION "V2.0.1"
|
||||
|
||||
/* elog_flash.c */
|
||||
ElogErrCode elog_flash_init(void);
|
||||
void elog_flash_output(size_t pos, size_t size);
|
||||
void elog_flash_output_all(void);
|
||||
void elog_flash_output_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);
|
||||
void elog_flash_lock_enabled(bool enabled);
|
||||
|
||||
#ifdef ELOG_FLASH_USING_BUF_MODE
|
||||
void elog_flash_flush(void);
|
||||
#endif
|
||||
|
||||
/* elog_flash_port.c */
|
||||
ElogErrCode elog_flash_port_init(void);
|
||||
void elog_flash_port_output(const char *log, size_t size);
|
||||
void elog_flash_port_lock(void);
|
||||
void elog_flash_port_unlock(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ELOG_FLASH_H__ */
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of the EasyLogger Library.
|
||||
*
|
||||
* Copyright (c) 2015, Armink, <armink.ztl@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* 'Software'), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Function: It is the configure head file for this flash log plugin.
|
||||
* Created on: 2015-07-30
|
||||
*/
|
||||
|
||||
#ifndef _ELOG_FLASH_CFG_H_
|
||||
#define _ELOG_FLASH_CFG_H_
|
||||
|
||||
/* EasyLogger flash log plugin's using buffer mode */
|
||||
#define ELOG_FLASH_USING_BUF_MODE
|
||||
/* EasyLogger flash log plugin's RAM buffer size */
|
||||
#define ELOG_FLASH_BUF_SIZE /* @note you must define it for a value */
|
||||
|
||||
#endif /* _ELOG_FLASH_CFG_H_ */
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of the EasyLogger Library.
|
||||
*
|
||||
* Copyright (c) 2015, Armink, <armink.ztl@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* 'Software'), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Function: Portable interface for EasyLogger's flash log pulgin.
|
||||
* Created on: 2015-07-28
|
||||
*/
|
||||
|
||||
#include "elog_flash.h"
|
||||
|
||||
/**
|
||||
* EasyLogger flash log pulgin port initialize
|
||||
*
|
||||
* @return result
|
||||
*/
|
||||
ElogErrCode elog_flash_port_init(void) {
|
||||
ElogErrCode result = ELOG_NO_ERR;
|
||||
|
||||
/* add your code here */
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* output flash saved log port interface
|
||||
*
|
||||
* @param log flash saved log
|
||||
* @param size log size
|
||||
*/
|
||||
void elog_flash_port_output(const char *log, size_t size) {
|
||||
|
||||
/* add your code here */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* flash log lock
|
||||
*/
|
||||
void elog_flash_port_lock(void) {
|
||||
|
||||
/* add your code here */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* flash log unlock
|
||||
*/
|
||||
void elog_flash_port_unlock(void) {
|
||||
|
||||
/* add your code here */
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user