|
19 | 19 |
|
20 | 20 | #pragma once |
21 | 21 |
|
| 22 | +#include <cinttypes> |
| 23 | +#include <cstdlib> |
| 24 | +#include <sstream> |
| 25 | +#include <string> |
| 26 | + |
22 | 27 | #include <olp/core/logging/Format.h> |
23 | 28 | #include <olp/core/logging/Level.h> |
24 | 29 |
|
25 | 30 | #include <olp/core/CoreApi.h> |
26 | 31 | #include <olp/core/utils/WarningWorkarounds.h> |
27 | 32 |
|
28 | | -#include <boost/none.hpp> |
29 | 33 | #include <boost/optional.hpp> |
30 | 34 |
|
31 | | -#include <cinttypes> |
32 | | -#include <cstdlib> |
33 | | -#include <sstream> |
34 | | -#include <string> |
35 | | - |
36 | 35 | /** |
37 | 36 | * @file |
38 | 37 | * @brief Provides the main interface for the logging library. |
|
41 | 40 | /** |
42 | 41 | * @brief Gets the current function signature for different compilers. |
43 | 42 | */ |
| 43 | +#ifdef LOGGING_DISABLE_LOCATION |
| 44 | + |
| 45 | +#define OLP_SDK_LOG_FUNCTION_SIGNATURE "" |
| 46 | +#define OLP_SDK_LOG_FILE "" |
| 47 | +#define OLP_SDK_LOG_LINE 0 |
| 48 | +#define OLP_SDK_LOG_FUNCTION "" |
| 49 | + |
| 50 | +#else // LOGGING_DISABLE_LOCATION |
| 51 | + |
44 | 52 | #if __GNUC__ >= 3 || defined(__clang__) |
45 | 53 | #define OLP_SDK_LOG_FUNCTION_SIGNATURE __PRETTY_FUNCTION__ |
46 | 54 | #elif defined(_MSC_VER) |
|
49 | 57 | #define OLP_SDK_LOG_FUNCTION_SIGNATURE __FUNCTION__ |
50 | 58 | #endif |
51 | 59 |
|
| 60 | +#define OLP_SDK_LOG_FILE __FILE__ |
| 61 | +#define OLP_SDK_LOG_LINE __LINE__ |
| 62 | +#define OLP_SDK_LOG_FUNCTION __FUNCTION__ |
| 63 | + |
| 64 | +#endif // LOGGING_DISABLE_LOCATION |
| 65 | + |
52 | 66 | /** |
53 | 67 | * @brief Logs a message using C++ style streams. |
54 | 68 | * |
|
59 | 73 | * @param tag The tag for the log component. |
60 | 74 | * @param message The log message. |
61 | 75 | */ |
62 | | -#define OLP_SDK_DO_LOG(level, tag, message) \ |
63 | | - do { \ |
64 | | - std::ostringstream __strm; \ |
65 | | - __strm << message; \ |
66 | | - ::olp::logging::Log::logMessage(level, tag, __strm.str(), __FILE__, \ |
67 | | - __LINE__, __FUNCTION__, \ |
68 | | - OLP_SDK_LOG_FUNCTION_SIGNATURE); \ |
69 | | - } \ |
| 76 | +#define OLP_SDK_DO_LOG(level, tag, message) \ |
| 77 | + do { \ |
| 78 | + std::ostringstream __strm; \ |
| 79 | + __strm << message; \ |
| 80 | + ::olp::logging::Log::logMessage( \ |
| 81 | + level, tag, __strm.str(), OLP_SDK_LOG_FILE, OLP_SDK_LOG_LINE, \ |
| 82 | + OLP_SDK_LOG_FUNCTION, OLP_SDK_LOG_FUNCTION_SIGNATURE); \ |
| 83 | + } \ |
70 | 84 | OLP_SDK_CORE_LOOP_ONCE() |
71 | 85 |
|
72 | 86 | /** |
|
153 | 167 | * @param level The log level. |
154 | 168 | * @param tag The tag for the log component. |
155 | 169 | */ |
156 | | -#define OLP_SDK_DO_LOG_F(level, tag, ...) \ |
157 | | - do { \ |
158 | | - std::string __message = ::olp::logging::format(__VA_ARGS__); \ |
159 | | - ::olp::logging::Log::logMessage(level, tag, __message, __FILE__, __LINE__, \ |
160 | | - __FUNCTION__, \ |
161 | | - OLP_SDK_LOG_FUNCTION_SIGNATURE); \ |
162 | | - } \ |
| 170 | +#define OLP_SDK_DO_LOG_F(level, tag, ...) \ |
| 171 | + do { \ |
| 172 | + std::string __message = ::olp::logging::format(__VA_ARGS__); \ |
| 173 | + ::olp::logging::Log::logMessage(level, tag, __message, OLP_SDK_LOG_FILE, \ |
| 174 | + OLP_SDK_LOG_LINE, OLP_SDK_LOG_FUNCTION, \ |
| 175 | + OLP_SDK_LOG_FUNCTION_SIGNATURE); \ |
| 176 | + } \ |
163 | 177 | OLP_SDK_CORE_LOOP_ONCE() |
164 | 178 |
|
165 | 179 | /** |
|
208 | 222 | OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Error, tag, __VA_ARGS__) |
209 | 223 |
|
210 | 224 | /** |
211 | | - * @brief Logs a "Critical fatal error" message using the printf-style formatting. |
| 225 | + * @brief Logs a "Critical fatal error" message using the printf-style |
| 226 | + * formatting. |
212 | 227 | * |
213 | 228 | * `OLP_SDK_LOGGING_DISABLED` does not disable this functionality. |
214 | 229 | * Additionally, it does not check to see if the tag is disabled. |
|
219 | 234 | OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Fatal, tag, __VA_ARGS__) |
220 | 235 |
|
221 | 236 | /** |
222 | | - * @brief Logs a "Critical fatal error" message using the printf-style formatting, |
223 | | - * and then abort sthe program. |
| 237 | + * @brief Logs a "Critical fatal error" message using the printf-style |
| 238 | + * formatting, and then abort sthe program. |
224 | 239 | * |
225 | 240 | * @param tag The tag for the log component. |
226 | 241 | */ |
@@ -480,7 +495,8 @@ class CORE_API Log { |
480 | 495 | * @param tag The tag for the log component. If empty, it sets the |
481 | 496 | * default level. |
482 | 497 | * |
483 | | - * @return The log level for the tag or `core::None` if the log level is unset. |
| 498 | + * @return The log level for the tag or `core::None` if the log level is |
| 499 | + * unset. |
484 | 500 | */ |
485 | 501 | static boost::optional<Level> getLevel(const std::string& tag); |
486 | 502 |
|
@@ -540,13 +556,13 @@ class CORE_API Log { |
540 | 556 | * @param file The file that generated the message. |
541 | 557 | * @param line The line in the file where the message was logged. |
542 | 558 | * @param function The function that generated the message. |
543 | | - * @param fullFunction The fully qualified function that generated the message. |
| 559 | + * @param fullFunction The fully qualified function that generated the |
| 560 | + * message. |
544 | 561 | */ |
545 | 562 | static void logMessage(Level level, const std::string& tag, |
546 | 563 | const std::string& message, const char* file, |
547 | 564 | unsigned int line, const char* function, |
548 | 565 | const char* fullFunction); |
549 | 566 | }; |
550 | | - |
551 | 567 | } // namespace logging |
552 | 568 | } // namespace olp |
0 commit comments