Chromium Code Reviews| Index: src/client/linux/log/log.cc |
| diff --git a/src/client/linux/log/log.cc b/src/client/linux/log/log.cc |
| index 186359139054177f85239d4a1e94304042c5fcbf..3b8f3b2a634b87d285bebcea684773c69bd84e46 100644 |
| --- a/src/client/linux/log/log.cc |
| +++ b/src/client/linux/log/log.cc |
| @@ -31,6 +31,12 @@ |
| #if defined(__ANDROID__) |
| #include <android/log.h> |
| +#include <dlfcn.h> |
| + |
| +// From Android system/core/include/log/log.h |
|
Lei Zhang
2015/08/13 21:07:57
Might be good to mention __android_log_buf_write()
Lei Zhang
2015/08/13 21:07:57
nit: Move these out of a #if block for #includes.
Primiano Tucci (use gerrit)
2015/08/14 09:16:45
Done.
Primiano Tucci (use gerrit)
2015/08/14 09:16:46
Moved below in the anonymous namespace
Primiano Tucci (use gerrit)
2015/08/14 09:16:46
Done.
|
| +using AndroidLogBufferWriteFunc = int (*)(int bufID, int prio, const char *tag, |
| + const char *text); |
| +static const char kAndroidLogTag[] = "google-breakpad"; |
| #else |
| #include "third_party/lss/linux_syscall_support.h" |
| #endif |
| @@ -39,10 +45,36 @@ namespace logger { |
| int write(const char* buf, size_t nbytes) { |
| #if defined(__ANDROID__) |
| - return __android_log_write(ANDROID_LOG_WARN, "google-breakpad", buf); |
| + return __android_log_write(ANDROID_LOG_WARN, kAndroidLogTag, buf); |
| #else |
| return sys_write(2, buf, nbytes); |
| #endif |
| } |
| +#if defined(__ANDROID__) |
| +namespace { |
|
Lei Zhang
2015/08/13 21:07:57
nit: blank lines after the start of the namespace
Primiano Tucci (use gerrit)
2015/08/14 09:16:45
Done.
|
| +bool g_crash_log_initialized = false; |
| +AndroidLogBufferWriteFunc g_android_log_buf_write = nullptr; |
| +} // namespace |
| + |
| +void initializeCrashLogWriter() { |
| + if (g_crash_log_initialized) |
| + return; |
| + g_android_log_buf_write = reinterpret_cast<AndroidLogBufferWriteFunc>( |
| + dlsym(RTLD_DEFAULT, "__android_log_buf_write")); |
| + g_crash_log_initialized = true; |
| +} |
| + |
| +int writeToCrashLog(const char* buf) { |
| + // Try writing to the crash log ring buffer. If not available, fall back using |
|
Lei Zhang
2015/08/13 21:07:57
nit: "fall back to" parses slightly better in my m
Primiano Tucci (use gerrit)
2015/08/14 09:16:45
Done.
|
| + // the standard log buffer. |
| + if (g_crash_log_initialized && g_android_log_buf_write) { |
|
Lei Zhang
2015/08/13 21:07:57
Do you really need to check |g_crash_log_initializ
Primiano Tucci (use gerrit)
2015/08/14 09:16:45
Nah not really. Done.
|
| + const int kAndroidCrashLogId = 4; |
|
Lei Zhang
2015/08/13 21:07:57
Where did this magical value come from? Add a comm
Primiano Tucci (use gerrit)
2015/08/14 09:16:46
Done.
|
| + return g_android_log_buf_write(kAndroidCrashLogId, ANDROID_LOG_FATAL, |
| + kAndroidLogTag, buf); |
| + } |
| + return __android_log_write(ANDROID_LOG_FATAL, kAndroidLogTag, buf); |
| +} |
| +#endif |
| + |
| } // namespace logger |