112 lines
2.7 KiB
C
112 lines
2.7 KiB
C
/**
|
|
* @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 |