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 "hc_log.h"
17 #include "securec.h"
18
19 #define LOG_PRINT_MAX_LEN 256
20
DevAuthOutPrint(const char * buf,DevAuthLogLevel level)21 static void DevAuthOutPrint(const char *buf, DevAuthLogLevel level)
22 {
23 #ifdef DEV_AUTH_DEBUG_PRINTF
24 printf("[DEVAUTH]: %s\n", buf);
25 return;
26 #endif
27 switch (level) {
28 case DEV_AUTH_LOG_LEVEL_DEBUG:
29 DEV_AUTH_LOG_DEBUG(buf);
30 break;
31 case DEV_AUTH_LOG_LEVEL_INFO:
32 DEV_AUTH_LOG_INFO(buf);
33 break;
34 case DEV_AUTH_LOG_LEVEL_WARN:
35 DEV_AUTH_LOG_WARN(buf);
36 break;
37 case DEV_AUTH_LOG_LEVEL_ERROR:
38 DEV_AUTH_LOG_ERROR(buf);
39 break;
40 default:
41 break;
42 }
43 }
44
DevAuthLogPrint(DevAuthLogLevel level,const char * funName,const char * fmt,...)45 void DevAuthLogPrint(DevAuthLogLevel level, const char *funName, const char *fmt, ...)
46 {
47 int32_t ulPos = 0;
48 char outStr[LOG_PRINT_MAX_LEN] = {0};
49 int32_t ret = sprintf_s(outStr, sizeof(outStr), "%s: ", funName);
50 if (ret < 0) {
51 return;
52 }
53 ulPos = strlen(outStr);
54 va_list arg;
55 va_start(arg, fmt);
56 ret = vsprintf_s(&outStr[ulPos], sizeof(outStr) - ulPos, fmt, arg);
57 va_end(arg);
58 if (ret < 0) {
59 return;
60 }
61 DevAuthOutPrint(outStr, level);
62 }