embedded-framework/utils/Log/include/ILog.h

60 lines
2.1 KiB
C

#ifndef ILOG_H
#define ILOG_H
#ifdef __cplusplus
extern "C"
{
#endif
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
};
typedef struct LogSetting
{
const char *fileName; // File name of saving log.
const char *maxSize; // Max size of saving log.
} LogSetting;
enum LogInstance
{
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
};
#define LogVerbose(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_VERBOSE, __VA_ARGS__)
#define LogDebug(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_DEBUG, __VA_ARGS__)
#define LogInfo(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_INFORMATION, __VA_ARGS__)
#define LogWarning(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_WARNING, __VA_ARGS__)
#define LogError(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_ERROR, __VA_ARGS__)
#define LogTrace(...) GetLogIntance()->printf(GetLogIntance(), __FUNCTION__, __LINE__, LOG_TYPE_TRACE, __VA_ARGS__)
typedef struct i_log ILog;
typedef struct i_log
{
void (*init)(ILog *, const LogInstance);
void (*free)(ILog *);
int (*printf)(ILog *, const char *, const int, const int, const char *, ...);
void (*un_init)(ILog *);
} ILog;
ILog *GetLogIntance(void);
void NewILog(ILog **object);
void ResetHalImpl(ILog *impl);
static inline void ILogInit(const LogInstance log)
{
return GetLogIntance()->init(GetLogIntance(), log);
}
static inline void IHalUnInit(void)
{
return GetLogIntance()->un_init(GetLogIntance());
}
void CreateLogModule(void);
void DestroyLogModule(void);
#ifdef __cplusplus
}
#endif
#endif