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

Side by Side Diff: base/logging.cc

Issue 6085015: Order function definitions in base/ according to the header. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lrn2merge Created 9 years, 11 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/json/json_reader.cc ('k') | base/message_loop_proxy_impl.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) 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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 ::SetLastError(last_error_); 523 ::SetLastError(last_error_);
524 } 524 }
525 #endif // defined(OS_WIN) 525 #endif // defined(OS_WIN)
526 526
527 LogMessage::LogMessage(const char* file, int line, LogSeverity severity, 527 LogMessage::LogMessage(const char* file, int line, LogSeverity severity,
528 int ctr) 528 int ctr)
529 : severity_(severity), file_(file), line_(line) { 529 : severity_(severity), file_(file), line_(line) {
530 Init(file, line); 530 Init(file, line);
531 } 531 }
532 532
533 LogMessage::LogMessage(const char* file, int line)
534 : severity_(LOG_INFO), file_(file), line_(line) {
535 Init(file, line);
536 }
537
538 LogMessage::LogMessage(const char* file, int line, LogSeverity severity)
539 : severity_(severity), file_(file), line_(line) {
540 Init(file, line);
541 }
542
533 LogMessage::LogMessage(const char* file, int line, const CheckOpString& result) 543 LogMessage::LogMessage(const char* file, int line, const CheckOpString& result)
534 : severity_(LOG_FATAL), file_(file), line_(line) { 544 : severity_(LOG_FATAL), file_(file), line_(line) {
535 Init(file, line); 545 Init(file, line);
536 stream_ << "Check failed: " << (*result.str_); 546 stream_ << "Check failed: " << (*result.str_);
537 } 547 }
538 548
539 LogMessage::LogMessage(const char* file, int line, LogSeverity severity, 549 LogMessage::LogMessage(const char* file, int line, LogSeverity severity,
540 const CheckOpString& result) 550 const CheckOpString& result)
541 : severity_(severity), file_(file), line_(line) { 551 : severity_(severity), file_(file), line_(line) {
542 Init(file, line); 552 Init(file, line);
543 stream_ << "Check failed: " << (*result.str_); 553 stream_ << "Check failed: " << (*result.str_);
544 } 554 }
545 555
546 LogMessage::LogMessage(const char* file, int line)
547 : severity_(LOG_INFO), file_(file), line_(line) {
548 Init(file, line);
549 }
550
551 LogMessage::LogMessage(const char* file, int line, LogSeverity severity)
552 : severity_(severity), file_(file), line_(line) {
553 Init(file, line);
554 }
555
556 // writes the common header info to the stream
557 void LogMessage::Init(const char* file, int line) {
558 base::StringPiece filename(file);
559 size_t last_slash_pos = filename.find_last_of("\\/");
560 if (last_slash_pos != base::StringPiece::npos)
561 filename.remove_prefix(last_slash_pos + 1);
562
563 // TODO(darin): It might be nice if the columns were fixed width.
564
565 stream_ << '[';
566 if (log_process_id)
567 stream_ << CurrentProcessId() << ':';
568 if (log_thread_id)
569 stream_ << CurrentThreadId() << ':';
570 if (log_timestamp) {
571 time_t t = time(NULL);
572 struct tm local_time = {0};
573 #if _MSC_VER >= 1400
574 localtime_s(&local_time, &t);
575 #else
576 localtime_r(&t, &local_time);
577 #endif
578 struct tm* tm_time = &local_time;
579 stream_ << std::setfill('0')
580 << std::setw(2) << 1 + tm_time->tm_mon
581 << std::setw(2) << tm_time->tm_mday
582 << '/'
583 << std::setw(2) << tm_time->tm_hour
584 << std::setw(2) << tm_time->tm_min
585 << std::setw(2) << tm_time->tm_sec
586 << ':';
587 }
588 if (log_tickcount)
589 stream_ << TickCount() << ':';
590 if (severity_ >= 0)
591 stream_ << log_severity_names[severity_];
592 else
593 stream_ << "VERBOSE" << -severity_;
594
595 stream_ << ":" << filename << "(" << line << ")] ";
596
597 message_start_ = stream_.tellp();
598 }
599
600 LogMessage::~LogMessage() { 556 LogMessage::~LogMessage() {
601 #ifndef NDEBUG 557 #ifndef NDEBUG
602 if (severity_ == LOG_FATAL) { 558 if (severity_ == LOG_FATAL) {
603 // Include a stack trace on a fatal. 559 // Include a stack trace on a fatal.
604 base::debug::StackTrace trace; 560 base::debug::StackTrace trace;
605 stream_ << std::endl; // Newline to separate from log message. 561 stream_ << std::endl; // Newline to separate from log message.
606 trace.OutputToStream(&stream_); 562 trace.OutputToStream(&stream_);
607 } 563 }
608 #endif 564 #endif
609 stream_ << std::endl; 565 stream_ << std::endl;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 } else if (severity_ == LOG_ERROR_REPORT) { 639 } else if (severity_ == LOG_ERROR_REPORT) {
684 // We are here only if the user runs with --enable-dcheck in release mode. 640 // We are here only if the user runs with --enable-dcheck in release mode.
685 if (log_report_handler) { 641 if (log_report_handler) {
686 log_report_handler(std::string(stream_.str())); 642 log_report_handler(std::string(stream_.str()));
687 } else { 643 } else {
688 DisplayDebugMessageInDialog(stream_.str()); 644 DisplayDebugMessageInDialog(stream_.str());
689 } 645 }
690 } 646 }
691 } 647 }
692 648
649 // writes the common header info to the stream
650 void LogMessage::Init(const char* file, int line) {
651 base::StringPiece filename(file);
652 size_t last_slash_pos = filename.find_last_of("\\/");
653 if (last_slash_pos != base::StringPiece::npos)
654 filename.remove_prefix(last_slash_pos + 1);
655
656 // TODO(darin): It might be nice if the columns were fixed width.
657
658 stream_ << '[';
659 if (log_process_id)
660 stream_ << CurrentProcessId() << ':';
661 if (log_thread_id)
662 stream_ << CurrentThreadId() << ':';
663 if (log_timestamp) {
664 time_t t = time(NULL);
665 struct tm local_time = {0};
666 #if _MSC_VER >= 1400
667 localtime_s(&local_time, &t);
668 #else
669 localtime_r(&t, &local_time);
670 #endif
671 struct tm* tm_time = &local_time;
672 stream_ << std::setfill('0')
673 << std::setw(2) << 1 + tm_time->tm_mon
674 << std::setw(2) << tm_time->tm_mday
675 << '/'
676 << std::setw(2) << tm_time->tm_hour
677 << std::setw(2) << tm_time->tm_min
678 << std::setw(2) << tm_time->tm_sec
679 << ':';
680 }
681 if (log_tickcount)
682 stream_ << TickCount() << ':';
683 if (severity_ >= 0)
684 stream_ << log_severity_names[severity_];
685 else
686 stream_ << "VERBOSE" << -severity_;
687
688 stream_ << ":" << filename << "(" << line << ")] ";
689
690 message_start_ = stream_.tellp();
691 }
692
693 #if defined(OS_WIN) 693 #if defined(OS_WIN)
694 // This has already been defined in the header, but defining it again as DWORD 694 // This has already been defined in the header, but defining it again as DWORD
695 // ensures that the type used in the header is equivalent to DWORD. If not, 695 // ensures that the type used in the header is equivalent to DWORD. If not,
696 // the redefinition is a compile error. 696 // the redefinition is a compile error.
697 typedef DWORD SystemErrorCode; 697 typedef DWORD SystemErrorCode;
698 #endif 698 #endif
699 699
700 SystemErrorCode GetLastSystemErrorCode() { 700 SystemErrorCode GetLastSystemErrorCode() {
701 #if defined(OS_WIN) 701 #if defined(OS_WIN)
702 return ::GetLastError(); 702 return ::GetLastError();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 817
818 if (level == LOG_FATAL) 818 if (level == LOG_FATAL)
819 base::debug::BreakDebugger(); 819 base::debug::BreakDebugger();
820 } 820 }
821 821
822 } // namespace logging 822 } // namespace logging
823 823
824 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { 824 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) {
825 return out << WideToUTF8(std::wstring(wstr)); 825 return out << WideToUTF8(std::wstring(wstr));
826 } 826 }
OLDNEW
« no previous file with comments | « base/json/json_reader.cc ('k') | base/message_loop_proxy_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698