1 /*
2 * Copyright (c) 2023 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 "cf_log.h"
17
18 #include "securec.h"
19
20 #define MAX_LOG_BUFF_LEN 512
21
CfLog(uint32_t logLevel,const char * funcName,uint32_t lineNo,const char * format,...)22 void CfLog(uint32_t logLevel, const char *funcName, uint32_t lineNo, const char *format, ...)
23 {
24 char buf[MAX_LOG_BUFF_LEN] = {0};
25
26 va_list ap;
27 va_start(ap, format);
28 int32_t ret = vsnprintf_s(buf, MAX_LOG_BUFF_LEN, MAX_LOG_BUFF_LEN - 1, format, ap);
29 va_end(ap);
30 if (ret < 0) {
31 HILOG_ERROR(LOG_CORE, "certificate framework log concatenate error.");
32 return;
33 }
34
35 switch (logLevel) {
36 case CF_LOG_LEVEL_I:
37 HILOG_INFO(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, buf);
38 break;
39 case CF_LOG_LEVEL_E:
40 HILOG_ERROR(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, buf);
41 break;
42 case CF_LOG_LEVEL_W:
43 HILOG_WARN(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, buf);
44 break;
45 case CF_LOG_LEVEL_D:
46 HILOG_DEBUG(LOG_CORE, "%{public}s[%{public}u]: %{private}s\n", funcName, lineNo, buf);
47 break;
48 default:
49 return;
50 }
51 }
52