!878 新增限频日志接口

Merge pull request !878 from dongqingran/feature_log_limit
This commit is contained in:
openharmony_ci 2024-02-04 11:02:38 +00:00 committed by Gitee
commit 258146dbbc
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -25,6 +25,8 @@
#define EVENT_LOG_TAG "Ces"
#endif
#define EVENT_LOG_LIMIT_INTERVALS 10000 //ms
#define CUR_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define EVENT_LOGF(fmt, ...) \
@ -43,4 +45,73 @@
((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, EVENT_LOG_DOMAIN, EVENT_LOG_TAG, \
"[%{public}s(%{public}s:%{public}d)]" fmt, CUR_FILE_NAME, __FUNCTION__, __LINE__, ##__VA_ARGS__))
#define EVENT_PRINT_LIMIT(type, level, intervals, canPrint) \
do { \
static auto last = std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>(); \
static uint32_t supressed = 0; \
auto now = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()); \
auto duration = now - last; \
if (duration.count() >= (intervals)) { \
last = now; \
uint32_t supressedCnt = supressed; \
supressed = 0; \
if (supressedCnt != 0) { \
((void)HILOG_IMPL((type), (level), EVENT_LOG_DOMAIN, EVENT_LOG_TAG, \
"[%{public}s(%{public}s:%{public}d)]log suppressed cnt %{public}u", \
CUR_FILE_NAME, __FUNCTION__, __LINE__, supressedCnt)); \
} \
(canPrint) = true; \
} else { \
supressed++; \
(canPrint) = false; \
} \
} while (0)
#define EVENT_LOGF_LIMIT(fmt, ...) \
do { \
bool can = true; \
EVENT_PRINT_LIMIT(LOG_CORE, LOG_FATAL, EVENT_LOG_LIMIT_INTERVALS, can); \
if (can) { \
EVENT_LOGF(fmt, ##__VA_ARGS__); \
} \
} while (0)
#define EVENT_LOGE_LIMIT(fmt, ...) \
do { \
bool can = true; \
EVENT_PRINT_LIMIT(LOG_CORE, LOG_ERROR, EVENT_LOG_LIMIT_INTERVALS, can); \
if (can) { \
EVENT_LOGE(fmt, ##__VA_ARGS__); \
} \
} while (0)
#define EVENT_LOGW_LIMIT(fmt, ...) \
do { \
bool can = true; \
EVENT_PRINT_LIMIT(LOG_CORE, LOG_WARN, EVENT_LOG_LIMIT_INTERVALS, can); \
if (can) { \
EVENT_LOGW(fmt, ##__VA_ARGS__); \
} \
} while (0)
#define EVENT_LOGI_LIMIT(fmt, ...) \
do { \
bool can = true; \
EVENT_PRINT_LIMIT(LOG_CORE, LOG_INFO, EVENT_LOG_LIMIT_INTERVALS, can); \
if (can) { \
EVENT_LOGI(fmt, ##__VA_ARGS__); \
} \
} while (0)
#define EVENT_LOGD_LIMIT(fmt, ...) \
do { \
bool can = true; \
EVENT_PRINT_LIMIT(LOG_CORE, LOG_DEBUG, EVENT_LOG_LIMIT_INTERVALS, can); \
if (can) { \
EVENT_LOGD(fmt, ##__VA_ARGS__); \
} \
} while (0)
#endif // FOUNDATION_EVENT_COMMON_LOG_INCLUDE_EVENT_LOG_WRAPPER_H