| OLD | NEW |
| 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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 case LOG_ERROR: | 602 case LOG_ERROR: |
| 603 case LOG_ERROR_REPORT: | 603 case LOG_ERROR_REPORT: |
| 604 priority = ANDROID_LOG_ERROR; | 604 priority = ANDROID_LOG_ERROR; |
| 605 break; | 605 break; |
| 606 case LOG_FATAL: | 606 case LOG_FATAL: |
| 607 priority = ANDROID_LOG_FATAL; | 607 priority = ANDROID_LOG_FATAL; |
| 608 break; | 608 break; |
| 609 } | 609 } |
| 610 __android_log_write(priority, "chromium", str_newline.c_str()); | 610 __android_log_write(priority, "chromium", str_newline.c_str()); |
| 611 #endif | 611 #endif |
| 612 fprintf(stderr, "%s", str_newline.c_str()); | 612 ignore_result(fwrite(str_newline.data(), str_newline.size(), 1, stderr)); |
| 613 fflush(stderr); | 613 fflush(stderr); |
| 614 } else if (severity_ >= kAlwaysPrintErrorLevel) { | 614 } else if (severity_ >= kAlwaysPrintErrorLevel) { |
| 615 // When we're only outputting to a log file, above a certain log level, we | 615 // When we're only outputting to a log file, above a certain log level, we |
| 616 // should still output to stderr so that we can better detect and diagnose | 616 // should still output to stderr so that we can better detect and diagnose |
| 617 // problems with unit tests, especially on the buildbots. | 617 // problems with unit tests, especially on the buildbots. |
| 618 fprintf(stderr, "%s", str_newline.c_str()); | 618 ignore_result(fwrite(str_newline.data(), str_newline.size(), 1, stderr)); |
| 619 fflush(stderr); | 619 fflush(stderr); |
| 620 } | 620 } |
| 621 | 621 |
| 622 // write to log file | 622 // write to log file |
| 623 if ((logging_destination & LOG_TO_FILE) != 0) { | 623 if ((logging_destination & LOG_TO_FILE) != 0) { |
| 624 // We can have multiple threads and/or processes, so try to prevent them | 624 // We can have multiple threads and/or processes, so try to prevent them |
| 625 // from clobbering each other's writes. | 625 // from clobbering each other's writes. |
| 626 // If the client app did not call InitLogging, and the lock has not | 626 // If the client app did not call InitLogging, and the lock has not |
| 627 // been created do it now. We do this on demand, but if two threads try | 627 // been created do it now. We do this on demand, but if two threads try |
| 628 // to do this at the same time, there will be a race condition to create | 628 // to do this at the same time, there will be a race condition to create |
| 629 // the lock. This is why InitLogging should be called from the main | 629 // the lock. This is why InitLogging should be called from the main |
| 630 // thread at the beginning of execution. | 630 // thread at the beginning of execution. |
| 631 LoggingLock::Init(LOCK_LOG_FILE, NULL); | 631 LoggingLock::Init(LOCK_LOG_FILE, NULL); |
| 632 LoggingLock logging_lock; | 632 LoggingLock logging_lock; |
| 633 if (InitializeLogFileHandle()) { | 633 if (InitializeLogFileHandle()) { |
| 634 #if defined(OS_WIN) | 634 #if defined(OS_WIN) |
| 635 SetFilePointer(log_file, 0, 0, SEEK_END); | 635 SetFilePointer(log_file, 0, 0, SEEK_END); |
| 636 DWORD num_written; | 636 DWORD num_written; |
| 637 WriteFile(log_file, | 637 WriteFile(log_file, |
| 638 static_cast<const void*>(str_newline.c_str()), | 638 static_cast<const void*>(str_newline.c_str()), |
| 639 static_cast<DWORD>(str_newline.length()), | 639 static_cast<DWORD>(str_newline.length()), |
| 640 &num_written, | 640 &num_written, |
| 641 NULL); | 641 NULL); |
| 642 #else | 642 #else |
| 643 fprintf(log_file, "%s", str_newline.c_str()); | 643 ignore_result(fwrite( |
| 644 str_newline.data(), str_newline.size(), 1, log_file)); |
| 644 fflush(log_file); | 645 fflush(log_file); |
| 645 #endif | 646 #endif |
| 646 } | 647 } |
| 647 } | 648 } |
| 648 | 649 |
| 649 if (severity_ == LOG_FATAL) { | 650 if (severity_ == LOG_FATAL) { |
| 650 // Ensure the first characters of the string are on the stack so they | 651 // Ensure the first characters of the string are on the stack so they |
| 651 // are contained in minidumps for diagnostic purposes. | 652 // are contained in minidumps for diagnostic purposes. |
| 652 char str_stack[1024]; | 653 char str_stack[1024]; |
| 653 str_newline.copy(str_stack, arraysize(str_stack)); | 654 str_newline.copy(str_stack, arraysize(str_stack)); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 return *log_file_name; | 865 return *log_file_name; |
| 865 return std::wstring(); | 866 return std::wstring(); |
| 866 } | 867 } |
| 867 #endif | 868 #endif |
| 868 | 869 |
| 869 } // namespace logging | 870 } // namespace logging |
| 870 | 871 |
| 871 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { | 872 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { |
| 872 return out << base::WideToUTF8(std::wstring(wstr)); | 873 return out << base::WideToUTF8(std::wstring(wstr)); |
| 873 } | 874 } |
| OLD | NEW |