mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Remove files unused.
This commit is contained in:
parent
2d74fe6e19
commit
8c9d0d89cb
|
@ -1,40 +0,0 @@
|
|||
/**
|
||||
* @brief
|
||||
* The only one header file for the other modules to use log module.
|
||||
*/
|
||||
#ifndef FILE_IO_H
|
||||
#define FILE_IO_H
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "file.h"
|
||||
|
||||
|
||||
void _write_config_file(char *cfgname);
|
||||
|
||||
//从文件中读取配置
|
||||
void __read_config_file(char *cfgName);
|
||||
|
||||
/**
|
||||
*@brief 从给定字符串中提取key和value对。
|
||||
*处理字符串data,从中取出第一个key和value并存入key和value
|
||||
*@param data 要解析的字符串
|
||||
*@param key 保存提取到的KEY串
|
||||
*@param value 保存提取到的value串
|
||||
*@param maxlen key和value能容忍的最大字符串长度
|
||||
*@return 处理完字符串后,指针指向的位置
|
||||
*
|
||||
*/
|
||||
char *sysfunc_get_key_value(char *data, char *key, char *value, int maxlen);
|
||||
|
||||
//从acData中,查找key的值,保存在value中
|
||||
static char *__get_value(char *acData, char *key, char *value, int nMaxLen)
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,108 +0,0 @@
|
|||
#include "file_io.h"
|
||||
|
||||
void _write_config_file(char *cfgname)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void __read_config_file(char *cfgName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*@brief 从给定字符串中提取key和value对。
|
||||
*处理字符串data,从中取出第一个key和value并存入key和value
|
||||
*@param data 要解析的字符串
|
||||
*@param key 保存提取到的KEY串
|
||||
*@param value 保存提取到的value串
|
||||
*@param maxlen key和value能容忍的最大字符串长度
|
||||
*@return 处理完字符串后,指针指向的位置
|
||||
*
|
||||
*/
|
||||
char *sysfunc_get_key_value(char *data, char *key, char *value, int maxlen)
|
||||
{
|
||||
int i = 0;
|
||||
char *temp = data;
|
||||
while(*temp && *temp == ';')
|
||||
temp++;
|
||||
while(*temp && *temp != ';' && *temp != '='
|
||||
&& i < maxlen)
|
||||
{
|
||||
key[i++] = *temp++;
|
||||
}
|
||||
key[i] = '\0';
|
||||
if (*temp == ';' || *temp == '\0')
|
||||
value[0] = '\0';
|
||||
else if(*temp == '=')
|
||||
{
|
||||
i = 0;
|
||||
temp++;
|
||||
while(*temp && *temp != ';'
|
||||
&& i < maxlen)
|
||||
{
|
||||
value[i++] = *temp++;
|
||||
}
|
||||
value[i] = 0;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
//返回参数长度
|
||||
U32 ParseParam(char *pParam, int nMaxLen, char *pBuffer)
|
||||
{
|
||||
int nLen = 0;
|
||||
while(pBuffer && *pBuffer && *pBuffer != ';')
|
||||
{
|
||||
*pParam++ = *pBuffer++;
|
||||
nLen++;
|
||||
}
|
||||
return nLen;
|
||||
}
|
||||
|
||||
//从acData中,查找key的值,保存在value中
|
||||
static char *__get_value(char *acData, char *key, char *value, int nMaxLen)
|
||||
{
|
||||
char *pItem, *pValue;
|
||||
U32 nRead;
|
||||
char acBuff[256]={0};
|
||||
U32 nOffset = 0;
|
||||
int nCh = 0;
|
||||
char *out_ptr = NULL;
|
||||
while ((nRead = ParseParam(acBuff, 64, acData+nOffset)) > 0)
|
||||
{
|
||||
acBuff[nRead] = 0; //把分号去掉
|
||||
nOffset += (nRead+1);
|
||||
if (strncmp(acBuff, "[CH1]", 5) == 0)
|
||||
{
|
||||
nCh = 0;
|
||||
}
|
||||
else if (strncmp(acBuff, "[CH2]", 5) == 0)
|
||||
{
|
||||
nCh = 1;
|
||||
}
|
||||
else if (strncmp(acBuff, "[CH3]", 5) == 0)
|
||||
{
|
||||
nCh = 2;
|
||||
}
|
||||
else if (strncmp(acBuff, "[ALL]", 5) == 0)
|
||||
{
|
||||
nCh = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
pItem = strtok_r(acBuff, "=", &out_ptr);
|
||||
pValue = strtok_r(NULL, "\r", &out_ptr);
|
||||
//Printf("pItem: %s, pValue: %s\n", pItem, pValue);
|
||||
if (pValue == NULL)
|
||||
pValue = "";
|
||||
|
||||
if (pItem != NULL && strcmp(pItem, key) == 0)
|
||||
{
|
||||
strncpy(value, pValue, nMaxLen);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
include_directories(
|
||||
./src
|
||||
./include
|
||||
# /usr/include/linux
|
||||
# /usr/include/c++/9/tr1
|
||||
# /usr/include/c++/9
|
||||
${UTILS_SOURCE_PATH}/ReturnCode/include
|
||||
)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
aux_source_directory(./src IMPL_SRC_FILES)
|
||||
aux_source_directory(./abstract ABSTRACT_FILES)
|
||||
|
||||
# # set(TARGET_NAME LogC)
|
||||
# add_library(LogCAbstract STATIC ${ABSTRACT_FILES})
|
||||
# target_link_libraries(${ABSTRACT_TARGET} ReturnCode)
|
||||
# add_library(LogCUb STATIC ${SRC_FILES})
|
||||
# target_link_libraries(${ABSTRACT_TARGET} ReturnCode)
|
||||
|
||||
set(ABSTRACT_TARGET LogCAbstract)
|
||||
set(IMPL_TARGET LogCUb)
|
||||
add_library(${ABSTRACT_TARGET} STATIC ${ABSTRACT_FILES})
|
||||
target_link_libraries(${ABSTRACT_TARGET} ReturnCode)
|
||||
add_library(${IMPL_TARGET} STATIC ${IMPL_SRC_FILES})
|
||||
target_link_libraries(${IMPL_TARGET} ${ABSTRACT_TARGET} ReturnCode)
|
||||
|
||||
add_custom_target(
|
||||
log_code_check
|
||||
# COMMAND ${CMAKE_SOURCE_DIR_IPCSDK}/tools/clang-tidy/clang-tidy
|
||||
COMMAND ${CLANG_TIDY_EXE}
|
||||
-checks='${CLANG_TIDY_CHECKS}'
|
||||
${IMPL_SRC_FILES}
|
||||
${ABSTRACT_FILES}
|
||||
${CLANG_TIDY_CONFIG}
|
||||
--header-filter=.*
|
||||
--system-headers=false
|
||||
-p ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR_IPCSDK}/utils/LogC
|
||||
)
|
||||
|
||||
# add_custom_command(
|
||||
# TARGET ${IMPL_TARGET}
|
||||
# TARGET ${ABSTRACT_TARGET}
|
||||
# PRE_BUILD
|
||||
# COMMAND make log_code_check
|
||||
# WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell/
|
||||
# )
|
|
@ -1,59 +0,0 @@
|
|||
#include "iLog.h"
|
||||
#include "ReturnCode.h"
|
||||
#include <string.h>
|
||||
|
||||
static RETURN_CODE_C def_log_init(ILog *impl)
|
||||
{
|
||||
return CreateReturnCode(C_RETURN_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
|
||||
static RETURN_CODE_C def_log_unInit(ILog *impl)
|
||||
{
|
||||
return CreateReturnCode(C_RETURN_CODE_VIRTUAL_FUNCTION);
|
||||
}
|
||||
|
||||
static void def_free(ILog *impl)
|
||||
{
|
||||
}
|
||||
|
||||
static void def_log_fmt(ILog *log, const LogLeveL level, const char *fmt, ...)
|
||||
{
|
||||
}
|
||||
|
||||
static ILog default_log = {
|
||||
.init = def_log_init,
|
||||
.log_fmt = def_log_fmt,
|
||||
.free = def_free,
|
||||
.unInit = def_log_unInit,
|
||||
};
|
||||
static ILog *instance = &default_log;
|
||||
|
||||
ILog *get_log_instance(void)
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
void reset_log_impl(ILog *impl)
|
||||
{
|
||||
instance->free(impl);
|
||||
instance = impl;
|
||||
}
|
||||
|
||||
RETURN_CODE_C new_i_Log(ILog **impl)
|
||||
{
|
||||
if (!impl || !(*impl))
|
||||
{
|
||||
return CreateReturnCode(C_RETURN_CODE_NOT_OK);
|
||||
}
|
||||
memcpy(*impl, &default_log, sizeof(ILog));
|
||||
return CreateReturnCode(C_RETURN_CODE_OK);
|
||||
}
|
||||
|
||||
RETURN_CODE_C create_log_module(void)
|
||||
{
|
||||
return CreateReturnCode(C_RETURN_CODE_OK);
|
||||
}
|
||||
RETURN_CODE_C destroy_log_module(void)
|
||||
{
|
||||
return CreateReturnCode(C_RETURN_CODE_OK);
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
#ifndef ILOG_H
|
||||
#define ILOG_H
|
||||
|
||||
// #include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ReturnCode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LogVerbose(...) get_log_instance()->log_fmt(get_log_instance(), LOG_TYPE_VERBOSE, __VA_ARGS__)
|
||||
#define LogInfo(...) get_log_instance()->log_fmt(get_log_instance(), LOG_TYPE_INFORMATION, __VA_ARGS__)
|
||||
#define LogDebug(...) get_log_instance()->log_fmt(get_log_instance(), LOG_TYPE_DEBUG, __VA_ARGS__)
|
||||
#define LogError(...) get_log_instance()->log_fmt(get_log_instance(), LOG_TYPE_ERROR, __VA_ARGS__)
|
||||
#define LogWarning(...) get_log_instance()->log_fmt(get_log_instance(), LOG_TYPE_WARNING, __VA_ARGS__)
|
||||
#define LogTrace(...) get_log_instance()->log_fmt(get_log_instance(), LOG_TYPE_TRACE, __VA_ARGS__)
|
||||
|
||||
typedef enum LogLeveL {
|
||||
LOG_TYPE_VERBOSE = 0,
|
||||
LOG_TYPE_DEBUG,
|
||||
LOG_TYPE_INFORMATION,
|
||||
LOG_TYPE_WARNING,
|
||||
LOG_TYPE_ERROR,
|
||||
LOG_TYPE_TRACE,
|
||||
LOG_TYPE_TEST_TIPS,
|
||||
LOG_TYPE_END
|
||||
}LogLeveL;
|
||||
|
||||
typedef enum LogMode {
|
||||
LOG_MODE_TERMINAL = 0,
|
||||
LOG_MODE_LOGFILE,
|
||||
LOG_MODE_BOTH,
|
||||
}LogMode;
|
||||
|
||||
typedef struct iLog ILog;
|
||||
struct iLog {
|
||||
RETURN_CODE_C (*init)(ILog *);
|
||||
RETURN_CODE_C (*unInit)(ILog *);
|
||||
void (*free)(ILog *);
|
||||
void (*log_fmt)(ILog *, const LogLeveL level, const char *fmt, ...);
|
||||
};
|
||||
ILog* get_log_instance(void);
|
||||
void reset_log_impl(ILog *impl);
|
||||
RETURN_CODE_C new_i_Log(ILog **impl);
|
||||
|
||||
static RETURN_CODE_C i_log_init()
|
||||
{
|
||||
return get_log_instance()->init(get_log_instance());
|
||||
}
|
||||
|
||||
static RETURN_CODE_C i_log_unInit()
|
||||
{
|
||||
return get_log_instance()->unInit(get_log_instance());
|
||||
}
|
||||
|
||||
RETURN_CODE_C create_log_module(void);
|
||||
RETURN_CODE_C destroy_log_module(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //ILOG_H
|
|
@ -1,56 +0,0 @@
|
|||
#include "logMakePtr.h"
|
||||
#include "ReturnCode.h"
|
||||
#include "iLog.h"
|
||||
#include "logUb.h"
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
// #include <stdlib.h>
|
||||
RETURN_CODE_C create_log_module(void)
|
||||
{
|
||||
LogUbuntu *log = NULL;
|
||||
RETURN_CODE_C code = create_log_instance(&log);
|
||||
if (C_RETURN_CODE_OK == code.mCode) {
|
||||
LogInfo("Create log instance ok.\n");
|
||||
reset_log_impl((ILog *)log);
|
||||
return code;
|
||||
}
|
||||
return CreateReturnCode(C_RETURN_CODE_NOT_OK);
|
||||
}
|
||||
|
||||
RETURN_CODE_C destroy_log_module(void)
|
||||
{
|
||||
reset_log_impl(NULL);
|
||||
return CreateReturnCode(C_RETURN_CODE_OK);
|
||||
}
|
||||
|
||||
static RETURN_CODE_C create_log_instance_ptr(LogMakePtr *object, LogUbuntu **log)
|
||||
{
|
||||
return new_log(log);
|
||||
}
|
||||
|
||||
static void log_make_ptr_free(LogMakePtr *object)
|
||||
{
|
||||
}
|
||||
|
||||
static LogMakePtr default_log_make_ptr = {
|
||||
.init = NULL,
|
||||
.create_log_instance = create_log_instance_ptr,
|
||||
.free = log_make_ptr_free,
|
||||
.unInit = NULL,
|
||||
};
|
||||
static LogMakePtr *log_make_ptr_instance = &default_log_make_ptr;
|
||||
|
||||
LogMakePtr *get_log_make_ptr_instance(void)
|
||||
{
|
||||
return log_make_ptr_instance;
|
||||
}
|
||||
|
||||
void log_make_ptr_object_init(LogMakePtr *object)
|
||||
{
|
||||
memcpy(object, &default_log_make_ptr, sizeof(LogMakePtr));
|
||||
}
|
||||
void reset_log_make_ptr_impl(LogMakePtr *impl)
|
||||
{
|
||||
log_make_ptr_instance->free(log_make_ptr_instance);
|
||||
log_make_ptr_instance = impl;
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
#ifndef LOGMAKEPTR_H
|
||||
#define LOGMAKEPTR_H
|
||||
|
||||
#include "ReturnCode.h"
|
||||
#include "logUb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct log_make_ptr LogMakePtr;
|
||||
typedef struct log_make_ptr {
|
||||
RETURN_CODE_C (*init)(LogMakePtr *);
|
||||
RETURN_CODE_C (*create_log_instance)(LogMakePtr *, LogUbuntu **);
|
||||
void (*free)(LogMakePtr *);
|
||||
RETURN_CODE_C (*unInit)(LogMakePtr *);
|
||||
} LogMakePtr;
|
||||
|
||||
LogMakePtr *get_log_make_ptr_instance(void);
|
||||
void log_make_ptr_object_init(LogMakePtr *object);
|
||||
void reset_log_make_ptr_impl(LogMakePtr *impl);
|
||||
|
||||
static inline RETURN_CODE_C log_make_ptr_init(void)
|
||||
{
|
||||
return get_log_make_ptr_instance()->init(get_log_make_ptr_instance());
|
||||
}
|
||||
|
||||
static inline RETURN_CODE_C log_make_ptr_un_init(void)
|
||||
{
|
||||
return get_log_make_ptr_instance()->unInit(get_log_make_ptr_instance());
|
||||
}
|
||||
|
||||
static inline RETURN_CODE_C create_log_instance(LogUbuntu **log)
|
||||
{
|
||||
return get_log_make_ptr_instance()->create_log_instance(get_log_make_ptr_instance(), log);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //LOGMAKEPTR_H
|
|
@ -1,90 +0,0 @@
|
|||
#include "iLog.h"
|
||||
#include "ReturnCode.h"
|
||||
#include "logUb.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
static const char *LogLevelStr[] = {
|
||||
"VERBOSE",
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
"WARR",
|
||||
"ERROR",
|
||||
"TRACE",
|
||||
"TEST_TIPS",
|
||||
};
|
||||
|
||||
void ub_log_free(ILog *impl)
|
||||
{
|
||||
if (impl != NULL) {
|
||||
free(impl);
|
||||
impl = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#define LOG_BUFF_SIZE (256)
|
||||
#define LOG_TIME_BUF_SIZE (32)
|
||||
static void ub_log_fmt(ILog *log, const LogLeveL level, const char *fmt, ...)
|
||||
{
|
||||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
char ubt_time_buf[LOG_TIME_BUF_SIZE] = {0};
|
||||
struct tm *info = localtime(&rawtime);
|
||||
strftime(ubt_time_buf, LOG_TIME_BUF_SIZE, "%y-%m-%d %H:%M:%S", info);
|
||||
|
||||
va_list args;
|
||||
size_t length;
|
||||
static char ubt_log_buf[LOG_BUFF_SIZE];
|
||||
va_start(args, fmt);
|
||||
length = vsnprintf(ubt_log_buf, sizeof(ubt_log_buf) - 1, fmt, args);
|
||||
if (length > LOG_BUFF_SIZE - 1)
|
||||
length = LOG_BUFF_SIZE - 1;
|
||||
printf("[%s][%s] %s\n", ubt_time_buf, LogLevelStr[level], ubt_log_buf);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static RETURN_CODE_C ub_log_init(ILog *impl)
|
||||
{
|
||||
return CreateReturnCode(C_RETURN_CODE_OK);
|
||||
}
|
||||
|
||||
static RETURN_CODE_C ub_log_unInit(ILog *impl)
|
||||
{
|
||||
return CreateReturnCode(C_RETURN_CODE_OK);
|
||||
}
|
||||
|
||||
void init_Log_Ubuntu(LogUbuntu *lu)
|
||||
{
|
||||
((ILog*)lu)->log_fmt = ub_log_fmt;
|
||||
((ILog*)lu)->init = ub_log_init;
|
||||
((ILog*)lu)->free = ub_log_free;
|
||||
((ILog*)lu)->unInit = ub_log_unInit;
|
||||
}
|
||||
|
||||
RETURN_CODE_C new_log(LogUbuntu **log_ub)
|
||||
{
|
||||
if (!log_ub) {
|
||||
printf("C_RETURN_CODE_INVALID_PARAMENTER\n");
|
||||
return CreateReturnCode(C_RETURN_CODE_INVALID_PARAMENTER);
|
||||
}
|
||||
// log_ub为NULL
|
||||
if (!(*log_ub)) {
|
||||
*log_ub = (LogUbuntu *)malloc(sizeof(LogUbuntu));
|
||||
// malloc success
|
||||
if (*log_ub) {
|
||||
printf("new_log succeed.\n");
|
||||
new_i_Log((ILog **)log_ub);
|
||||
init_Log_Ubuntu(*log_ub);
|
||||
return CreateReturnCode(C_RETURN_CODE_OK);
|
||||
}
|
||||
// malloc failed
|
||||
// init_Log_Ubuntu(*log_ub);
|
||||
printf("new_log failed.\n");
|
||||
return CreateReturnCode(C_RETURN_CODE_NOT_OK);
|
||||
}
|
||||
// log_ub 不为NULL
|
||||
init_Log_Ubuntu(*log_ub);
|
||||
return CreateReturnCode(C_RETURN_CODE_OK);
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
#ifndef _IPC_LOG_UBUNTU_H_
|
||||
#define _IPC_LOG_UBUNTU_H_
|
||||
|
||||
#include "iLog.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct LogUbuntu LogUbuntu;
|
||||
struct LogUbuntu {
|
||||
ILog base;
|
||||
};
|
||||
|
||||
RETURN_CODE_C new_log(LogUbuntu **log_ub);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_IPC_LOG_UBUNTU_H_
|
|
@ -1,24 +0,0 @@
|
|||
|
||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
|
||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
|
||||
|
||||
include_directories(
|
||||
./src
|
||||
./include
|
||||
${UTILS_SOURCE_PATH}/Log/src/easyloggingpp
|
||||
)
|
||||
#do not rely on any other library
|
||||
#link_directories(
|
||||
#)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
aux_source_directory(./src/easyloggingpp SRC_FILES)
|
||||
|
||||
set(TARGET_NAME Log)
|
||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
|
||||
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
/**
|
||||
* @brief
|
||||
* The only one header file for the other modules to use log module.
|
||||
*/
|
||||
#ifndef LOG_H
|
||||
#define LOG_H
|
||||
#define LogVerbose(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_VERBOSE, __VA_ARGS__)
|
||||
#define LogDebug(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_DEBUG, __VA_ARGS__)
|
||||
#define LogInfo(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_INFORMATION, __VA_ARGS__)
|
||||
#define LogWarning(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_WARNING, __VA_ARGS__)
|
||||
#define LogError(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_ERROR, __VA_ARGS__)
|
||||
#define LogTrace(...) Log(__FUNCTION__, __LINE__, LOG_TYPE_TRACE, __VA_ARGS__)
|
||||
// For test code, never using in release version.
|
||||
// #define LogTestTips(...) TestTips(LOG_TYPE_TEST_TIPS, __VA_ARGS__)
|
||||
|
||||
// TODO:
|
||||
#if 1 // For wifi log, should delete finally.
|
||||
#define LOGD(...)
|
||||
|
||||
#define LOGI(...)
|
||||
|
||||
#define LOGW(...)
|
||||
|
||||
#define LOGE(...)
|
||||
|
||||
#define LOGF(...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* log type.
|
||||
*/
|
||||
enum LogType
|
||||
{
|
||||
LOG_TYPE_VERBOSE = 0,
|
||||
LOG_TYPE_DEBUG,
|
||||
LOG_TYPE_INFORMATION,
|
||||
LOG_TYPE_WARNING,
|
||||
LOG_TYPE_ERROR,
|
||||
LOG_TYPE_TRACE,
|
||||
LOG_TYPE_TEST_TIPS,
|
||||
LOG_TYPE_END
|
||||
};
|
||||
/**
|
||||
* @brief
|
||||
* instance type of log module.
|
||||
*/
|
||||
enum LogInstanceType
|
||||
{
|
||||
LOG_SERIAL_PRINT = 0, // for serial print.
|
||||
LOG_EASYLOGGING, // for easylogging++.
|
||||
LOG_CAPTURE_LOG, // capture log to other who need it
|
||||
LOG_INSTANCE_TYPE_END
|
||||
|
||||
};
|
||||
/**
|
||||
* @brief
|
||||
* Log setting
|
||||
*/
|
||||
typedef struct LogSetting
|
||||
{
|
||||
const char *fileName; // File name of saving log.
|
||||
const char *maxSize; // Max size of saving log.
|
||||
const int (*callback)(const char *); //
|
||||
|
||||
const int (*callback_InFo)(const char *);
|
||||
const int (*callback_Warning)(const char *);
|
||||
const int (*callback_Error)(const char *);
|
||||
const int (*callback_Debug)(const char *);
|
||||
const int (*callback_Trace)(const char *);
|
||||
} LogSetting;
|
||||
/*
|
||||
** Make sure we can call this stuff from C++.
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/**
|
||||
* @brief
|
||||
* Init what type of log to run, see LogInstanceType in this file.
|
||||
* @param logInstanceType
|
||||
* @param setting Setting of log module, See LogSetting.
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
int InitLog(const int logInstanceType, const LogSetting *setting);
|
||||
int UnInitLog();
|
||||
/**
|
||||
* @brief
|
||||
* Print log
|
||||
* TODO: Crash will happen if print a string without '\0'.
|
||||
* @param function
|
||||
* @param line
|
||||
* @param type
|
||||
* @param format
|
||||
* @param ...
|
||||
* @return int
|
||||
*/
|
||||
int Log(const char *function, int line, int type, const char *format, ...);
|
||||
/**
|
||||
* @brief
|
||||
* Only for test code.
|
||||
* @param format
|
||||
* @param ...
|
||||
* @return const char*
|
||||
*/
|
||||
// const char *TestTips(int type, const char *format, ...);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,32 +0,0 @@
|
|||
#include "ILog.h"
|
||||
#include <thread>
|
||||
std::shared_ptr<ILog> &ILog::GetInstance(std::shared_ptr<ILog> *impl)
|
||||
{
|
||||
static std::shared_ptr<ILog> instance = std::make_shared<ILog>();
|
||||
static bool instanceChanging = false;
|
||||
if (impl && false == instanceChanging)
|
||||
{
|
||||
// Don't use std::mutex for runing faster.
|
||||
// Sleep for difference thread to release instance.
|
||||
instanceChanging = true;
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
if (instance.use_count() == 1) // bug?
|
||||
{
|
||||
instance->Log("Instance change succeed.\n");
|
||||
instance->UnInit();
|
||||
(*impl)->Init();
|
||||
instance = *impl;
|
||||
}
|
||||
else
|
||||
{
|
||||
instance->Log("[ error ] instance change failed, using by some one.\n");
|
||||
}
|
||||
instanceChanging = false;
|
||||
}
|
||||
if (instanceChanging)
|
||||
{
|
||||
static std::shared_ptr<ILog> tmporaryInstance = std::make_shared<ILog>();
|
||||
return tmporaryInstance;
|
||||
}
|
||||
return instance;
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
#ifndef I_LOG_H
|
||||
#define I_LOG_H
|
||||
// #include "VReturnCode.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
class ILog
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Get the Instance object
|
||||
* Return reference for runing faster. Usage : ILog::GetInstance()->Init();
|
||||
* Don't use ILog like this:
|
||||
* std::shared_ptr<ILog> &log = ILog::GetInstance(); or std::shared_ptr<ILog> log = ILog::GetInstance();
|
||||
* log->Log("Your log.");
|
||||
* @param impl Change the instance.
|
||||
* @return std::shared_ptr<ILog>&
|
||||
*/
|
||||
static std::shared_ptr<ILog> &GetInstance(std::shared_ptr<ILog> *impl = nullptr);
|
||||
ILog() = default;
|
||||
virtual ~ILog() = default;
|
||||
virtual bool Init() { return false; }
|
||||
virtual bool UnInit() { return false; }
|
||||
/**
|
||||
* @brief
|
||||
* If the Log module is working.
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
virtual bool IsWorking() { return false; }
|
||||
/**
|
||||
* @brief
|
||||
* Virtual log function.
|
||||
* @param buff
|
||||
* @return int
|
||||
*/
|
||||
virtual int Log(const char *buff) { return 0; }
|
||||
|
||||
virtual int InFo(const char *buff) { return 0; }
|
||||
|
||||
virtual int Warning(const char *buff) { return 0; }
|
||||
|
||||
virtual int Error(const char *buff) { return 0; }
|
||||
|
||||
virtual int Trace(const char *buff) { return 0; }
|
||||
|
||||
virtual int Debug(const char *buff) { return 0; }
|
||||
};
|
||||
#endif
|
|
@ -1,19 +0,0 @@
|
|||
#include "ILogMakePtr.h"
|
||||
#include "LogImpl.h"
|
||||
#include "LogEasylogging.h"
|
||||
#include "LogCapture.h"
|
||||
std::shared_ptr<ILog> ILogMakePtr::MakeLogImplPtr()
|
||||
{
|
||||
std::shared_ptr<ILog> logImpl = std::make_shared<LogImpl>();
|
||||
return logImpl;
|
||||
}
|
||||
std::shared_ptr<ILog> ILogMakePtr::MakeLogEasylogging(const LogSetting *setting)
|
||||
{
|
||||
std::shared_ptr<ILog> logImpl = std::make_shared<LogEasylogging>(setting);
|
||||
return logImpl;
|
||||
}
|
||||
std::shared_ptr<ILog> ILogMakePtr::MakeLongCapture(const LogSetting *setting)
|
||||
{
|
||||
std::shared_ptr<ILog> logImpl = std::make_shared<LogCapture>(*setting);
|
||||
return logImpl;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef ILOG_MAKE_PTR_H
|
||||
#define ILOG_MAKE_PTR_H
|
||||
#include "ILog.h"
|
||||
#include "Log.h"
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
class ILogMakePtr
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<ILogMakePtr> &GetInstance(std::shared_ptr<ILogMakePtr> *impl = nullptr)
|
||||
{
|
||||
static std::shared_ptr<ILogMakePtr> instance = std::make_shared<ILogMakePtr>();
|
||||
if (impl)
|
||||
{
|
||||
instance = *impl;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
ILogMakePtr() = default;
|
||||
virtual ~ILogMakePtr() = default;
|
||||
virtual std::shared_ptr<ILog> MakeLogImplPtr();
|
||||
virtual std::shared_ptr<ILog> MakeLogEasylogging(const LogSetting *setting);
|
||||
virtual std::shared_ptr<ILog> MakeLongCapture(const LogSetting *setting);
|
||||
};
|
||||
#endif
|
|
@ -1,109 +0,0 @@
|
|||
#include "Log.h"
|
||||
#include "ILog.h"
|
||||
#include "LogImpl.h"
|
||||
#include "ILogMakePtr.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string.h>
|
||||
|
||||
int InitLog(const int logInstanceType, const LogSetting *setting)
|
||||
{
|
||||
switch (logInstanceType)
|
||||
{
|
||||
case LOG_SERIAL_PRINT:
|
||||
{
|
||||
std::shared_ptr<ILog> logImpl = ILogMakePtr::GetInstance()->MakeLogImplPtr();
|
||||
ILog::GetInstance(&logImpl);
|
||||
break;
|
||||
}
|
||||
case LOG_EASYLOGGING:
|
||||
{
|
||||
std::shared_ptr<ILog> logImpl = ILogMakePtr::GetInstance()->MakeLogEasylogging(setting);
|
||||
ILog::GetInstance(&logImpl);
|
||||
break;
|
||||
}
|
||||
case LOG_CAPTURE_LOG:
|
||||
{
|
||||
std::shared_ptr<ILog> logImpl = ILogMakePtr::GetInstance()->MakeLongCapture(setting);
|
||||
ILog::GetInstance(&logImpl);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
LogError("Log module init error.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int UnInitLog()
|
||||
{
|
||||
std::shared_ptr<ILog> logImpl = std::make_shared<ILog>();
|
||||
ILog::GetInstance(&logImpl);
|
||||
return 0;
|
||||
}
|
||||
// static void LogTypeToString(const int type)
|
||||
// {
|
||||
// switch (type)
|
||||
// {
|
||||
// case LOG_TYPE_ERROR:
|
||||
// {
|
||||
// ILog::GetInstance()->Log("[ ERROR ]");
|
||||
// break;
|
||||
// }
|
||||
// case LOG_TYPE_TEST_TIPS:
|
||||
// {
|
||||
// ILog::GetInstance()->Log("[ FAILURE ]");
|
||||
// break;
|
||||
// }
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
int Log(const char *function, int line, int type, const char *format, ...)
|
||||
{
|
||||
if (!ILog::GetInstance()->IsWorking())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// TODO:
|
||||
// LogTypeToString(type);
|
||||
constexpr int SEND_TRACE_BUFF_SIZE = 2048;
|
||||
char buff[SEND_TRACE_BUFF_SIZE] = {0};
|
||||
snprintf(buff, SEND_TRACE_BUFF_SIZE, "[%s][line:%d]:", function, line);
|
||||
// ILog::GetInstance()->Log(buff);
|
||||
const int headLen = strlen(buff);
|
||||
va_list vargs;
|
||||
va_start(vargs, format);
|
||||
int len = vsnprintf(buff + headLen, SEND_TRACE_BUFF_SIZE - headLen, format, vargs);
|
||||
va_end(vargs);
|
||||
switch (type)
|
||||
{
|
||||
case LOG_TYPE_INFORMATION:
|
||||
ILog::GetInstance()->InFo(buff);
|
||||
break;
|
||||
|
||||
case LOG_TYPE_WARNING:
|
||||
ILog::GetInstance()->Warning(buff);
|
||||
break;
|
||||
|
||||
case LOG_TYPE_ERROR:
|
||||
ILog::GetInstance()->Error(buff);
|
||||
break;
|
||||
|
||||
case LOG_TYPE_DEBUG:
|
||||
ILog::GetInstance()->Debug(buff);
|
||||
break;
|
||||
|
||||
case LOG_TYPE_TRACE:
|
||||
ILog::GetInstance()->Trace(buff);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return len;
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
#include "LogCapture.h"
|
||||
#include <thread>
|
||||
#include <stdio.h>
|
||||
|
||||
LogCapture::LogCapture(const LogSetting setting) : mLogCapture(setting.callback),
|
||||
mLogCapture_InFo(setting.callback_InFo), mLogCapture_Warning(setting.callback_Warning),
|
||||
mLogCapture_Error(setting.callback_Error), mLogCapture_Debug(setting.callback_Debug),
|
||||
mLogCapture_Trace(setting.callback_Trace)
|
||||
{
|
||||
if (!setting.callback)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool LogCapture::Init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool LogCapture::UnInit()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LogCapture::IsWorking()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int LogCapture::Log(const char *buff)
|
||||
{
|
||||
if (mLogCapture)
|
||||
{
|
||||
mLogCapture(buff);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LogCapture::InFo(const char *buff)
|
||||
{
|
||||
if (mLogCapture_InFo)
|
||||
{
|
||||
mLogCapture_InFo(buff);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LogCapture::Warning(const char *buff)
|
||||
{
|
||||
if (mLogCapture_Warning)
|
||||
{
|
||||
mLogCapture_Warning(buff);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LogCapture::Error(const char *buff)
|
||||
{
|
||||
if (mLogCapture_Error)
|
||||
{
|
||||
mLogCapture_Error(buff);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LogCapture::Debug(const char *buff)
|
||||
{
|
||||
if (mLogCapture_Debug)
|
||||
{
|
||||
mLogCapture_Debug(buff);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LogCapture::Trace(const char *buff)
|
||||
{
|
||||
if (mLogCapture_Trace)
|
||||
{
|
||||
mLogCapture_Trace(buff);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
#ifndef LOG_CAPTURE_H
|
||||
#define LOG_CAPTURE_H
|
||||
#include "ILog.h"
|
||||
#include "Log.h"
|
||||
|
||||
class LogCapture : public ILog
|
||||
{
|
||||
public:
|
||||
LogCapture(const LogSetting settings); // settings may it should add (*)?
|
||||
virtual ~LogCapture() = default;
|
||||
bool Init() override;
|
||||
bool UnInit() override;
|
||||
bool IsWorking() override;
|
||||
int Log(const char *buff) override;
|
||||
int InFo(const char *buff) override;
|
||||
int Warning(const char *buff) override;
|
||||
int Error(const char *buff) override;
|
||||
int Trace(const char *buff) override;
|
||||
int Debug(const char *buff) override;
|
||||
|
||||
private:
|
||||
std::string mFileName; // File name of saving log.
|
||||
std::string mMaxSize; // Max size of saving log.
|
||||
const int (*mLogCapture)(const char *buff); // For other modules to capture what to print.
|
||||
const int (*mLogCapture_InFo)(const char *buff);
|
||||
const int (*mLogCapture_Warning)(const char *buff);
|
||||
const int (*mLogCapture_Error)(const char *buff);
|
||||
const int (*mLogCapture_Debug)(const char *buff);
|
||||
const int (*mLogCapture_Trace)(const char *buff);
|
||||
};
|
||||
#endif
|
|
@ -1,89 +0,0 @@
|
|||
#include "LogEasylogging.h"
|
||||
#include "easylogging++.h"
|
||||
#include <thread>
|
||||
// #define ELPP_UNICODE // Define for easylogging
|
||||
INITIALIZE_EASYLOGGINGPP // Init easylogging
|
||||
// static bool initFlag = false; // Only used for init easyloggingpp
|
||||
bool test = false;
|
||||
LogEasylogging::LogEasylogging(const LogSetting *setting)
|
||||
{
|
||||
if (!setting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (setting->fileName)
|
||||
{
|
||||
mFileName = setting->fileName;
|
||||
}
|
||||
if (setting->maxSize)
|
||||
{
|
||||
mMaxSize = setting->maxSize;
|
||||
}
|
||||
}
|
||||
bool LogEasylogging::Init()
|
||||
{
|
||||
#if 0
|
||||
el::Configurations conf("/home/xiaojiazhu/project/OS/OSThings/test/output_files/bin/default-logger.conf");
|
||||
el::Loggers::reconfigureAllLoggers(conf);
|
||||
#endif
|
||||
// Set the log path.
|
||||
if (mFileName.size() > 0)
|
||||
{
|
||||
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Filename, mFileName.c_str());
|
||||
}
|
||||
|
||||
// Set the max size of log file.
|
||||
// el::Loggers::reconfigureAllLoggers(el::ConfigurationType::MaxLogFileSize, "1048576");
|
||||
if (mMaxSize.size() > 0)
|
||||
{
|
||||
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::MaxLogFileSize, mMaxSize.c_str());
|
||||
}
|
||||
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "true");
|
||||
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::ToFile, "true");
|
||||
return true;
|
||||
}
|
||||
bool LogEasylogging::UnInit()
|
||||
{
|
||||
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::ToFile, "false");
|
||||
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "false");
|
||||
return true;
|
||||
}
|
||||
bool LogEasylogging::IsWorking()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int LogEasylogging::Log(const char *buff)
|
||||
{
|
||||
// LOG(INFO) << buff;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LogEasylogging::InFo(const char *buff)
|
||||
{
|
||||
LOG(INFO) << buff;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LogEasylogging::Warning(const char *buff)
|
||||
{
|
||||
LOG(WARNING) << buff;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LogEasylogging::Error(const char *buff)
|
||||
{
|
||||
LOG(ERROR) << buff;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LogEasylogging::Debug(const char *buff)
|
||||
{
|
||||
LOG(DEBUG) << buff;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LogEasylogging::Trace(const char *buff)
|
||||
{
|
||||
LOG(TRACE) << buff;
|
||||
return 0;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
#ifndef LOG_EASYLOGGING_H
|
||||
#define LOG_EASYLOGGING_H
|
||||
#include "ILog.h"
|
||||
#include "Log.h"
|
||||
class LogEasylogging : public ILog
|
||||
{
|
||||
public:
|
||||
LogEasylogging(const LogSetting *setting);
|
||||
virtual ~LogEasylogging() = default;
|
||||
bool Init() override;
|
||||
bool UnInit() override;
|
||||
bool IsWorking() override;
|
||||
int Log(const char *buff) override;
|
||||
int InFo(const char *buff) override;
|
||||
int Warning(const char *buff) override;
|
||||
int Error(const char *buff) override;
|
||||
int Trace(const char *buff) override;
|
||||
int Debug(const char *buff) override;
|
||||
|
||||
private:
|
||||
std::string mFileName; // File name of saving log.
|
||||
std::string mMaxSize; // Max size of saving log.
|
||||
};
|
||||
#endif
|
|
@ -1,9 +0,0 @@
|
|||
#include "LogImpl.h"
|
||||
bool LogImpl::IsWorking()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int LogImpl::Log(const char *buff)
|
||||
{
|
||||
return printf("%s", buff);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
#ifndef LOG_IMPL_H
|
||||
#define LOG_IMPL_H
|
||||
#include "ILog.h"
|
||||
class LogImpl : public ILog
|
||||
{
|
||||
public:
|
||||
LogImpl() = default;
|
||||
virtual ~LogImpl() = default;
|
||||
bool IsWorking() override;
|
||||
int Log(const char *buff) override;
|
||||
};
|
||||
#endif
|
|
@ -1,9 +0,0 @@
|
|||
这是一个开源库的源码。
|
||||
注意:
|
||||
//1. 需要定义宏
|
||||
//#define ELPP_UNICODE // Define for easylogging
|
||||
2. 初始化
|
||||
INITIALIZE_EASYLOGGINGPP // Init easylogging
|
||||
//3. 支持多线程,在源码头文件"easyloggingpp.h"定义宏
|
||||
//#define ELPP_THREAD_SAFE // Working in threads. Added by xiaojiazhu
|
||||
4. ELPP_NO_DEFAULT_LOG_FILE 此宏屏蔽生成默认的log文件
|
|
@ -1,25 +0,0 @@
|
|||
* GLOBAL:
|
||||
FORMAT = "%datetime | %level | %logger | %msg"
|
||||
FILENAME = "/tmp/logs/myeasylog-configuration.cpp.log"
|
||||
ENABLED = true
|
||||
TO_FILE = true
|
||||
TO_STANDARD_OUTPUT = true
|
||||
SUBSECOND_PRECISION = 3
|
||||
PERFORMANCE_TRACKING = false
|
||||
MAX_LOG_FILE_SIZE = 2097152 ## Throw log files away after 2MB
|
||||
* DEBUG:
|
||||
FILENAME = "/tmp/logs/myeasylog-configuration.cpp-debug.log"
|
||||
TO_STANDARD_OUTPUT = true
|
||||
ENABLED = true ## We will set it to false after development completed
|
||||
* WARNING:
|
||||
FILENAME = "/tmp/logs/filename-with-time-%datetime{%H:%m}"
|
||||
* TRACE:
|
||||
TO_FILE = true ## Unnecessary configuration cuz its already true in GLOBAL but doing it anyway!
|
||||
* VERBOSE:
|
||||
FORMAT = "%datetime{%d/%M/%y} | %level-%vlevel | %msg"
|
||||
## Error logs
|
||||
* ERROR:
|
||||
ENABLED = false
|
||||
FILENAME = "/tmp/logs/myeasylog-configuration.cpp-error.log"
|
||||
* FATAL:
|
||||
ENABLED = false
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user