From 5e8097873ee5baecc1779420c3ef5be6036d2161 Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 6 Jun 2023 17:02:06 +0800 Subject: [PATCH 1/3] update Signed-off-by: yangliu --- framework/common/logger.h | 65 ++++++++++++++----- .../jskitsimpl/common/napi_data_utils.cpp | 2 +- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/framework/common/logger.h b/framework/common/logger.h index a823081..2292aac 100755 --- a/framework/common/logger.h +++ b/framework/common/logger.h @@ -39,21 +39,56 @@ static inline OHOS::HiviewDFX::HiLogLabel LogLabel() // In order to improve performance, do not check the module range. // Besides, make sure module is less than UDMF_SERVICE. -#define LOG_FATAL(module, fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Fatal( \ - LogLabel(), "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__) -#define LOG_ERROR(module, fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Error( \ - LogLabel(), "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__) -#define LOG_WARN(module, fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Warn( \ - LogLabel(), "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__) -#define LOG_INFO(module, fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Info( \ - LogLabel(), "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__) -#define LOG_DEBUG(module, fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Debug( \ - LogLabel(), "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__) +#define LOG_FATAL(module, fmt, ...) \ + do { \ + using HiLog = OHOS::HiviewDFX::HiLog; \ + auto lable = LogLabel(); \ + if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_FATAL)) { \ + break; \ + } \ + HiLog::Fatal(lable, "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__); \ + } while (0) + +#define LOG_ERROR(module, fmt, ...) \ + do { \ + using HiLog = OHOS::HiviewDFX::HiLog; \ + auto lable = LogLabel(); \ + if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_ERROR)) { \ + break; \ + } \ + HiLog::Error(lable, "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__); \ + } while (0) + +#define LOG_WARN(module, fmt, ...) \ + do { \ + using HiLog = OHOS::HiviewDFX::HiLog; \ + auto lable = LogLabel(); \ + if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_WARN)) { \ + break; \ + } \ + HiLog::Warn(lable, "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__); \ + } while (0) + +#define LOG_INFO(module, fmt, ...) \ + do { \ + using HiLog = OHOS::HiviewDFX::HiLog; \ + auto lable = LogLabel(); \ + if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_INFO)) { \ + break; \ + } \ + HiLog::Info(lable, "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__); \ + } while (0) + +#define LOG_DEBUG(module, fmt, ...) \ + do { \ + using HiLog = OHOS::HiviewDFX::HiLog; \ + auto lable = LogLabel(); \ + if (!HiLogIsLoggable(lable.domain, lable.tag, LogLevel::LOG_DEBUG)) { \ + break; \ + } \ + HiLog::Debug(lable, "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__); \ + } while (0) + } // namespace UDMF } // namespace OHOS #endif // UDMF_LOGGER_H diff --git a/framework/jskitsimpl/common/napi_data_utils.cpp b/framework/jskitsimpl/common/napi_data_utils.cpp index d8eb507..8e474b3 100644 --- a/framework/jskitsimpl/common/napi_data_utils.cpp +++ b/framework/jskitsimpl/common/napi_data_utils.cpp @@ -176,7 +176,7 @@ napi_status NapiDataUtils::GetValue(napi_env env, napi_value in, std::vector 0) && (data != nullptr), "invalid data!", napi_invalid_arg); - out.assign(reinterpret_cast(data), reinterpret_cast(data) + length); + out = (data != nullptr ? std::vector((uint8_t*)data, ((uint8_t*)data) + length) : std::vector()); return status; } -- Gitee From e05f45d6df8437ad4025862e5d72686d929a6fb4 Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 6 Jun 2023 18:03:26 +0800 Subject: [PATCH 2/3] update Signed-off-by: yangliu --- framework/common/logger.h | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/common/logger.h b/framework/common/logger.h index 2292aac..370b383 100755 --- a/framework/common/logger.h +++ b/framework/common/logger.h @@ -88,7 +88,6 @@ static inline OHOS::HiviewDFX::HiLogLabel LogLabel() } \ HiLog::Debug(lable, "%{public}d: %{public}s " fmt " ", __LINE__, __FUNCTION__, ##__VA_ARGS__); \ } while (0) - } // namespace UDMF } // namespace OHOS #endif // UDMF_LOGGER_H -- Gitee From c6a379f885f513265ac9b7c05f821c9fdd72aafd Mon Sep 17 00:00:00 2001 From: yangliu Date: Tue, 6 Jun 2023 21:04:21 +0800 Subject: [PATCH 3/3] fix Signed-off-by: yangliu --- framework/jskitsimpl/common/napi_data_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/jskitsimpl/common/napi_data_utils.cpp b/framework/jskitsimpl/common/napi_data_utils.cpp index 8e474b3..d8eb507 100644 --- a/framework/jskitsimpl/common/napi_data_utils.cpp +++ b/framework/jskitsimpl/common/napi_data_utils.cpp @@ -176,7 +176,7 @@ napi_status NapiDataUtils::GetValue(napi_env env, napi_value in, std::vector 0) && (data != nullptr), "invalid data!", napi_invalid_arg); - out = (data != nullptr ? std::vector((uint8_t*)data, ((uint8_t*)data) + length) : std::vector()); + out.assign(reinterpret_cast(data), reinterpret_cast(data) + length); return status; } -- Gitee