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 "softbus_log.h"
17 
18 #include <securec.h>
19 
20 #define NSTACKX_LOG_LEVEL_CONVERT_BASE 8
21 
SoftBusLogPrint(const char * line,uint32_t level,uint32_t domain,const char * tag)22 static void SoftBusLogPrint(const char *line, uint32_t level, uint32_t domain, const char *tag)
23 {
24 #if defined(SOFTBUS_LITEOS_M)
25     (void)level;
26     (void)domain;
27     (void)tag;
28     printf("%s\n", line);
29 #else
30     (void)HiLogPrint(LOG_CORE, (LogLevel)level, domain, tag, "%{public}s", line);
31 #endif
32 }
33 
NstackxLogInnerImpl(const char * moduleName,uint32_t logLevel,const char * fmt,...)34 void NstackxLogInnerImpl(const char *moduleName, uint32_t logLevel, const char *fmt, ...)
35 {
36     uint32_t level = NSTACKX_LOG_LEVEL_CONVERT_BASE - logLevel;
37     va_list args = { 0 };
38     char line[LOG_LINE_MAX_LENGTH + 1] = { 0 };
39     va_start(args, fmt);
40     int32_t ret = vsprintf_s(line, sizeof(line), fmt, args);
41     va_end(args);
42     if (ret < 0) {
43         return; // Do not print log here
44     }
45     SoftBusLogPrint(line, level, NSTACKX_LOG_DOMAIN, moduleName);
46 }