2021-01-18 20:35:11 +08:00
|
|
|
#pragma once
|
2020-01-18 03:01:02 +08:00
|
|
|
|
2022-05-19 05:11:57 +08:00
|
|
|
#include "common/timing.h"
|
2020-01-18 03:01:02 +08:00
|
|
|
|
|
|
|
#define CLOUDLOG_DEBUG 10
|
|
|
|
#define CLOUDLOG_INFO 20
|
|
|
|
#define CLOUDLOG_WARNING 30
|
|
|
|
#define CLOUDLOG_ERROR 40
|
|
|
|
#define CLOUDLOG_CRITICAL 50
|
|
|
|
|
2022-01-28 00:14:38 +08:00
|
|
|
|
2023-08-01 08:49:50 +08:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define SWAG_LOG_CHECK_FMT(a, b) __attribute__ ((format (printf, a, b)))
|
|
|
|
#else
|
|
|
|
#define SWAG_LOG_CHECK_FMT(a, b)
|
|
|
|
#endif
|
|
|
|
|
2020-01-18 03:01:02 +08:00
|
|
|
void cloudlog_e(int levelnum, const char* filename, int lineno, const char* func,
|
2023-08-01 08:49:50 +08:00
|
|
|
const char* fmt, ...) SWAG_LOG_CHECK_FMT(5, 6);
|
2020-01-18 03:01:02 +08:00
|
|
|
|
2022-04-20 05:29:24 +08:00
|
|
|
void cloudlog_te(int levelnum, const char* filename, int lineno, const char* func,
|
2023-08-01 08:49:50 +08:00
|
|
|
const char* fmt, ...) SWAG_LOG_CHECK_FMT(5, 6);
|
2022-04-20 05:29:24 +08:00
|
|
|
|
|
|
|
void cloudlog_te(int levelnum, const char* filename, int lineno, const char* func,
|
2023-08-01 08:49:50 +08:00
|
|
|
uint32_t frame_id, const char* fmt, ...) SWAG_LOG_CHECK_FMT(6, 7);
|
2022-04-20 05:29:24 +08:00
|
|
|
|
2022-04-06 12:05:45 +08:00
|
|
|
|
2020-01-18 03:01:02 +08:00
|
|
|
#define cloudlog(lvl, fmt, ...) cloudlog_e(lvl, __FILE__, __LINE__, \
|
|
|
|
__func__, \
|
2023-07-20 10:46:42 +08:00
|
|
|
fmt, ## __VA_ARGS__)
|
|
|
|
|
2022-04-20 05:29:24 +08:00
|
|
|
#define cloudlog_t(lvl, ...) cloudlog_te(lvl, __FILE__, __LINE__, \
|
|
|
|
__func__, \
|
2023-07-20 10:46:42 +08:00
|
|
|
__VA_ARGS__)
|
2022-04-20 05:29:24 +08:00
|
|
|
|
2020-01-18 03:01:02 +08:00
|
|
|
|
|
|
|
#define cloudlog_rl(burst, millis, lvl, fmt, ...) \
|
|
|
|
{ \
|
|
|
|
static uint64_t __begin = 0; \
|
|
|
|
static int __printed = 0; \
|
|
|
|
static int __missed = 0; \
|
|
|
|
\
|
|
|
|
int __burst = (burst); \
|
|
|
|
int __millis = (millis); \
|
|
|
|
uint64_t __ts = nanos_since_boot(); \
|
|
|
|
\
|
2023-08-24 01:13:46 +08:00
|
|
|
if (!__begin) { __begin = __ts; } \
|
2020-01-18 03:01:02 +08:00
|
|
|
\
|
|
|
|
if (__begin + __millis*1000000ULL < __ts) { \
|
|
|
|
if (__missed) { \
|
2021-08-06 03:05:49 +08:00
|
|
|
cloudlog(CLOUDLOG_WARNING, "cloudlog: %d messages suppressed", __missed); \
|
2020-01-18 03:01:02 +08:00
|
|
|
} \
|
|
|
|
__begin = 0; \
|
|
|
|
__printed = 0; \
|
|
|
|
__missed = 0; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
if (__printed < __burst) { \
|
|
|
|
cloudlog(lvl, fmt, ## __VA_ARGS__); \
|
|
|
|
__printed++; \
|
|
|
|
} else { \
|
|
|
|
__missed++; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2022-04-20 05:29:24 +08:00
|
|
|
|
|
|
|
#define LOGT(...) cloudlog_t(CLOUDLOG_DEBUG, __VA_ARGS__)
|
2020-01-18 03:01:02 +08:00
|
|
|
#define LOGD(fmt, ...) cloudlog(CLOUDLOG_DEBUG, fmt, ## __VA_ARGS__)
|
|
|
|
#define LOG(fmt, ...) cloudlog(CLOUDLOG_INFO, fmt, ## __VA_ARGS__)
|
|
|
|
#define LOGW(fmt, ...) cloudlog(CLOUDLOG_WARNING, fmt, ## __VA_ARGS__)
|
|
|
|
#define LOGE(fmt, ...) cloudlog(CLOUDLOG_ERROR, fmt, ## __VA_ARGS__)
|
|
|
|
|
|
|
|
#define LOGD_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_DEBUG, fmt, ## __VA_ARGS__)
|
|
|
|
#define LOG_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_INFO, fmt, ## __VA_ARGS__)
|
|
|
|
#define LOGW_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_WARNING, fmt, ## __VA_ARGS__)
|
|
|
|
#define LOGE_100(fmt, ...) cloudlog_rl(2, 100, CLOUDLOG_ERROR, fmt, ## __VA_ARGS__)
|