• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 <stdint.h>
19 #include "config.h"
20 #include "securec.h"
21 
HcfOutPrint(const char * buf,HcfLogLevel level)22 static void HcfOutPrint(const char *buf, HcfLogLevel level)
23 {
24     switch (level) {
25         case HCF_LOG_LEVEL_DEBUG:
26             HCF_LOG_DEBUG(buf);
27             break;
28         case HCF_LOG_LEVEL_INFO:
29             HCF_LOG_INFO(buf);
30             break;
31         case HCF_LOG_LEVEL_WARN:
32             HCF_LOG_WARN(buf);
33             break;
34         case HCF_LOG_LEVEL_ERROR:
35             HCF_LOG_ERROR(buf);
36             break;
37         default:
38             break;
39     }
40 }
41 
HcfLogPrint(HcfLogLevel level,const char * funName,const char * fmt,...)42 void HcfLogPrint(HcfLogLevel level, const char *funName, const char *fmt, ...)
43 {
44     int32_t ulPos = 0;
45     char outStr[LOG_PRINT_MAX_LEN] = {0};
46     int32_t ret = sprintf_s(outStr, sizeof(outStr), "%s: ", funName);
47     if (ret < 0) {
48         return;
49     }
50     ulPos = strlen(outStr);
51     va_list arg;
52     va_start(arg, fmt);
53     ret = vsprintf_s(&outStr[ulPos], sizeof(outStr) - ulPos, fmt, arg);
54     va_end(arg);
55     if (ret < 0) {
56         return;
57     }
58     HcfOutPrint(outStr, level);
59 }
60