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 |
111 namespace internal { | 117 namespace internal { |
| 118 |
112 #if defined(__ANDROID__) | 119 #if defined(__ANDROID__) |
113 inline void DefaultLogHandler(LogLevel level, const char* filename, int line, | 120 inline void DefaultLogHandler(LogLevel level, const char* filename, int line, |
114 const string& message) { | 121 const string& message) { |
115 #ifdef GOOGLE_PROTOBUF_MIN_LOG_LEVEL | |
116 if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { | 122 if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { |
117 return; | 123 return; |
118 } | 124 } |
119 static const char* level_names[] = {"INFO", "WARNING", "ERROR", "FATAL"}; | 125 static const char* level_names[] = {"INFO", "WARNING", "ERROR", "FATAL"}; |
120 | 126 |
121 static const int android_log_levels[] = { | 127 static const int android_log_levels[] = { |
122 ANDROID_LOG_INFO, // LOG(INFO), | 128 ANDROID_LOG_INFO, // LOG(INFO), |
123 ANDROID_LOG_WARN, // LOG(WARNING) | 129 ANDROID_LOG_WARN, // LOG(WARNING) |
124 ANDROID_LOG_ERROR, // LOG(ERROR) | 130 ANDROID_LOG_ERROR, // LOG(ERROR) |
125 ANDROID_LOG_FATAL, // LOG(FATAL) | 131 ANDROID_LOG_FATAL, // LOG(FATAL) |
(...skipping 10 matching lines...) Expand all Loading... |
136 ostr.str().c_str()); | 142 ostr.str().c_str()); |
137 // Also output to std::cerr. | 143 // Also output to std::cerr. |
138 fprintf(stderr, "%s", ostr.str().c_str()); | 144 fprintf(stderr, "%s", ostr.str().c_str()); |
139 fflush(stderr); | 145 fflush(stderr); |
140 | 146 |
141 // Indicate termination if needed. | 147 // Indicate termination if needed. |
142 if (android_log_level == ANDROID_LOG_FATAL) { | 148 if (android_log_level == ANDROID_LOG_FATAL) { |
143 __android_log_write(ANDROID_LOG_FATAL, "libprotobuf-native", | 149 __android_log_write(ANDROID_LOG_FATAL, "libprotobuf-native", |
144 "terminating.\n"); | 150 "terminating.\n"); |
145 } | 151 } |
146 #endif | |
147 } | 152 } |
| 153 |
148 #else | 154 #else |
149 void DefaultLogHandler(LogLevel level, const char* filename, int line, | 155 void DefaultLogHandler(LogLevel level, const char* filename, int line, |
150 const string& message) { | 156 const string& message) { |
| 157 if (level < GOOGLE_PROTOBUF_MIN_LOG_LEVEL) { |
| 158 return; |
| 159 } |
151 static const char* level_names[] = { "INFO", "WARNING", "ERROR", "FATAL" }; | 160 static const char* level_names[] = { "INFO", "WARNING", "ERROR", "FATAL" }; |
152 | 161 |
153 // We use fprintf() instead of cerr because we want this to work at static | 162 // We use fprintf() instead of cerr because we want this to work at static |
154 // initialization time. | 163 // initialization time. |
155 fprintf(stderr, "[libprotobuf %s %s:%d] %s\n", | 164 fprintf(stderr, "[libprotobuf %s %s:%d] %s\n", |
156 level_names[level], filename, line, message.c_str()); | 165 level_names[level], filename, line, message.c_str()); |
157 fflush(stderr); // Needed on MSVC. | 166 fflush(stderr); // Needed on MSVC. |
158 } | 167 } |
159 #endif | 168 #endif |
160 | 169 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 #if PROTOBUF_USE_EXCEPTIONS | 459 #if PROTOBUF_USE_EXCEPTIONS |
451 FatalException::~FatalException() throw() {} | 460 FatalException::~FatalException() throw() {} |
452 | 461 |
453 const char* FatalException::what() const throw() { | 462 const char* FatalException::what() const throw() { |
454 return message_.c_str(); | 463 return message_.c_str(); |
455 } | 464 } |
456 #endif | 465 #endif |
457 | 466 |
458 } // namespace protobuf | 467 } // namespace protobuf |
459 } // namespace google | 468 } // namespace google |
OLD | NEW |