OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/logging.h" | 5 #include "base/logging.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <io.h> | 8 #include <io.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 typedef HANDLE FileHandle; | 10 typedef HANDLE FileHandle; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "base/debug/stack_trace.h" | 51 #include "base/debug/stack_trace.h" |
52 #include "base/eintr_wrapper.h" | 52 #include "base/eintr_wrapper.h" |
53 #include "base/string_piece.h" | 53 #include "base/string_piece.h" |
54 #include "base/synchronization/lock_impl.h" | 54 #include "base/synchronization/lock_impl.h" |
55 #include "base/utf_string_conversions.h" | 55 #include "base/utf_string_conversions.h" |
56 #include "base/vlog.h" | 56 #include "base/vlog.h" |
57 #if defined(OS_POSIX) | 57 #if defined(OS_POSIX) |
58 #include "base/safe_strerror_posix.h" | 58 #include "base/safe_strerror_posix.h" |
59 #endif | 59 #endif |
60 | 60 |
| 61 #if defined(OS_ANDROID) |
| 62 #include <android/log.h> |
| 63 #endif |
| 64 |
61 namespace logging { | 65 namespace logging { |
62 | 66 |
63 DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; | 67 DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; |
64 VlogInfo* g_vlog_info = NULL; | 68 VlogInfo* g_vlog_info = NULL; |
65 | 69 |
66 const char* const log_severity_names[LOG_NUM_SEVERITIES] = { | 70 const char* const log_severity_names[LOG_NUM_SEVERITIES] = { |
67 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" }; | 71 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" }; |
68 | 72 |
69 int min_log_level = 0; | 73 int min_log_level = 0; |
70 | 74 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 #endif | 126 #endif |
123 } | 127 } |
124 | 128 |
125 int32 CurrentThreadId() { | 129 int32 CurrentThreadId() { |
126 #if defined(OS_WIN) | 130 #if defined(OS_WIN) |
127 return GetCurrentThreadId(); | 131 return GetCurrentThreadId(); |
128 #elif defined(OS_MACOSX) | 132 #elif defined(OS_MACOSX) |
129 return mach_thread_self(); | 133 return mach_thread_self(); |
130 #elif defined(OS_LINUX) | 134 #elif defined(OS_LINUX) |
131 return syscall(__NR_gettid); | 135 return syscall(__NR_gettid); |
| 136 #elif defined(OS_ANDROID) |
| 137 return gettid(); |
132 #elif defined(OS_FREEBSD) | 138 #elif defined(OS_FREEBSD) |
133 // TODO(BSD): find a better thread ID | 139 // TODO(BSD): find a better thread ID |
134 return reinterpret_cast<int64>(pthread_self()); | 140 return reinterpret_cast<int64>(pthread_self()); |
135 #elif defined(OS_NACL) | 141 #elif defined(OS_NACL) |
136 return pthread_self(); | 142 return pthread_self(); |
137 #endif | 143 #endif |
138 } | 144 } |
139 | 145 |
140 uint64 TickCount() { | 146 uint64 TickCount() { |
141 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 545 |
540 LogMessage::LogMessage(const char* file, int line, LogSeverity severity, | 546 LogMessage::LogMessage(const char* file, int line, LogSeverity severity, |
541 std::string* result) | 547 std::string* result) |
542 : severity_(severity), file_(file), line_(line) { | 548 : severity_(severity), file_(file), line_(line) { |
543 Init(file, line); | 549 Init(file, line); |
544 stream_ << "Check failed: " << *result; | 550 stream_ << "Check failed: " << *result; |
545 delete result; | 551 delete result; |
546 } | 552 } |
547 | 553 |
548 LogMessage::~LogMessage() { | 554 LogMessage::~LogMessage() { |
549 #ifndef NDEBUG | 555 // TODO(port): enable stacktrace generation on LOG_FATAL once backtrace are |
| 556 // working in Android. |
| 557 #if !defined(NDEBUG) && !defined(OS_ANDROID) |
550 if (severity_ == LOG_FATAL) { | 558 if (severity_ == LOG_FATAL) { |
551 // Include a stack trace on a fatal. | 559 // Include a stack trace on a fatal. |
552 base::debug::StackTrace trace; | 560 base::debug::StackTrace trace; |
553 stream_ << std::endl; // Newline to separate from log message. | 561 stream_ << std::endl; // Newline to separate from log message. |
554 trace.OutputToStream(&stream_); | 562 trace.OutputToStream(&stream_); |
555 } | 563 } |
556 #endif | 564 #endif |
557 stream_ << std::endl; | 565 stream_ << std::endl; |
558 std::string str_newline(stream_.str()); | 566 std::string str_newline(stream_.str()); |
559 | 567 |
560 // Give any log message handler first dibs on the message. | 568 // Give any log message handler first dibs on the message. |
561 if (log_message_handler && log_message_handler(severity_, file_, line_, | 569 if (log_message_handler && log_message_handler(severity_, file_, line_, |
562 message_start_, str_newline)) { | 570 message_start_, str_newline)) { |
563 // The handler took care of it, no further processing. | 571 // The handler took care of it, no further processing. |
564 return; | 572 return; |
565 } | 573 } |
566 | 574 |
567 if (logging_destination == LOG_ONLY_TO_SYSTEM_DEBUG_LOG || | 575 if (logging_destination == LOG_ONLY_TO_SYSTEM_DEBUG_LOG || |
568 logging_destination == LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG) { | 576 logging_destination == LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG) { |
569 #if defined(OS_WIN) | 577 #if defined(OS_WIN) |
570 OutputDebugStringA(str_newline.c_str()); | 578 OutputDebugStringA(str_newline.c_str()); |
| 579 #elif defined(OS_ANDROID) |
| 580 android_LogPriority priority = ANDROID_LOG_UNKNOWN; |
| 581 switch (severity_) { |
| 582 case LOG_INFO: |
| 583 priority = ANDROID_LOG_INFO; |
| 584 break; |
| 585 case LOG_WARNING: |
| 586 priority = ANDROID_LOG_WARN; |
| 587 break; |
| 588 case LOG_ERROR: |
| 589 case LOG_ERROR_REPORT: |
| 590 priority = ANDROID_LOG_ERROR; |
| 591 break; |
| 592 case LOG_FATAL: |
| 593 priority = ANDROID_LOG_FATAL; |
| 594 break; |
| 595 } |
| 596 __android_log_write(priority, "chromium", str_newline.c_str()); |
571 #endif | 597 #endif |
572 fprintf(stderr, "%s", str_newline.c_str()); | 598 fprintf(stderr, "%s", str_newline.c_str()); |
573 fflush(stderr); | 599 fflush(stderr); |
574 } else if (severity_ >= kAlwaysPrintErrorLevel) { | 600 } else if (severity_ >= kAlwaysPrintErrorLevel) { |
575 // When we're only outputting to a log file, above a certain log level, we | 601 // When we're only outputting to a log file, above a certain log level, we |
576 // should still output to stderr so that we can better detect and diagnose | 602 // should still output to stderr so that we can better detect and diagnose |
577 // problems with unit tests, especially on the buildbots. | 603 // problems with unit tests, especially on the buildbots. |
578 fprintf(stderr, "%s", str_newline.c_str()); | 604 fprintf(stderr, "%s", str_newline.c_str()); |
579 fflush(stderr); | 605 fflush(stderr); |
580 } | 606 } |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
821 | 847 |
822 // This was defined at the beginnig of this file. | 848 // This was defined at the beginnig of this file. |
823 #undef write | 849 #undef write |
824 | 850 |
825 std::ostream& operator<<(std::ostream& o, const StringPiece& piece) { | 851 std::ostream& operator<<(std::ostream& o, const StringPiece& piece) { |
826 o.write(piece.data(), static_cast<std::streamsize>(piece.size())); | 852 o.write(piece.data(), static_cast<std::streamsize>(piece.size())); |
827 return o; | 853 return o; |
828 } | 854 } |
829 | 855 |
830 } // namespace base | 856 } // namespace base |
OLD | NEW |