1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "log.h"
17
18 #include "securec.h"
19
20 #ifdef HILOG_ENABLE
21 #include "hilog/log.h"
22 #define HCF_MAX_LOG_BUFF_LEN 512
23
HcfLogPrint(uint32_t hcfLogLevel,const char * funcName,uint32_t lineNo,const char * format,...)24 void HcfLogPrint(uint32_t hcfLogLevel, const char *funcName, uint32_t lineNo, const char *format, ...)
25 {
26 char logBuf[HCF_MAX_LOG_BUFF_LEN] = {0};
27
28 va_list arg;
29 va_start(arg, format);
30 int32_t ret = vsnprintf_s(logBuf, HCF_MAX_LOG_BUFF_LEN, HCF_MAX_LOG_BUFF_LEN - 1, format, arg);
31 va_end(arg);
32 if (ret < 0) {
33 HILOG_ERROR(LOG_CORE, "crypto framework log concatenate error.");
34 return;
35 }
36
37 switch (hcfLogLevel) {
38 case HCF_LOG_LEVEL_I:
39 HILOG_INFO(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, logBuf);
40 break;
41 case HCF_LOG_LEVEL_E:
42 HILOG_ERROR(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, logBuf);
43 break;
44 case HCF_LOG_LEVEL_W:
45 HILOG_WARN(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, logBuf);
46 break;
47 case HCF_LOG_LEVEL_D:
48 HILOG_DEBUG(LOG_CORE, "%{public}s[%{public}u]: %{private}s\n", funcName, lineNo, logBuf);
49 break;
50 default:
51 return;
52 }
53 }
54 #endif
55