| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 24 matching lines...) Expand all Loading... |
| 35 typedef pthread_mutex_t* MutexHandle; | 35 typedef pthread_mutex_t* MutexHandle; |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 #include <ctime> | 38 #include <ctime> |
| 39 #include <iomanip> | 39 #include <iomanip> |
| 40 #include <cstring> | 40 #include <cstring> |
| 41 #include <algorithm> | 41 #include <algorithm> |
| 42 | 42 |
| 43 #include "base/base_switches.h" | 43 #include "base/base_switches.h" |
| 44 #include "base/command_line.h" | 44 #include "base/command_line.h" |
| 45 #include "base/debug_util.h" | 45 #include "base/debug/debugger.h" |
| 46 #include "base/debug/stack_trace.h" |
| 46 #include "base/eintr_wrapper.h" | 47 #include "base/eintr_wrapper.h" |
| 47 #include "base/lock_impl.h" | 48 #include "base/lock_impl.h" |
| 48 #if defined(OS_POSIX) | 49 #if defined(OS_POSIX) |
| 49 #include "base/safe_strerror_posix.h" | 50 #include "base/safe_strerror_posix.h" |
| 50 #endif | 51 #endif |
| 51 #include "base/process_util.h" | 52 #include "base/process_util.h" |
| 52 #include "base/string_piece.h" | 53 #include "base/string_piece.h" |
| 53 #include "base/utf_string_conversions.h" | 54 #include "base/utf_string_conversions.h" |
| 54 #include "base/vlog.h" | 55 #include "base/vlog.h" |
| 55 | 56 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // \ is not a legal character in mutex names so we replace \ with / | 214 // \ is not a legal character in mutex names so we replace \ with / |
| 214 std::replace(safe_name.begin(), safe_name.end(), '\\', '/'); | 215 std::replace(safe_name.begin(), safe_name.end(), '\\', '/'); |
| 215 std::wstring t(L"Global\\"); | 216 std::wstring t(L"Global\\"); |
| 216 t.append(safe_name); | 217 t.append(safe_name); |
| 217 log_mutex = ::CreateMutex(NULL, FALSE, t.c_str()); | 218 log_mutex = ::CreateMutex(NULL, FALSE, t.c_str()); |
| 218 | 219 |
| 219 if (log_mutex == NULL) { | 220 if (log_mutex == NULL) { |
| 220 #if DEBUG | 221 #if DEBUG |
| 221 // Keep the error code for debugging | 222 // Keep the error code for debugging |
| 222 int error = GetLastError(); // NOLINT | 223 int error = GetLastError(); // NOLINT |
| 223 DebugUtil::BreakDebugger(); | 224 base::debug::BreakDebugger(); |
| 224 #endif | 225 #endif |
| 225 // Return nicely without putting initialized to true. | 226 // Return nicely without putting initialized to true. |
| 226 return; | 227 return; |
| 227 } | 228 } |
| 228 } | 229 } |
| 229 #endif | 230 #endif |
| 230 } else { | 231 } else { |
| 231 log_lock = new LockImpl(); | 232 log_lock = new LockImpl(); |
| 232 } | 233 } |
| 233 initialized = true; | 234 initialized = true; |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 LogMessage::~LogMessage() { | 574 LogMessage::~LogMessage() { |
| 574 // The macros in logging.h should already avoid creating LogMessages | 575 // The macros in logging.h should already avoid creating LogMessages |
| 575 // when this holds, but it's possible that users create LogMessages | 576 // when this holds, but it's possible that users create LogMessages |
| 576 // directly (e.g., using LOG_STREAM() directly). | 577 // directly (e.g., using LOG_STREAM() directly). |
| 577 if (severity_ < min_log_level) | 578 if (severity_ < min_log_level) |
| 578 return; | 579 return; |
| 579 | 580 |
| 580 #ifndef NDEBUG | 581 #ifndef NDEBUG |
| 581 if (severity_ == LOG_FATAL) { | 582 if (severity_ == LOG_FATAL) { |
| 582 // Include a stack trace on a fatal. | 583 // Include a stack trace on a fatal. |
| 583 StackTrace trace; | 584 base::debug::StackTrace trace; |
| 584 stream_ << std::endl; // Newline to separate from log message. | 585 stream_ << std::endl; // Newline to separate from log message. |
| 585 trace.OutputToStream(&stream_); | 586 trace.OutputToStream(&stream_); |
| 586 } | 587 } |
| 587 #endif | 588 #endif |
| 588 stream_ << std::endl; | 589 stream_ << std::endl; |
| 589 std::string str_newline(stream_.str()); | 590 std::string str_newline(stream_.str()); |
| 590 | 591 |
| 591 // Give any log message handler first dibs on the message. | 592 // Give any log message handler first dibs on the message. |
| 592 if (log_message_handler && log_message_handler(severity_, str_newline)) | 593 if (log_message_handler && log_message_handler(severity_, str_newline)) |
| 593 return; | 594 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 NULL); | 631 NULL); |
| 631 #else | 632 #else |
| 632 fprintf(log_file, "%s", str_newline.c_str()); | 633 fprintf(log_file, "%s", str_newline.c_str()); |
| 633 fflush(log_file); | 634 fflush(log_file); |
| 634 #endif | 635 #endif |
| 635 } | 636 } |
| 636 } | 637 } |
| 637 | 638 |
| 638 if (severity_ == LOG_FATAL) { | 639 if (severity_ == LOG_FATAL) { |
| 639 // display a message or break into the debugger on a fatal error | 640 // display a message or break into the debugger on a fatal error |
| 640 if (DebugUtil::BeingDebugged()) { | 641 if (base::debug::BeingDebugged()) { |
| 641 DebugUtil::BreakDebugger(); | 642 base::debug::BreakDebugger(); |
| 642 } else { | 643 } else { |
| 643 if (log_assert_handler) { | 644 if (log_assert_handler) { |
| 644 // make a copy of the string for the handler out of paranoia | 645 // make a copy of the string for the handler out of paranoia |
| 645 log_assert_handler(std::string(stream_.str())); | 646 log_assert_handler(std::string(stream_.str())); |
| 646 } else { | 647 } else { |
| 647 // Don't use the string with the newline, get a fresh version to send to | 648 // Don't use the string with the newline, get a fresh version to send to |
| 648 // the debug message process. We also don't display assertions to the | 649 // the debug message process. We also don't display assertions to the |
| 649 // user in release mode. The enduser can't do anything with this | 650 // user in release mode. The enduser can't do anything with this |
| 650 // information, and displaying message boxes when the application is | 651 // information, and displaying message boxes when the application is |
| 651 // hosed can cause additional problems. | 652 // hosed can cause additional problems. |
| 652 #ifndef NDEBUG | 653 #ifndef NDEBUG |
| 653 DisplayDebugMessageInDialog(stream_.str()); | 654 DisplayDebugMessageInDialog(stream_.str()); |
| 654 #endif | 655 #endif |
| 655 // Crash the process to generate a dump. | 656 // Crash the process to generate a dump. |
| 656 DebugUtil::BreakDebugger(); | 657 base::debug::BreakDebugger(); |
| 657 } | 658 } |
| 658 } | 659 } |
| 659 } else if (severity_ == LOG_ERROR_REPORT) { | 660 } else if (severity_ == LOG_ERROR_REPORT) { |
| 660 // We are here only if the user runs with --enable-dcheck in release mode. | 661 // We are here only if the user runs with --enable-dcheck in release mode. |
| 661 if (log_report_handler) { | 662 if (log_report_handler) { |
| 662 log_report_handler(std::string(stream_.str())); | 663 log_report_handler(std::string(stream_.str())); |
| 663 } else { | 664 } else { |
| 664 DisplayDebugMessageInDialog(stream_.str()); | 665 DisplayDebugMessageInDialog(stream_.str()); |
| 665 } | 666 } |
| 666 } | 667 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 rv = HANDLE_EINTR(write(STDERR_FILENO, "\n", 1)); | 786 rv = HANDLE_EINTR(write(STDERR_FILENO, "\n", 1)); |
| 786 if (rv < 0) { | 787 if (rv < 0) { |
| 787 // Give up, nothing we can do now. | 788 // Give up, nothing we can do now. |
| 788 break; | 789 break; |
| 789 } | 790 } |
| 790 } while (rv != 1); | 791 } while (rv != 1); |
| 791 } | 792 } |
| 792 } | 793 } |
| 793 | 794 |
| 794 if (level == LOG_FATAL) | 795 if (level == LOG_FATAL) |
| 795 DebugUtil::BreakDebugger(); | 796 base::debug::BreakDebugger(); |
| 796 } | 797 } |
| 797 | 798 |
| 798 } // namespace logging | 799 } // namespace logging |
| 799 | 800 |
| 800 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { | 801 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { |
| 801 return out << WideToUTF8(std::wstring(wstr)); | 802 return out << WideToUTF8(std::wstring(wstr)); |
| 802 } | 803 } |
| OLD | NEW |