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 "dev_slinfo_log.h"
17
18 #include <stdint.h>
19 #include "securec.h"
20
DataSlPrint(const char * buf,DataSlLogLevel level)21 static void DataSlPrint(const char *buf, DataSlLogLevel level)
22 {
23 switch (level) {
24 case LOG_LEVEL_DEBUG:
25 DataSl_LOG_DEBUG(buf);
26 break;
27 case LOG_LEVEL_INFO:
28 DataSl_LOG_INFO(buf);
29 break;
30 case LOG_LEVEL_WARN:
31 DataSl_LOG_WARN(buf);
32 break;
33 case LOG_LEVEL_ERROR:
34 DataSl_LOG_ERROR(buf);
35 break;
36 default:
37 break;
38 }
39 }
40
DataSlLogPrint(DataSlLogLevel level,const char * funName,const char * fmt,...)41 void DataSlLogPrint(DataSlLogLevel level, const char *funName, const char *fmt, ...)
42 {
43 int32_t ulPos = 0;
44 char outStr[LOG_PRINT_MAX_LEN] = {0};
45 int32_t ret = sprintf_s(outStr, sizeof(outStr), "%s: ", funName);
46 if (ret < 0) {
47 return;
48 }
49 ulPos = strlen(outStr);
50 va_list arg;
51 va_start(arg, fmt);
52 ret = vsprintf_s(&outStr[ulPos], sizeof(outStr) - ulPos, fmt, arg);
53 va_end(arg);
54 if (ret < 0) {
55 return;
56 }
57 DataSlPrint(outStr, level);
58 }
59