Skip to content

Commit f590798

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 f590798

File tree

4 files changed

+61
-38
lines changed

4 files changed

+61
-38
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: 54 additions & 38 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
*/
@@ -406,7 +421,7 @@ class NullLogStream {
406421
/**
407422
* @brief The stream operator to print or serialize the given log stream.
408423
*/
409-
NullLogStream& operator<<(const T&) {
424+
NullLogStream &operator<<(const T &) {
410425
return *this;
411426
}
412427
};
@@ -461,7 +476,7 @@ class CORE_API Log {
461476
* @param tag The tag for the log component. If empty, it sets the
462477
* default level.
463478
*/
464-
static void setLevel(Level level, const std::string& tag);
479+
static void setLevel(Level level, const std::string &tag);
465480

466481
/**
467482
* @brief Sets the log level for a tag.
@@ -472,25 +487,26 @@ class CORE_API Log {
472487
* @param tag The tag for the log component. If empty, it sets the
473488
* default level.
474489
*/
475-
static void setLevel(const std::string& level, const std::string& tag);
490+
static void setLevel(const std::string &level, const std::string &tag);
476491

477492
/**
478493
* @brief Gets the log level for a tag.
479494
*
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
*/
485-
static boost::optional<Level> getLevel(const std::string& tag);
501+
static boost::optional<Level> getLevel(const std::string &tag);
486502

487503
/**
488504
* @brief Clears the log level for a tag and sets it to
489505
* the default value.
490506
*
491507
* @param tag The tag for the log component.
492508
*/
493-
static void clearLevel(const std::string& tag);
509+
static void clearLevel(const std::string &tag);
494510

495511
/**
496512
* @brief Clears the log levels for all tags and sets them to
@@ -507,7 +523,7 @@ class CORE_API Log {
507523
*
508524
* @param filters The filter group to apply.
509525
*/
510-
static void applyFilterGroup(const FilterGroup& filters);
526+
static void applyFilterGroup(const FilterGroup &filters);
511527

512528
/**
513529
* @brief Checks whether a level is enabled by default.
@@ -526,7 +542,7 @@ class CORE_API Log {
526542
*
527543
* @return True if the log is enabled; false otherwise.
528544
*/
529-
static bool isEnabled(Level level, const std::string& tag);
545+
static bool isEnabled(Level level, const std::string &tag);
530546

531547
/**
532548
* @brief Logs a message to the registered appenders.
@@ -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
*/
545-
static void logMessage(Level level, const std::string& tag,
546-
const std::string& message, const char* file,
547-
unsigned int line, const char* function,
548-
const char* fullFunction);
562+
static void logMessage(Level level, const std::string &tag,
563+
const std::string &message, const char *file,
564+
unsigned int line, const char *function,
565+
const char *fullFunction);
549566
};
550-
551567
} // namespace logging
552568
} // namespace olp

0 commit comments

Comments
 (0)