diff options
author | Adam Cozzette <acozzette@google.com> | 2016-12-07 14:34:37 -0800 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2016-12-07 14:34:37 -0800 |
commit | 2f29f0ae090ca8633ba1b81e8b22333ef091411c (patch) | |
tree | 2d035d64c5e323b7e8c14d183a0a71fc26985ab3 | |
parent | 057389cae36b0fedab240a2c05885f860efe6c37 (diff) | |
download | protobuf-2f29f0ae090ca8633ba1b81e8b22333ef091411c.tar.gz protobuf-2f29f0ae090ca8633ba1b81e8b22333ef091411c.tar.bz2 protobuf-2f29f0ae090ca8633ba1b81e8b22333ef091411c.zip |
Send all protobuf logging to logcat by default on Android
Currently the default for protobuf on Android is to silently drop all log
messages. This makes debugging difficult because things like GOOGLE_LOG(FATAL)
will crash the process without actually logging a useful error.
This CL changes the logging so that by default we send messages for all log
levels to logcat (and stderr). Users can override this by setting
GOOGLE_PROTOBUF_MIN_LOG_LEVEL. Also, that option was not being respected for
non-Android platforms so I went ahead and fixed that to make things consistent.
-rw-r--r-- | src/google/protobuf/stubs/common.cc | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc index 54dbafab..14655916 100644 --- a/src/google/protobuf/stubs/common.cc +++ b/src/google/protobuf/stubs/common.cc @@ -108,11 +108,17 @@ string VersionString(int version) { // =================================================================== // emulates google3/base/logging.cc +// If the minimum logging level is not set, we default to logging messages for +// all levels. +#ifndef GOOGLE_PROTOBUF_MIN_LOG_LEVEL +#define GOOGLE_PROTOBUF_MIN_LOG_LEVEL LOGLEVEL_INFO +#endif + namespace internal { + #if defined(__ANDROID__) inline void DefaultLogHandler(LogLevel level, const char* filename, int line, const string& message) { -#ifdef GOOGLE_PROTOBUF_MIN_LOG_LEVEL if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { return; } @@ -143,11 +149,14 @@ inline void DefaultLogHandler(LogLevel level, const char* filename, int line, __android_log_write(ANDROID_LOG_FATAL, "libprotobuf-native", "terminating.\n"); } -#endif } + #else void DefaultLogHandler(LogLevel level, const char* filename, int line, const string& message) { + if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { + return; + } static const char* level_names[] = { "INFO", "WARNING", "ERROR", "FATAL" }; // We use fprintf() instead of cerr because we want this to work at static |