Skip to content

Commit 82f684d

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 82f684d

File tree

4 files changed

+184
-162
lines changed

4 files changed

+184
-162
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: 177 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
/**
4242
* @brief Gets the current function signature for different compilers.
4343
*/
44+
#ifdef LOGGING_DISABLE_LOCATION
45+
46+
#define OLP_SDK_LOG_FUNCTION_SIGNATURE ""
47+
#define OLP_SDK_LOG_FILE ""
48+
#define OLP_SDK_LOG_LINE 0
49+
#define OLP_SDK_LOG_FUNCTION ""
50+
51+
#else // LOGGING_DISABLE_LOCATION
52+
4453
#if __GNUC__ >= 3 || defined(__clang__)
4554
#define OLP_SDK_LOG_FUNCTION_SIGNATURE __PRETTY_FUNCTION__
4655
#elif defined(_MSC_VER)
@@ -49,6 +58,12 @@
4958
#define OLP_SDK_LOG_FUNCTION_SIGNATURE __FUNCTION__
5059
#endif
5160

61+
#define OLP_SDK_LOG_FILE __FILE__
62+
#define OLP_SDK_LOG_LINE __LINE__
63+
#define OLP_SDK_LOG_FUNCTION __FUNCTION__
64+
65+
#endif // LOGGING_DISABLE_LOCATION
66+
5267
/**
5368
* @brief Logs a message using C++ style streams.
5469
*
@@ -63,8 +78,9 @@
6378
do { \
6479
std::ostringstream __strm; \
6580
__strm << message; \
66-
::olp::logging::Log::logMessage(level, tag, __strm.str(), __FILE__, \
67-
__LINE__, __FUNCTION__, \
81+
::olp::logging::Log::logMessage(level, tag, __strm.str(), \
82+
OLP_SDK_LOG_FILE, OLP_SDK_LOG_LINE, \
83+
OLP_SDK_LOG_FUNCTION, \
6884
OLP_SDK_LOG_FUNCTION_SIGNATURE); \
6985
} \
7086
OLP_SDK_CORE_LOOP_ONCE()
@@ -156,8 +172,8 @@
156172
#define OLP_SDK_DO_LOG_F(level, tag, ...) \
157173
do { \
158174
std::string __message = ::olp::logging::format(__VA_ARGS__); \
159-
::olp::logging::Log::logMessage(level, tag, __message, __FILE__, __LINE__, \
160-
__FUNCTION__, \
175+
::olp::logging::Log::logMessage(level, tag, __message, OLP_SDK_LOG_FILE, \
176+
OLP_SDK_LOG_LINE, OLP_SDK_LOG_FUNCTION, \
161177
OLP_SDK_LOG_FUNCTION_SIGNATURE); \
162178
} \
163179
OLP_SDK_CORE_LOOP_ONCE()
@@ -392,161 +408,160 @@
392408
* @brief A namespace for the logging library.
393409
*/
394410
namespace olp {
395-
namespace logging {
396-
class Configuration;
397-
class FilterGroup;
398-
399-
/**
400-
* @brief Used for disabled logs at compile time.
401-
*/
402-
class NullLogStream {
403-
public:
404-
template <typename T>
405-
406-
/**
407-
* @brief The stream operator to print or serialize the given log stream.
408-
*/
409-
NullLogStream& operator<<(const T&) {
410-
return *this;
411-
}
412-
};
413-
414-
/**
415-
* @brief A primary interface for log messages.
416-
*/
417-
class CORE_API Log {
418-
public:
419-
/**
420-
* @brief Configures the log system.
421-
*
422-
* It overrides the previous configuration.
423-
*
424-
* @return False if the configuration is invalid.
425-
* The configuration does not change in this case.
426-
*/
427-
static bool configure(Configuration configuration);
428-
429-
/**
430-
* @brief Gets a copy of the current configuration.
431-
*
432-
* Use it to add an appender and reconfigure the system.
433-
*
434-
* @return A copy of the current configuration.
435-
*/
436-
static Configuration getConfiguration();
437-
438-
/**
439-
* @brief Sets the default log level.
440-
*
441-
* No messages below this level are displayed unless overridden by
442-
* specific log tags.
443-
*
444-
* @param level The log level.
445-
*/
446-
static void setLevel(Level level);
447-
448-
/**
449-
* @brief Gets the default log level.
450-
*
451-
* @return The log level.
452-
*/
453-
static Level getLevel();
454-
455-
/**
456-
* @brief Sets the log level for a tag.
457-
*
458-
* It overrides the default configurations.
459-
*
460-
* @param level The log level.
461-
* @param tag The tag for the log component. If empty, it sets the
462-
* default level.
463-
*/
464-
static void setLevel(Level level, const std::string& tag);
465-
466-
/**
467-
* @brief Sets the log level for a tag.
468-
*
469-
* It overrides the default configurations.
470-
*
471-
* @param level The log level.
472-
* @param tag The tag for the log component. If empty, it sets the
473-
* default level.
474-
*/
475-
static void setLevel(const std::string& level, const std::string& tag);
476-
477-
/**
478-
* @brief Gets the log level for a tag.
479-
*
480-
* @param tag The tag for the log component. If empty, it sets the
481-
* default level.
482-
*
483-
* @return The log level for the tag or `core::None` if the log level is unset.
484-
*/
485-
static boost::optional<Level> getLevel(const std::string& tag);
486-
487-
/**
488-
* @brief Clears the log level for a tag and sets it to
489-
* the default value.
490-
*
491-
* @param tag The tag for the log component.
492-
*/
493-
static void clearLevel(const std::string& tag);
494-
495-
/**
496-
* @brief Clears the log levels for all tags and sets them to
497-
* the default value.
498-
*/
499-
static void clearLevels();
500-
501-
/**
502-
* @brief Applies a filter group.
503-
*
504-
* It clears all the log levels for tags and replaces them
505-
* with the levels set in the filter group. If the default log level is set in
506-
* the filter group, it is also applied.
507-
*
508-
* @param filters The filter group to apply.
509-
*/
510-
static void applyFilterGroup(const FilterGroup& filters);
511-
512-
/**
513-
* @brief Checks whether a level is enabled by default.
514-
*
515-
* @param level The log level.
516-
*
517-
* @return True if the log is enabled; false otherwise.
518-
*/
519-
static bool isEnabled(Level level);
520-
521-
/**
522-
* @brief Checks whether a log tag is enabled for a level.
523-
*
524-
* @param tag The tag for the log component.
525-
* @param level The log level.
526-
*
527-
* @return True if the log is enabled; false otherwise.
528-
*/
529-
static bool isEnabled(Level level, const std::string& tag);
530-
531-
/**
532-
* @brief Logs a message to the registered appenders.
533-
*
534-
* Outputting to the appender depends on whether
535-
* the appender is enabled for this level.
536-
*
537-
* @param level The log level.
538-
* @param tag The tag for the log component.
539-
* @param message The log message.
540-
* @param file The file that generated the message.
541-
* @param line The line in the file where the message was logged.
542-
* @param function The function that generated the message.
543-
* @param fullFunction The fully qualified function that generated the message.
544-
*/
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);
549-
};
550-
551-
} // namespace logging
552-
} // namespace olp
411+
namespace logging {
412+
class Configuration;
413+
class FilterGroup;
414+
415+
/**
416+
* @brief Used for disabled logs at compile time.
417+
*/
418+
class NullLogStream {
419+
public:
420+
template<typename T>
421+
422+
/**
423+
* @brief The stream operator to print or serialize the given log stream.
424+
*/
425+
NullLogStream &operator<<(const T &) {
426+
return *this;
427+
}
428+
};
429+
430+
/**
431+
* @brief A primary interface for log messages.
432+
*/
433+
class CORE_API Log {
434+
public:
435+
/**
436+
* @brief Configures the log system.
437+
*
438+
* It overrides the previous configuration.
439+
*
440+
* @return False if the configuration is invalid.
441+
* The configuration does not change in this case.
442+
*/
443+
static bool configure(Configuration configuration);
444+
445+
/**
446+
* @brief Gets a copy of the current configuration.
447+
*
448+
* Use it to add an appender and reconfigure the system.
449+
*
450+
* @return A copy of the current configuration.
451+
*/
452+
static Configuration getConfiguration();
453+
454+
/**
455+
* @brief Sets the default log level.
456+
*
457+
* No messages below this level are displayed unless overridden by
458+
* specific log tags.
459+
*
460+
* @param level The log level.
461+
*/
462+
static void setLevel(Level level);
463+
464+
/**
465+
* @brief Gets the default log level.
466+
*
467+
* @return The log level.
468+
*/
469+
static Level getLevel();
470+
471+
/**
472+
* @brief Sets the log level for a tag.
473+
*
474+
* It overrides the default configurations.
475+
*
476+
* @param level The log level.
477+
* @param tag The tag for the log component. If empty, it sets the
478+
* default level.
479+
*/
480+
static void setLevel(Level level, const std::string &tag);
481+
482+
/**
483+
* @brief Sets the log level for a tag.
484+
*
485+
* It overrides the default configurations.
486+
*
487+
* @param level The log level.
488+
* @param tag The tag for the log component. If empty, it sets the
489+
* default level.
490+
*/
491+
static void setLevel(const std::string &level, const std::string &tag);
492+
493+
/**
494+
* @brief Gets the log level for a tag.
495+
*
496+
* @param tag The tag for the log component. If empty, it sets the
497+
* default level.
498+
*
499+
* @return The log level for the tag or `core::None` if the log level is unset.
500+
*/
501+
static boost::optional<Level> getLevel(const std::string &tag);
502+
503+
/**
504+
* @brief Clears the log level for a tag and sets it to
505+
* the default value.
506+
*
507+
* @param tag The tag for the log component.
508+
*/
509+
static void clearLevel(const std::string &tag);
510+
511+
/**
512+
* @brief Clears the log levels for all tags and sets them to
513+
* the default value.
514+
*/
515+
static void clearLevels();
516+
517+
/**
518+
* @brief Applies a filter group.
519+
*
520+
* It clears all the log levels for tags and replaces them
521+
* with the levels set in the filter group. If the default log level is set in
522+
* the filter group, it is also applied.
523+
*
524+
* @param filters The filter group to apply.
525+
*/
526+
static void applyFilterGroup(const FilterGroup &filters);
527+
528+
/**
529+
* @brief Checks whether a level is enabled by default.
530+
*
531+
* @param level The log level.
532+
*
533+
* @return True if the log is enabled; false otherwise.
534+
*/
535+
static bool isEnabled(Level level);
536+
537+
/**
538+
* @brief Checks whether a log tag is enabled for a level.
539+
*
540+
* @param tag The tag for the log component.
541+
* @param level The log level.
542+
*
543+
* @return True if the log is enabled; false otherwise.
544+
*/
545+
static bool isEnabled(Level level, const std::string &tag);
546+
547+
/**
548+
* @brief Logs a message to the registered appenders.
549+
*
550+
* Outputting to the appender depends on whether
551+
* the appender is enabled for this level.
552+
*
553+
* @param level The log level.
554+
* @param tag The tag for the log component.
555+
* @param message The log message.
556+
* @param file The file that generated the message.
557+
* @param line The line in the file where the message was logged.
558+
* @param function The function that generated the message.
559+
* @param fullFunction The fully qualified function that generated the message.
560+
*/
561+
static void logMessage(Level level, const std::string &tag,
562+
const std::string &message, const char *file,
563+
unsigned int line, const char *function,
564+
const char *fullFunction);
565+
};
566+
} // namespace logging
567+
} // namespace olp

0 commit comments

Comments
 (0)