Skip to content

Commit

Permalink
build(log): add cmake option ALSO_LOG_TO_STDERR
Browse files Browse the repository at this point in the history
allow turning on/off glog's alsologtostderr flag in custom build.
by default OFF in release build, ON in debug build.

Fixes #799
  • Loading branch information
lotem committed Feb 8, 2024
1 parent 8709a7a commit 36eb14c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ option(BUILD_SAMPLE "Build sample Rime plugin" OFF)
option(BUILD_TEST "Build and run tests" ON)
option(BUILD_SEPARATE_LIBS "Build separate rime-* libraries" OFF)
option(ENABLE_LOGGING "Enable logging with google-glog library" ON)
option(ALSO_LOG_TO_STDERR "Log to stderr as well as log file" OFF)
option(ENABLE_ASAN "Enable Address Sanitizer (Unix Only)" OFF)
option(INSTALL_PRIVATE_HEADERS "Install private headers (usually needed for externally built Rime plugins)" OFF)
option(ENABLE_EXTERNAL_PLUGINS "Enable loading of externally built Rime plugins (from directory set by RIME_PLUGINS_DIR variable)" OFF)
Expand Down Expand Up @@ -86,6 +87,9 @@ if(ENABLE_LOGGING)

set(RIME_ENABLE_LOGGING 1)

if (ALSO_LOG_TO_STDERR)
set(RIME_ALSO_LOG_TO_STDERR 1)
endif()
endif()

find_package(Threads)
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ debug:
-DCMAKE_INSTALL_PREFIX=$(prefix) \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_MERGED_PLUGINS=OFF \
-DALSO_LOG_TO_STDERR=ON \
-DENABLE_EXTERNAL_PLUGINS=ON
cmake --build $(build)

Expand Down
1 change: 1 addition & 0 deletions src/rime/build_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define RIME_BUILD_CONFIG_H_

#cmakedefine RIME_ENABLE_LOGGING
#cmakedefine RIME_ALSO_LOG_TO_STDERR

#cmakedefine RIME_DATA_DIR "@RIME_DATA_DIR@"
#cmakedefine RIME_PLUGINS_DIR "@RIME_PLUGINS_DIR@"
Expand Down
2 changes: 2 additions & 0 deletions src/rime/setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ RIME_API void SetupLogging(const char* app_name,
const char* log_dir) {
#ifdef RIME_ENABLE_LOGGING
FLAGS_minloglevel = min_log_level;
#ifdef RIME_ALSO_LOG_TO_STDERR
FLAGS_alsologtostderr = true;
#endif // RIME_ALSO_LOG_TO_STDERR
if (log_dir) {
if (log_dir[0] == '\0') {
google::LogToStderr();
Expand Down

0 comments on commit 36eb14c

Please sign in to comment.