Skip to content

Commit 627bc83

Browse files
Add an option to disable the log messages location
By disabling the log locations, the compiler will generate binaries with lower size Relates-To: DATASDK-51 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent de37609 commit 627bc83

File tree

4 files changed

+50
-27
lines changed

4 files changed

+50
-27
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ option(OLP_SDK_BUILD_EXTERNAL_DEPS "Download and build external dependencies" ON
4242
option(OLP_SDK_BUILD_EXAMPLES "Enable examples targets" OFF)
4343
option(OLP_SDK_MSVC_PARALLEL_BUILD_ENABLE "Enable parallel build on MSVC" ON)
4444
option(OLP_SDK_DISABLE_DEBUG_LOGGING "Disable debug and trace level logging" OFF)
45+
option(OLP_SDK_DISABLE_LOCATION_LOGGING "Disable the log location" OFF)
4546
option(OLP_SDK_ENABLE_DEFAULT_CACHE "Enable default cache implementation based on LevelDB" ON)
4647
option(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB "Enable default cache implementation based on LMDB" OFF)
4748
option(OLP_SDK_ENABLE_ANDROID_CURL "Enable curl based network layer for Android" OFF)

docs/get-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ cmake --build . --target docs
133133
| `OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL` | Defaults to `OFF`. When `OLP_SDK_NO_EXCEPTION` is `ON`, `boost` requires `boost::throw_exception()` to be defined. If enabled, the external definition of `boost::throw_exception()` is used. Otherwise, the library uses own definition. |
134134
| `OLP_SDK_MSVC_PARALLEL_BUILD_ENABLE` (Windows Only) | Defaults to `ON`. If enabled, the `/MP` compilation flag is added to build the Data SDK using multiple cores. |
135135
| `OLP_SDK_DISABLE_DEBUG_LOGGING`| Defaults to `OFF`. If enabled, the debug and trace level log messages are not printed. |
136+
| `OLP_SDK_DISABLE_LOCATION_LOGGING`| Defaults to `OFF`. If enabled, the level messages locations are not generated by compiler. |
136137
| `OLP_SDK_ENABLE_DEFAULT_CACHE `| Defaults to `ON`. If enabled, the default cache implementation based on the LevelDB backend is enabled. |
137138
| `OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB `| Defaults to `OFF`. If enabled, the default cache implementation based on the LMDB backend is enabled. |
138139
| `OLP_SDK_ENABLE_ANDROID_CURL`| Defaults to `OFF`. If enabled, libcurl will be used instead of the Android native HTTP client. |

olp-cpp-sdk-core/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,11 @@ if (OLP_SDK_DISABLE_DEBUG_LOGGING)
423423
PUBLIC LOGGING_DISABLE_DEBUG_LEVEL)
424424
endif()
425425

426+
if (OLP_SDK_DISABLE_LOCATION_LOGGING)
427+
target_compile_definitions(${PROJECT_NAME}
428+
PUBLIC LOGGING_DISABLE_LOCATION)
429+
endif()
430+
426431
target_compile_definitions(${PROJECT_NAME}
427432
PRIVATE ${OLP_SDK_DEFAULT_NETWORK_DEFINITION})
428433

olp-cpp-sdk-core/include/olp/core/logging/Log.h

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,19 @@
1919

2020
#pragma once
2121

22+
#include <cinttypes>
23+
#include <cstdlib>
24+
#include <sstream>
25+
#include <string>
26+
2227
#include <olp/core/logging/Format.h>
2328
#include <olp/core/logging/Level.h>
2429

2530
#include <olp/core/CoreApi.h>
2631
#include <olp/core/utils/WarningWorkarounds.h>
2732

28-
#include <boost/none.hpp>
2933
#include <boost/optional.hpp>
3034

31-
#include <cinttypes>
32-
#include <cstdlib>
33-
#include <sstream>
34-
#include <string>
35-
3635
/**
3736
* @file
3837
* @brief Provides the main interface for the logging library.
@@ -41,6 +40,15 @@
4140
/**
4241
* @brief Gets the current function signature for different compilers.
4342
*/
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+
4452
#if __GNUC__ >= 3 || defined(__clang__)
4553
#define OLP_SDK_LOG_FUNCTION_SIGNATURE __PRETTY_FUNCTION__
4654
#elif defined(_MSC_VER)
@@ -49,6 +57,12 @@
4957
#define OLP_SDK_LOG_FUNCTION_SIGNATURE __FUNCTION__
5058
#endif
5159

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+
5266
/**
5367
* @brief Logs a message using C++ style streams.
5468
*
@@ -59,14 +73,14 @@
5973
* @param tag The tag for the log component.
6074
* @param message The log message.
6175
*/
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+
} \
7084
OLP_SDK_CORE_LOOP_ONCE()
7185

7286
/**
@@ -153,13 +167,13 @@
153167
* @param level The log level.
154168
* @param tag The tag for the log component.
155169
*/
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+
} \
163177
OLP_SDK_CORE_LOOP_ONCE()
164178

165179
/**
@@ -208,7 +222,8 @@
208222
OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Error, tag, __VA_ARGS__)
209223

210224
/**
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.
212227
*
213228
* `OLP_SDK_LOGGING_DISABLED` does not disable this functionality.
214229
* Additionally, it does not check to see if the tag is disabled.
@@ -219,8 +234,8 @@
219234
OLP_SDK_LOG_CRITICAL_F(::olp::logging::Level::Fatal, tag, __VA_ARGS__)
220235

221236
/**
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.
224239
*
225240
* @param tag The tag for the log component.
226241
*/
@@ -480,7 +495,8 @@ class CORE_API Log {
480495
* @param tag The tag for the log component. If empty, it sets the
481496
* default level.
482497
*
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.
484500
*/
485501
static boost::optional<Level> getLevel(const std::string& tag);
486502

@@ -540,13 +556,13 @@ class CORE_API Log {
540556
* @param file The file that generated the message.
541557
* @param line The line in the file where the message was logged.
542558
* @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.
544561
*/
545562
static void logMessage(Level level, const std::string& tag,
546563
const std::string& message, const char* file,
547564
unsigned int line, const char* function,
548565
const char* fullFunction);
549566
};
550-
551567
} // namespace logging
552568
} // namespace olp

0 commit comments

Comments
 (0)