| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 buffer[sizeof(buffer)-1] = '\0'; | 101 buffer[sizeof(buffer)-1] = '\0'; |
| 102 | 102 |
| 103 return buffer; | 103 return buffer; |
| 104 } | 104 } |
| 105 | 105 |
| 106 } // namespace internal | 106 } // namespace internal |
| 107 | 107 |
| 108 // =================================================================== | 108 // =================================================================== |
| 109 // emulates google3/base/logging.cc | 109 // emulates google3/base/logging.cc |
| 110 | 110 |
| 111 // If the minimum logging level is not set, we default to logging messages for | |
| 112 // all levels. | |
| 113 #ifndef GOOGLE_PROTOBUF_MIN_LOG_LEVEL | |
| 114 #define GOOGLE_PROTOBUF_MIN_LOG_LEVEL LOGLEVEL_INFO | |
| 115 #endif | |
| 116 | |
| 117 namespace internal { | 111 namespace internal { |
| 118 | |
| 119 #if defined(__ANDROID__) | 112 #if defined(__ANDROID__) |
| 120 inline void DefaultLogHandler(LogLevel level, const char* filename, int line, | 113 inline void DefaultLogHandler(LogLevel level, const char* filename, int line, |
| 121 const string& message) { | 114 const string& message) { |
| 115 #ifdef GOOGLE_PROTOBUF_MIN_LOG_LEVEL |
| 122 if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { | 116 if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { |
| 123 return; | 117 return; |
| 124 } | 118 } |
| 125 static const char* level_names[] = {"INFO", "WARNING", "ERROR", "FATAL"}; | 119 static const char* level_names[] = {"INFO", "WARNING", "ERROR", "FATAL"}; |
| 126 | 120 |
| 127 static const int android_log_levels[] = { | 121 static const int android_log_levels[] = { |
| 128 ANDROID_LOG_INFO, // LOG(INFO), | 122 ANDROID_LOG_INFO, // LOG(INFO), |
| 129 ANDROID_LOG_WARN, // LOG(WARNING) | 123 ANDROID_LOG_WARN, // LOG(WARNING) |
| 130 ANDROID_LOG_ERROR, // LOG(ERROR) | 124 ANDROID_LOG_ERROR, // LOG(ERROR) |
| 131 ANDROID_LOG_FATAL, // LOG(FATAL) | 125 ANDROID_LOG_FATAL, // LOG(FATAL) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 142 ostr.str().c_str()); | 136 ostr.str().c_str()); |
| 143 // Also output to std::cerr. | 137 // Also output to std::cerr. |
| 144 fprintf(stderr, "%s", ostr.str().c_str()); | 138 fprintf(stderr, "%s", ostr.str().c_str()); |
| 145 fflush(stderr); | 139 fflush(stderr); |
| 146 | 140 |
| 147 // Indicate termination if needed. | 141 // Indicate termination if needed. |
| 148 if (android_log_level == ANDROID_LOG_FATAL) { | 142 if (android_log_level == ANDROID_LOG_FATAL) { |
| 149 __android_log_write(ANDROID_LOG_FATAL, "libprotobuf-native", | 143 __android_log_write(ANDROID_LOG_FATAL, "libprotobuf-native", |
| 150 "terminating.\n"); | 144 "terminating.\n"); |
| 151 } | 145 } |
| 146 #endif |
| 152 } | 147 } |
| 153 | |
| 154 #else | 148 #else |
| 155 void DefaultLogHandler(LogLevel level, const char* filename, int line, | 149 void DefaultLogHandler(LogLevel level, const char* filename, int line, |
| 156 const string& message) { | 150 const string& message) { |
| 157 if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { | |
| 158 return; | |
| 159 } | |
| 160 static const char* level_names[] = { "INFO", "WARNING", "ERROR", "FATAL" }; | 151 static const char* level_names[] = { "INFO", "WARNING", "ERROR", "FATAL" }; |
| 161 | 152 |
| 162 // We use fprintf() instead of cerr because we want this to work at static | 153 // We use fprintf() instead of cerr because we want this to work at static |
| 163 // initialization time. | 154 // initialization time. |
| 164 fprintf(stderr, "[libprotobuf %s %s:%d] %s\n", | 155 fprintf(stderr, "[libprotobuf %s %s:%d] %s\n", |
| 165 level_names[level], filename, line, message.c_str()); | 156 level_names[level], filename, line, message.c_str()); |
| 166 fflush(stderr); // Needed on MSVC. | 157 fflush(stderr); // Needed on MSVC. |
| 167 } | 158 } |
| 168 #endif | 159 #endif |
| 169 | 160 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 #if PROTOBUF_USE_EXCEPTIONS | 450 #if PROTOBUF_USE_EXCEPTIONS |
| 460 FatalException::~FatalException() throw() {} | 451 FatalException::~FatalException() throw() {} |
| 461 | 452 |
| 462 const char* FatalException::what() const throw() { | 453 const char* FatalException::what() const throw() { |
| 463 return message_.c_str(); | 454 return message_.c_str(); |
| 464 } | 455 } |
| 465 #endif | 456 #endif |
| 466 | 457 |
| 467 } // namespace protobuf | 458 } // namespace protobuf |
| 468 } // namespace google | 459 } // namespace google |
| OLD | NEW |