• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #undef LOG_DOMAIN
21 #undef LOG_TAG
22 static const unsigned int LOG_DOMAIN = 0xD002F01;
23 static const char* LOG_TAG = "CertFramework";
24 
25 #define MAX_LOG_BUFF_LEN 512
26 
CfLog(uint32_t logLevel,const char * funcName,uint32_t lineNo,const char * format,...)27 void CfLog(uint32_t logLevel, const char *funcName, uint32_t lineNo, const char *format, ...)
28 {
29     char buf[MAX_LOG_BUFF_LEN] = {0};
30 
31     va_list ap;
32     va_start(ap, format);
33     int32_t ret = vsnprintf_s(buf, MAX_LOG_BUFF_LEN, MAX_LOG_BUFF_LEN - 1, format, ap);
34     va_end(ap);
35     if (ret < 0) {
36         HILOG_ERROR(LOG_CORE, "certificate framework log concatenate error.");
37         return;
38     }
39 
40     switch (logLevel) {
41         case CF_LOG_LEVEL_I:
42             HILOG_INFO(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, buf);
43             break;
44         case CF_LOG_LEVEL_E:
45             HILOG_ERROR(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, buf);
46             break;
47         case CF_LOG_LEVEL_W:
48             HILOG_WARN(LOG_CORE, "%{public}s[%{public}u]: %{public}s\n", funcName, lineNo, buf);
49             break;
50         case CF_LOG_LEVEL_D:
51             HILOG_DEBUG(LOG_CORE, "%{public}s[%{public}u]: %{private}s\n", funcName, lineNo, buf);
52             break;
53         default:
54             return;
55     }
56 }
57