Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: base/logging.cc

Issue 331143007: Remove the LOG_ERROR_REPORT log severity level. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: missed a SetLogReportHandler; also removed the --silent-dump-on-dcheck flag Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/logging.h ('k') | base/logging_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #endif 67 #endif
68 68
69 namespace logging { 69 namespace logging {
70 70
71 namespace { 71 namespace {
72 72
73 VlogInfo* g_vlog_info = NULL; 73 VlogInfo* g_vlog_info = NULL;
74 VlogInfo* g_vlog_info_prev = NULL; 74 VlogInfo* g_vlog_info_prev = NULL;
75 75
76 const char* const log_severity_names[LOG_NUM_SEVERITIES] = { 76 const char* const log_severity_names[LOG_NUM_SEVERITIES] = {
77 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" }; 77 "INFO", "WARNING", "ERROR", "FATAL" };
78 78
79 const char* log_severity_name(int severity) 79 const char* log_severity_name(int severity)
80 { 80 {
81 if (severity >= 0 && severity < LOG_NUM_SEVERITIES) 81 if (severity >= 0 && severity < LOG_NUM_SEVERITIES)
82 return log_severity_names[severity]; 82 return log_severity_names[severity];
83 return "UNKNOWN"; 83 return "UNKNOWN";
84 } 84 }
85 85
86 int min_log_level = 0; 86 int min_log_level = 0;
87 87
(...skipping 20 matching lines...) Expand all
108 bool log_thread_id = false; 108 bool log_thread_id = false;
109 bool log_timestamp = true; 109 bool log_timestamp = true;
110 bool log_tickcount = false; 110 bool log_tickcount = false;
111 111
112 // Should we pop up fatal debug messages in a dialog? 112 // Should we pop up fatal debug messages in a dialog?
113 bool show_error_dialogs = false; 113 bool show_error_dialogs = false;
114 114
115 // An assert handler override specified by the client to be called instead of 115 // An assert handler override specified by the client to be called instead of
116 // the debug message dialog and process termination. 116 // the debug message dialog and process termination.
117 LogAssertHandlerFunction log_assert_handler = NULL; 117 LogAssertHandlerFunction log_assert_handler = NULL;
118 // An report handler override specified by the client to be called instead of
119 // the debug message dialog.
120 LogReportHandlerFunction log_report_handler = NULL;
121 // A log message handler that gets notified of every log message we process. 118 // A log message handler that gets notified of every log message we process.
122 LogMessageHandlerFunction log_message_handler = NULL; 119 LogMessageHandlerFunction log_message_handler = NULL;
123 120
124 // Helper functions to wrap platform differences. 121 // Helper functions to wrap platform differences.
125 122
126 int32 CurrentProcessId() { 123 int32 CurrentProcessId() {
127 #if defined(OS_WIN) 124 #if defined(OS_WIN)
128 return GetCurrentProcessId(); 125 return GetCurrentProcessId();
129 #elif defined(OS_POSIX) 126 #elif defined(OS_POSIX)
130 return getpid(); 127 return getpid();
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 if (!log_file_name) 392 if (!log_file_name)
396 log_file_name = new PathString(); 393 log_file_name = new PathString();
397 *log_file_name = settings.log_file; 394 *log_file_name = settings.log_file;
398 if (settings.delete_old == DELETE_OLD_LOG_FILE) 395 if (settings.delete_old == DELETE_OLD_LOG_FILE)
399 DeleteFilePath(*log_file_name); 396 DeleteFilePath(*log_file_name);
400 397
401 return InitializeLogFileHandle(); 398 return InitializeLogFileHandle();
402 } 399 }
403 400
404 void SetMinLogLevel(int level) { 401 void SetMinLogLevel(int level) {
405 min_log_level = std::min(LOG_ERROR_REPORT, level); 402 min_log_level = std::min(LOG_FATAL, level);
406 } 403 }
407 404
408 int GetMinLogLevel() { 405 int GetMinLogLevel() {
409 return min_log_level; 406 return min_log_level;
410 } 407 }
411 408
412 int GetVlogVerbosity() { 409 int GetVlogVerbosity() {
413 return std::max(-1, LOG_INFO - GetMinLogLevel()); 410 return std::max(-1, LOG_INFO - GetMinLogLevel());
414 } 411 }
415 412
(...skipping 16 matching lines...) Expand all
432 } 429 }
433 430
434 void SetShowErrorDialogs(bool enable_dialogs) { 431 void SetShowErrorDialogs(bool enable_dialogs) {
435 show_error_dialogs = enable_dialogs; 432 show_error_dialogs = enable_dialogs;
436 } 433 }
437 434
438 void SetLogAssertHandler(LogAssertHandlerFunction handler) { 435 void SetLogAssertHandler(LogAssertHandlerFunction handler) {
439 log_assert_handler = handler; 436 log_assert_handler = handler;
440 } 437 }
441 438
442 void SetLogReportHandler(LogReportHandlerFunction handler) {
443 log_report_handler = handler;
444 }
445
446 void SetLogMessageHandler(LogMessageHandlerFunction handler) { 439 void SetLogMessageHandler(LogMessageHandlerFunction handler) {
447 log_message_handler = handler; 440 log_message_handler = handler;
448 } 441 }
449 442
450 LogMessageHandlerFunction GetLogMessageHandler() { 443 LogMessageHandlerFunction GetLogMessageHandler() {
451 return log_message_handler; 444 return log_message_handler;
452 } 445 }
453 446
454 // MSVC doesn't like complex extern templates and DLLs. 447 // MSVC doesn't like complex extern templates and DLLs.
455 #if !defined(COMPILER_MSVC) 448 #if !defined(COMPILER_MSVC)
456 // Explicit instantiations for commonly used comparisons. 449 // Explicit instantiations for commonly used comparisons.
457 template std::string* MakeCheckOpString<int, int>( 450 template std::string* MakeCheckOpString<int, int>(
458 const int&, const int&, const char* names); 451 const int&, const int&, const char* names);
459 template std::string* MakeCheckOpString<unsigned long, unsigned long>( 452 template std::string* MakeCheckOpString<unsigned long, unsigned long>(
460 const unsigned long&, const unsigned long&, const char* names); 453 const unsigned long&, const unsigned long&, const char* names);
461 template std::string* MakeCheckOpString<unsigned long, unsigned int>( 454 template std::string* MakeCheckOpString<unsigned long, unsigned int>(
462 const unsigned long&, const unsigned int&, const char* names); 455 const unsigned long&, const unsigned int&, const char* names);
463 template std::string* MakeCheckOpString<unsigned int, unsigned long>( 456 template std::string* MakeCheckOpString<unsigned int, unsigned long>(
464 const unsigned int&, const unsigned long&, const char* names); 457 const unsigned int&, const unsigned long&, const char* names);
465 template std::string* MakeCheckOpString<std::string, std::string>( 458 template std::string* MakeCheckOpString<std::string, std::string>(
466 const std::string&, const std::string&, const char* name); 459 const std::string&, const std::string&, const char* name);
467 #endif 460 #endif
468 461
462 #if !defined(NDEBUG)
469 // Displays a message box to the user with the error message in it. 463 // Displays a message box to the user with the error message in it.
470 // Used for fatal messages, where we close the app simultaneously. 464 // Used for fatal messages, where we close the app simultaneously.
471 // This is for developers only; we don't use this in circumstances 465 // This is for developers only; we don't use this in circumstances
472 // (like release builds) where users could see it, since users don't 466 // (like release builds) where users could see it, since users don't
473 // understand these messages anyway. 467 // understand these messages anyway.
474 void DisplayDebugMessageInDialog(const std::string& str) { 468 void DisplayDebugMessageInDialog(const std::string& str) {
475 if (str.empty()) 469 if (str.empty())
476 return; 470 return;
477 471
478 if (!show_error_dialogs) 472 if (!show_error_dialogs)
(...skipping 30 matching lines...) Expand all
509 } else { 503 } else {
510 // debug process broken, let's just do a message box 504 // debug process broken, let's just do a message box
511 MessageBoxW(NULL, &cmdline[0], L"Fatal error", 505 MessageBoxW(NULL, &cmdline[0], L"Fatal error",
512 MB_OK | MB_ICONHAND | MB_TOPMOST); 506 MB_OK | MB_ICONHAND | MB_TOPMOST);
513 } 507 }
514 #else 508 #else
515 // We intentionally don't implement a dialog on other platforms. 509 // We intentionally don't implement a dialog on other platforms.
516 // You can just look at stderr. 510 // You can just look at stderr.
517 #endif 511 #endif
518 } 512 }
513 #endif // !defined(NDEBUG)
519 514
520 #if defined(OS_WIN) 515 #if defined(OS_WIN)
521 LogMessage::SaveLastError::SaveLastError() : last_error_(::GetLastError()) { 516 LogMessage::SaveLastError::SaveLastError() : last_error_(::GetLastError()) {
522 } 517 }
523 518
524 LogMessage::SaveLastError::~SaveLastError() { 519 LogMessage::SaveLastError::~SaveLastError() {
525 ::SetLastError(last_error_); 520 ::SetLastError(last_error_);
526 } 521 }
527 #endif // defined(OS_WIN) 522 #endif // defined(OS_WIN)
528 523
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 android_LogPriority priority = 579 android_LogPriority priority =
585 (severity_ < 0) ? ANDROID_LOG_VERBOSE : ANDROID_LOG_UNKNOWN; 580 (severity_ < 0) ? ANDROID_LOG_VERBOSE : ANDROID_LOG_UNKNOWN;
586 switch (severity_) { 581 switch (severity_) {
587 case LOG_INFO: 582 case LOG_INFO:
588 priority = ANDROID_LOG_INFO; 583 priority = ANDROID_LOG_INFO;
589 break; 584 break;
590 case LOG_WARNING: 585 case LOG_WARNING:
591 priority = ANDROID_LOG_WARN; 586 priority = ANDROID_LOG_WARN;
592 break; 587 break;
593 case LOG_ERROR: 588 case LOG_ERROR:
594 case LOG_ERROR_REPORT:
595 priority = ANDROID_LOG_ERROR; 589 priority = ANDROID_LOG_ERROR;
596 break; 590 break;
597 case LOG_FATAL: 591 case LOG_FATAL:
598 priority = ANDROID_LOG_FATAL; 592 priority = ANDROID_LOG_FATAL;
599 break; 593 break;
600 } 594 }
601 __android_log_write(priority, "chromium", str_newline.c_str()); 595 __android_log_write(priority, "chromium", str_newline.c_str());
602 #endif 596 #endif
603 ignore_result(fwrite(str_newline.data(), str_newline.size(), 1, stderr)); 597 ignore_result(fwrite(str_newline.data(), str_newline.size(), 1, stderr));
604 fflush(stderr); 598 fflush(stderr);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 // the debug message process. We also don't display assertions to the 647 // the debug message process. We also don't display assertions to the
654 // user in release mode. The enduser can't do anything with this 648 // user in release mode. The enduser can't do anything with this
655 // information, and displaying message boxes when the application is 649 // information, and displaying message boxes when the application is
656 // hosed can cause additional problems. 650 // hosed can cause additional problems.
657 #ifndef NDEBUG 651 #ifndef NDEBUG
658 DisplayDebugMessageInDialog(stream_.str()); 652 DisplayDebugMessageInDialog(stream_.str());
659 #endif 653 #endif
660 // Crash the process to generate a dump. 654 // Crash the process to generate a dump.
661 base::debug::BreakDebugger(); 655 base::debug::BreakDebugger();
662 } 656 }
663 } else if (severity_ == LOG_ERROR_REPORT) {
664 // We are here only if the user runs with --enable-dcheck in release mode.
665 if (log_report_handler) {
666 log_report_handler(std::string(stream_.str()));
667 } else {
668 DisplayDebugMessageInDialog(stream_.str());
669 }
670 } 657 }
671 } 658 }
672 659
673 // writes the common header info to the stream 660 // writes the common header info to the stream
674 void LogMessage::Init(const char* file, int line) { 661 void LogMessage::Init(const char* file, int line) {
675 base::StringPiece filename(file); 662 base::StringPiece filename(file);
676 size_t last_slash_pos = filename.find_last_of("\\/"); 663 size_t last_slash_pos = filename.find_last_of("\\/");
677 if (last_slash_pos != base::StringPiece::npos) 664 if (last_slash_pos != base::StringPiece::npos)
678 filename.remove_prefix(last_slash_pos + 1); 665 filename.remove_prefix(last_slash_pos + 1);
679 666
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 return *log_file_name; 817 return *log_file_name;
831 return std::wstring(); 818 return std::wstring();
832 } 819 }
833 #endif 820 #endif
834 821
835 } // namespace logging 822 } // namespace logging
836 823
837 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { 824 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) {
838 return out << base::WideToUTF8(std::wstring(wstr)); 825 return out << base::WideToUTF8(std::wstring(wstr));
839 } 826 }
OLDNEW
« no previous file with comments | « base/logging.h ('k') | base/logging_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698