| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <windows.h> | 9 #include <windows.h> |
| 9 typedef HANDLE FileHandle; | 10 typedef HANDLE FileHandle; |
| 10 typedef HANDLE MutexHandle; | 11 typedef HANDLE MutexHandle; |
| 12 // Windows warns on using write(). It prefers _write(). |
| 13 #define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count)) |
| 14 // Windows doesn't define STDERR_FILENO. Define it here. |
| 15 #define STDERR_FILENO 2 |
| 11 #elif defined(OS_MACOSX) | 16 #elif defined(OS_MACOSX) |
| 12 #include <CoreFoundation/CoreFoundation.h> | 17 #include <CoreFoundation/CoreFoundation.h> |
| 13 #include <mach/mach.h> | 18 #include <mach/mach.h> |
| 14 #include <mach/mach_time.h> | 19 #include <mach/mach_time.h> |
| 15 #include <mach-o/dyld.h> | 20 #include <mach-o/dyld.h> |
| 16 #elif defined(OS_LINUX) | 21 #elif defined(OS_LINUX) |
| 17 #include <sys/syscall.h> | 22 #include <sys/syscall.h> |
| 18 #include <time.h> | 23 #include <time.h> |
| 19 #endif | 24 #endif |
| 20 | 25 |
| 21 #if defined(OS_POSIX) | 26 #if defined(OS_POSIX) |
| 22 #include <errno.h> | 27 #include <errno.h> |
| 23 #include <stdlib.h> | 28 #include <stdlib.h> |
| 24 #include <stdio.h> | 29 #include <stdio.h> |
| 25 #include <string.h> | 30 #include <string.h> |
| 26 #include <unistd.h> | 31 #include <unistd.h> |
| 27 #define MAX_PATH PATH_MAX | 32 #define MAX_PATH PATH_MAX |
| 28 typedef FILE* FileHandle; | 33 typedef FILE* FileHandle; |
| 29 typedef pthread_mutex_t* MutexHandle; | 34 typedef pthread_mutex_t* MutexHandle; |
| 30 #endif | 35 #endif |
| 31 | 36 |
| 32 #include <ctime> | 37 #include <ctime> |
| 33 #include <iomanip> | 38 #include <iomanip> |
| 34 #include <cstring> | 39 #include <cstring> |
| 35 #include <algorithm> | 40 #include <algorithm> |
| 36 | 41 |
| 37 #include "base/base_switches.h" | 42 #include "base/base_switches.h" |
| 38 #include "base/command_line.h" | 43 #include "base/command_line.h" |
| 39 #include "base/debug_util.h" | 44 #include "base/debug_util.h" |
| 45 #include "base/eintr_wrapper.h" |
| 40 #include "base/lock_impl.h" | 46 #include "base/lock_impl.h" |
| 41 #if defined(OS_POSIX) | 47 #if defined(OS_POSIX) |
| 42 #include "base/safe_strerror_posix.h" | 48 #include "base/safe_strerror_posix.h" |
| 43 #endif | 49 #endif |
| 44 #include "base/string_piece.h" | 50 #include "base/string_piece.h" |
| 45 #include "base/string_util.h" | 51 #include "base/string_util.h" |
| 46 #include "base/utf_string_conversions.h" | 52 #include "base/utf_string_conversions.h" |
| 47 | 53 |
| 48 namespace logging { | 54 namespace logging { |
| 49 | 55 |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 #endif // OS_WIN | 666 #endif // OS_WIN |
| 661 | 667 |
| 662 void CloseLogFile() { | 668 void CloseLogFile() { |
| 663 if (!log_file) | 669 if (!log_file) |
| 664 return; | 670 return; |
| 665 | 671 |
| 666 CloseFile(log_file); | 672 CloseFile(log_file); |
| 667 log_file = NULL; | 673 log_file = NULL; |
| 668 } | 674 } |
| 669 | 675 |
| 676 void RawLog(int level, const char* message) { |
| 677 if (level >= min_log_level) { |
| 678 size_t bytes_written = 0; |
| 679 const size_t message_len = strlen(message); |
| 680 int rv; |
| 681 while (bytes_written < message_len) { |
| 682 rv = HANDLE_EINTR( |
| 683 write(STDERR_FILENO, message + bytes_written, |
| 684 message_len - bytes_written)); |
| 685 if (rv < 0) { |
| 686 // Give up, nothing we can do now. |
| 687 break; |
| 688 } |
| 689 bytes_written += rv; |
| 690 } |
| 691 |
| 692 if (message_len > 0 && message[message_len - 1] != '\n') { |
| 693 do { |
| 694 rv = HANDLE_EINTR(write(STDERR_FILENO, "\n", 1)); |
| 695 if (rv < 0) { |
| 696 // Give up, nothing we can do now. |
| 697 break; |
| 698 } |
| 699 } while (rv != 1); |
| 700 } |
| 701 } |
| 702 |
| 703 if (level == LOG_FATAL) |
| 704 DebugUtil::BreakDebugger(); |
| 705 } |
| 706 |
| 670 } // namespace logging | 707 } // namespace logging |
| 671 | 708 |
| 672 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { | 709 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { |
| 673 return out << WideToUTF8(std::wstring(wstr)); | 710 return out << WideToUTF8(std::wstring(wstr)); |
| 674 } | 711 } |
| OLD | NEW |