!568 fix: user版本中不打印filename,同时避免二进制中带入路径信息

Merge pull request !568 from hw_mzyan/master
This commit is contained in:
openharmony_ci 2024-08-24 11:44:34 +00:00 committed by Gitee
commit 0987d6c262
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 28 additions and 10 deletions

View File

@ -32,6 +32,10 @@ config("hiperf_inner_config") {
cflags -= [ "-Werror" ]
}
if (build_variant == "user") {
cflags += [ "-DIS_RELEASE_VERSION" ]
}
if (is_mingw) {
# lld: error: unable to find library -latomic
# lld: error: unable to find library -ldl

View File

@ -75,9 +75,6 @@ const std::string DEFAULT_LOG_PATH = "hiperf_log.txt";
#define HILOG_TAG_NAME HILOG_BASE_TAG "_" HILOG_TAG
#endif
#define SHORT_FILENAME \
(__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
const std::map<DebugLevel, const std::string> DebugLevelMap = {
{LEVEL_MUCH, "M"}, {LEVEL_VERBOSE, "V"}, {LEVEL_DEBUG, "D"}, {LEVEL_INFO, "I"},
{LEVEL_WARNING, "W"}, {LEVEL_ERROR, "E"}, {LEVEL_FATAL, "F"},
@ -185,16 +182,28 @@ private:
#define LOG_LEVEL_FATAL "F:"
#ifndef HLOG
#ifdef IS_RELEASE_VERSION
#define HLOG(level, format, ...) \
do { \
if (__builtin_expect(!DebugLogger::logDisabled_, false)) { \
DebugLogger::GetInstance()->Log( \
level, HILOG_TAG, \
HILOG_TAG_NAME "/" LOG_LEVEL(level) "<%ld>%s:" format "\n", gettid(), \
__FUNCTION__, ##__VA_ARGS__); \
} \
} while (0)
#else
#define HLOG(level, format, ...) \
do { \
if (__builtin_expect(!DebugLogger::logDisabled_, false)) { \
DebugLogger::GetInstance()->Log( \
level, HILOG_TAG, \
HILOG_TAG_NAME "/" LOG_LEVEL(level) "<%ld>[%s:%d]%s:" format "\n", gettid(), \
SHORT_FILENAME, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
__FILE_NAME__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \
} \
} while (0)
#endif
#endif
// only log first n times
#ifndef HLOGV_FIRST
@ -266,8 +275,12 @@ private:
#endif
#ifndef HLOGF
#ifdef IS_RELEASE_VERSION
#define HLOGF(format, ...) HLOG(LEVEL_FATAL, "FATAL error occured, " format, ##__VA_ARGS__)
#else
#define HLOGF(format, ...) \
HLOG(LEVEL_FATAL, "FATAL error at %s:%d " format, __FILE__, __LINE__, ##__VA_ARGS__)
HLOG(LEVEL_FATAL, "FATAL error at %s:%d " format, __FILE_NAME__, __LINE__, ##__VA_ARGS__)
#endif
#endif
#ifndef HLOG_ASSERT_MESSAGE

View File

@ -27,12 +27,13 @@
#define HILOG_NEWLINE "\n"
#endif
#define FILENAME \
(__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define FORMATTED(fmt, ...) \
"[%" HILOG_PUBLIC "s:%" HILOG_PUBLIC "d] %" HILOG_PUBLIC "s# " fmt HILOG_NEWLINE, FILENAME, \
#ifdef IS_RELEASE_VERSION
#define FORMATTED(fmt, ...) "[%" HILOG_PUBLIC "s]" fmt HILOG_NEWLINE, __FUNCTION__, ##__VA_ARGS__
#else
#define FORMATTED(fmt, ...) \
"[%" HILOG_PUBLIC "s:%" HILOG_PUBLIC "d] %" HILOG_PUBLIC "s# " fmt HILOG_NEWLINE, __FILE_NAME__, \
__LINE__, __FUNCTION__, ##__VA_ARGS__
#endif
#ifndef CONFIG_NO_HILOG
#include "hilog/log.h"