mirror of
https://gitee.com/openharmony/security_crypto_framework
synced 2024-11-23 15:00:04 +00:00
日志整改
Signed-off-by: 王静 <wangjing561@huawei.com>
This commit is contained in:
parent
1b3f9c5567
commit
9c2898f274
@ -21,6 +21,7 @@ framework_common_util_files = [
|
||||
"//base/security/crypto_framework/common/src/asy_key_params.c",
|
||||
"//base/security/crypto_framework/common/src/blob.c",
|
||||
"//base/security/crypto_framework/common/src/utils.c",
|
||||
"//base/security/crypto_framework/common/src/log.c",
|
||||
"//base/security/crypto_framework/common/src/memory.c",
|
||||
"//base/security/crypto_framework/common/src/hcf_parcel.c",
|
||||
"//base/security/crypto_framework/common/src/hcf_string.c",
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#define HCF_MAX_STR_LEN 1024 // input string parameter max length limit, include \0
|
||||
#define HCF_MAX_ALGO_NAME_LEN 128 // input algoName parameter max length limit, include \0
|
||||
#define LOG_PRINT_MAX_LEN 1024 // log max length limit
|
||||
#define LOG_PRINT_MAX_LEN 256 // log max length limit
|
||||
#define HCF_MAX_BUFFER_LEN 8192
|
||||
#define SERIAL_NUMBER_HEDER_SIZE 2
|
||||
#define INVALID_VERSION (-1)
|
||||
|
@ -16,8 +16,28 @@
|
||||
#ifndef HCF_LOG_H
|
||||
#define HCF_LOG_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HILOG_ENABLE
|
||||
|
||||
enum HcfLogLevel {
|
||||
HCF_LOG_LEVEL_I,
|
||||
HCF_LOG_LEVEL_E,
|
||||
HCF_LOG_LEVEL_W,
|
||||
HCF_LOG_LEVEL_D,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void HcfLogPrint(uint32_t hcfLogLevel, const char *funcName, uint32_t lineNo, const char *format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "hilog/log.h"
|
||||
|
||||
#undef LOG_TAG
|
||||
@ -26,11 +46,10 @@
|
||||
#undef LOG_DOMAIN
|
||||
#define LOG_DOMAIN 0xD002F0A /* Security subsystem's domain id */
|
||||
|
||||
#define LOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, "[%{public}s] " fmt, __func__, ##__VA_ARGS__)
|
||||
#define LOGI(fmt, ...) HILOG_INFO(LOG_CORE, "[%{public}s] " fmt, __func__, ##__VA_ARGS__)
|
||||
#define LOGW(fmt, ...) HILOG_WARN(LOG_CORE, "[%{public}s] " fmt, __func__, ##__VA_ARGS__)
|
||||
#define LOGE(fmt, ...) HILOG_DEBUG(LOG_CORE, "[%{public}s] " fmt, __func__, ##__VA_ARGS__)
|
||||
|
||||
#define LOGI(...) HcfLogPrint(HCF_LOG_LEVEL_I, __func__, __LINE__, __VA_ARGS__)
|
||||
#define LOGW(...) HcfLogPrint(HCF_LOG_LEVEL_W, __func__, __LINE__, __VA_ARGS__)
|
||||
#define LOGE(...) HcfLogPrint(HCF_LOG_LEVEL_E, __func__, __LINE__, __VA_ARGS__)
|
||||
#define LOGD(...) HcfLogPrint(HCF_LOG_LEVEL_D, __func__, __LINE__, __VA_ARGS__)
|
||||
#else
|
||||
|
||||
#include <stdio.h>
|
||||
|
51
common/src/log.c
Normal file
51
common/src/log.c
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "securec.h"
|
||||
|
||||
#define HCF_MAX_LOG_BUFF_LEN 512
|
||||
|
||||
void HcfLogPrint(uint32_t hcfLogLevel, const char *funcName, uint32_t lineNo, const char *format, ...)
|
||||
{
|
||||
char logBuf[HCF_MAX_LOG_BUFF_LEN] = {0};
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
int32_t ret = vsnprintf_s(logBuf, HCF_MAX_LOG_BUFF_LEN, HCF_MAX_LOG_BUFF_LEN - 1, format, arg);
|
||||
va_end(arg);
|
||||
if (ret < 0) {
|
||||
HILOG_ERROR(LOG_CORE, "crypto framework log concatenate error.");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (hcfLogLevel) {
|
||||
case HCF_LOG_LEVEL_I:
|
||||
HILOG_INFO(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, logBuf);
|
||||
break;
|
||||
case HCF_LOG_LEVEL_E:
|
||||
HILOG_ERROR(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, logBuf);
|
||||
break;
|
||||
case HCF_LOG_LEVEL_W:
|
||||
HILOG_WARN(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, logBuf);
|
||||
break;
|
||||
case HCF_LOG_LEVEL_D:
|
||||
HILOG_DEBUG(LOG_CORE, "%{public}s[%{public}u]: %{private}s\n", funcName, lineNo, logBuf);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
@ -380,7 +380,7 @@ HcfResult GetSm2SpecStringSm3(char **returnString)
|
||||
|
||||
void HcfPrintOpensslError(void)
|
||||
{
|
||||
char szErr[256] = {0}; // Then maximum length of the OpenSSL error string is 256, less than LOG_PRINT_MAX_LEN.
|
||||
char szErr[LOG_PRINT_MAX_LEN] = {0}; // Then maximum length of the OpenSSL error string is 256.
|
||||
unsigned long errCode;
|
||||
|
||||
errCode = ERR_get_error();
|
||||
|
@ -126,6 +126,7 @@ ohos_unittest("crypto_framework_test") {
|
||||
"//base/security/crypto_framework/common/src/blob.c",
|
||||
"//base/security/crypto_framework/common/src/hcf_parcel.c",
|
||||
"//base/security/crypto_framework/common/src/hcf_string.c",
|
||||
"//base/security/crypto_framework/common/src/log.c",
|
||||
"//base/security/crypto_framework/common/src/object_base.c",
|
||||
"//base/security/crypto_framework/common/src/params_parser.c",
|
||||
"//base/security/crypto_framework/common/src/utils.c",
|
||||
|
Loading…
Reference in New Issue
Block a user