Files

62 lines
2.0 KiB
C
Raw Permalink Normal View History

#ifndef _ZXCVBSAMPLE_LOG_H_
#define _ZXCVBSAMPLE_LOG_H_
2024-04-10 12:21:46 +08:00
#include <stdio.h>
2024-06-18 12:17:32 +08:00
typedef enum {
SAMPLE_LOG_MIN_ = -1,
SAMPLE_LOG_EMERGENCY_ = 0,
SAMPLE_LOG_ALERT_ = 1,
SAMPLE_LOG_CRITICAL_ = 2,
SAMPLE_LOG_ERROR_ = 3,
SAMPLE_LOG_WARN_ = 4,
SAMPLE_LOG_NOTICE_ = 5,
SAMPLE_LOG_INFO_ = 6,
SAMPLE_LOG_DEBUG_ = 7,
SAMPLE_LOG_MAX_
} SAMPLE_LOG_LEVEL_E_;
2024-04-10 12:21:46 +08:00
#if defined(CONFIG_SAMPLE_LOG_LEVEL_)
static SAMPLE_LOG_LEVEL_E_ log_level_ = CONFIG_SAMPLE_LOG_LEVEL_;
#elif defined(CONFIG_SAMPLE_LOG_LEVEL_EXPORT_)
extern SAMPLE_LOG_LEVEL_E_ log_level_;
2024-06-18 12:17:32 +08:00
#else
static SAMPLE_LOG_LEVEL_E_ log_level_ = SAMPLE_LOG_INFO_;
2024-06-18 12:17:32 +08:00
#endif
2024-04-10 12:21:46 +08:00
#if 1
2024-06-18 12:17:32 +08:00
#define MACRO_BLACK "\033[1;30;30m"
#define MACRO_RED "\033[1;30;31m"
#define MACRO_GREEN "\033[1;30;32m"
2024-04-10 12:21:46 +08:00
#define MACRO_YELLOW "\033[1;30;33m"
2024-06-18 12:17:32 +08:00
#define MACRO_BLUE "\033[1;30;34m"
2024-04-10 12:21:46 +08:00
#define MACRO_PURPLE "\033[1;30;35m"
2024-06-18 12:17:32 +08:00
#define MACRO_WHITE "\033[1;30;37m"
#define MACRO_END "\033[0m"
2024-04-10 12:21:46 +08:00
#else
#define MACRO_BLACK
#define MACRO_RED
#define MACRO_GREEN
#define MACRO_YELLOW
#define MACRO_BLUE
#define MACRO_PURPLE
#define MACRO_WHITE
#define MACRO_END
#endif
#define SLOGE(fmt, ...) printf(MACRO_RED "[E][%32s][%4d]: " fmt MACRO_END "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define SLOGW(fmt, ...) \
if (log_level_ >= SAMPLE_LOG_WARN_) \
2024-04-10 12:21:46 +08:00
printf(MACRO_YELLOW "[W][%s][%4d]: " fmt MACRO_END "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define SLOGI(fmt, ...) \
if (log_level_ >= SAMPLE_LOG_INFO_) \
2024-04-10 12:21:46 +08:00
printf(MACRO_GREEN "[I][%s][%4d]: " fmt MACRO_END "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define SLOGD(fmt, ...) \
if (log_level_ >= SAMPLE_LOG_DEBUG_) \
2024-04-10 12:21:46 +08:00
printf(MACRO_WHITE "[D][%s][%4d]: " fmt MACRO_END "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define SLOGN(fmt, ...) \
if (log_level_ >= SAMPLE_LOG_NOTICE_) \
2024-04-10 12:21:46 +08:00
printf(MACRO_PURPLE "[N][%s][%4d]: " fmt MACRO_END "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
#endif /* _SAMPLE_LOG_H_ */