• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2025 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 #ifndef PANDA_PLUGINS_ETS_TOOLS_FORMAT_LOGGER_H
17 #define PANDA_PLUGINS_ETS_TOOLS_FORMAT_LOGGER_H
18 #include "utils/logger.h"
19 #include <securec.h>
20 
21 namespace ark {
FormatString(const char * fmt,...)22 inline std::string FormatString(const char *fmt, ...)
23 {
24     // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
25     va_list args;
26     // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
27     va_start(args, fmt);
28     const size_t bufferSize = 512;
29     std::array<char, bufferSize> buffer {};
30     int put = vsnprintf_s(buffer.data(), bufferSize, bufferSize - 1, fmt, args);
31     if (put < 0) {
32         return "";
33     }
34     va_end(args);
35     return std::string(buffer.data());
36 }
37 
38 // NOLINTBEGIN(cppcoreguidelines-macro-usage)
39 #define LOG_INFO_SDK(...) IMPL_LOG(INFO, SDK, false) << ark::FormatString(__VA_ARGS__)
40 #define LOG_WARNING_SDK(...) IMPL_LOG(WARNING, SDK, false) << ark::FormatString(__VA_ARGS__)
41 #define LOG_ERROR_SDK(...) IMPL_LOG(ERROR, SDK, false) << ark::FormatString(__VA_ARGS__)
42 #define LOG_FATAL_SDK(...) IMPL_LOG(FATAL, SDK, false) << ark::FormatString(__VA_ARGS__)
43 // NOLINTEND(cppcoreguidelines-macro-usage)
44 }  // namespace ark
45 #endif
46