Chromium Code Reviews| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 bool LoggingLock::initialized = false; | 290 bool LoggingLock::initialized = false; |
| 291 // static | 291 // static |
| 292 base::internal::LockImpl* LoggingLock::log_lock = NULL; | 292 base::internal::LockImpl* LoggingLock::log_lock = NULL; |
| 293 // static | 293 // static |
| 294 LogLockingState LoggingLock::lock_log_file = LOCK_LOG_FILE; | 294 LogLockingState LoggingLock::lock_log_file = LOCK_LOG_FILE; |
| 295 | 295 |
| 296 #if defined(OS_WIN) | 296 #if defined(OS_WIN) |
| 297 // static | 297 // static |
| 298 MutexHandle LoggingLock::log_mutex = NULL; | 298 MutexHandle LoggingLock::log_mutex = NULL; |
| 299 #elif defined(OS_POSIX) | 299 #elif defined(OS_POSIX) |
| 300 // TODO(wtc): this pthread_mutex_t is not process-shared! | |
| 300 pthread_mutex_t LoggingLock::log_mutex = PTHREAD_MUTEX_INITIALIZER; | 301 pthread_mutex_t LoggingLock::log_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 301 #endif | 302 #endif |
| 302 | 303 |
| 303 // Called by logging functions to ensure that debug_file is initialized | 304 // Called by logging functions to ensure that debug_file is initialized |
| 304 // and can be used for writing. Returns false if the file could not be | 305 // and can be used for writing. Returns false if the file could not be |
| 305 // initialized. debug_file will be NULL in this case. | 306 // initialized. debug_file will be NULL in this case. |
| 306 bool InitializeLogFileHandle() { | 307 bool InitializeLogFileHandle() { |
| 307 if (log_file) | 308 if (log_file) |
| 308 return true; | 309 return true; |
| 309 | 310 |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 // from clobbering each other's writes. | 613 // from clobbering each other's writes. |
| 613 // If the client app did not call InitLogging, and the lock has not | 614 // If the client app did not call InitLogging, and the lock has not |
| 614 // been created do it now. We do this on demand, but if two threads try | 615 // been created do it now. We do this on demand, but if two threads try |
| 615 // to do this at the same time, there will be a race condition to create | 616 // to do this at the same time, there will be a race condition to create |
| 616 // the lock. This is why InitLogging should be called from the main | 617 // the lock. This is why InitLogging should be called from the main |
| 617 // thread at the beginning of execution. | 618 // thread at the beginning of execution. |
| 618 LoggingLock::Init(LOCK_LOG_FILE, NULL); | 619 LoggingLock::Init(LOCK_LOG_FILE, NULL); |
| 619 // write to log file | 620 // write to log file |
| 620 if (logging_destination != LOG_NONE && | 621 if (logging_destination != LOG_NONE && |
| 621 logging_destination != LOG_ONLY_TO_SYSTEM_DEBUG_LOG) { | 622 logging_destination != LOG_ONLY_TO_SYSTEM_DEBUG_LOG) { |
| 622 LoggingLock logging_lock; | 623 LoggingLock logging_lock; |
|
wtc
2012/09/12 20:27:09
This is the only place where we write to a log fil
| |
| 623 if (InitializeLogFileHandle()) { | 624 if (InitializeLogFileHandle()) { |
| 624 #if defined(OS_WIN) | 625 #if defined(OS_WIN) |
| 625 SetFilePointer(log_file, 0, 0, SEEK_END); | 626 SetFilePointer(log_file, 0, 0, SEEK_END); |
| 626 DWORD num_written; | 627 DWORD num_written; |
| 627 WriteFile(log_file, | 628 WriteFile(log_file, |
| 628 static_cast<const void*>(str_newline.c_str()), | 629 static_cast<const void*>(str_newline.c_str()), |
| 629 static_cast<DWORD>(str_newline.length()), | 630 static_cast<DWORD>(str_newline.length()), |
| 630 &num_written, | 631 &num_written, |
| 631 NULL); | 632 NULL); |
| 632 #else | 633 #else |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 851 } | 852 } |
| 852 | 853 |
| 853 // This was defined at the beginning of this file. | 854 // This was defined at the beginning of this file. |
| 854 #undef write | 855 #undef write |
| 855 | 856 |
| 856 } // namespace logging | 857 } // namespace logging |
| 857 | 858 |
| 858 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { | 859 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { |
| 859 return out << WideToUTF8(std::wstring(wstr)); | 860 return out << WideToUTF8(std::wstring(wstr)); |
| 860 } | 861 } |
| OLD | NEW |