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 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 | 12 |
| 13 #if defined(OS_WIN) | 13 #if defined(OS_WIN) |
| 14 #include <io.h> | 14 #include <io.h> |
| 15 #include <windows.h> | 15 #include <windows.h> |
| 16 #include "base/files/file_path.h" | |
| 17 #include "base/files/file_util.h" | |
| 18 typedef HANDLE FileHandle; | 16 typedef HANDLE FileHandle; |
| 19 typedef HANDLE MutexHandle; | 17 typedef HANDLE MutexHandle; |
| 20 // Windows warns on using write(). It prefers _write(). | 18 // Windows warns on using write(). It prefers _write(). |
| 21 #define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count)) | 19 #define write(fd, buf, count) _write(fd, buf, static_cast<unsigned int>(count)) |
| 22 // Windows doesn't define STDERR_FILENO. Define it here. | 20 // Windows doesn't define STDERR_FILENO. Define it here. |
| 23 #define STDERR_FILENO 2 | 21 #define STDERR_FILENO 2 |
| 24 #elif defined(OS_MACOSX) | 22 #elif defined(OS_MACOSX) |
| 25 #include <asl.h> | 23 #include <asl.h> |
| 26 #include <CoreFoundation/CoreFoundation.h> | 24 #include <CoreFoundation/CoreFoundation.h> |
| 27 #include <mach/mach.h> | 25 #include <mach/mach.h> |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 #if defined(OS_WIN) | 281 #if defined(OS_WIN) |
| 284 // The FILE_APPEND_DATA access mask ensures that the file is atomically | 282 // The FILE_APPEND_DATA access mask ensures that the file is atomically |
| 285 // appended to across accesses from multiple threads. | 283 // appended to across accesses from multiple threads. |
| 286 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa364399(v=vs.85 ).aspx | 284 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa364399(v=vs.85 ).aspx |
| 287 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85 ).aspx | 285 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85 ).aspx |
| 288 g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA, | 286 g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA, |
| 289 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, | 287 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, |
| 290 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); | 288 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); |
| 291 if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) { | 289 if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) { |
| 292 // try the current directory | 290 // try the current directory |
| 293 base::FilePath file_path; | 291 wchar_t system_buffer[MAX_PATH]; |
| 294 if (!base::GetCurrentDirectory(&file_path)) | 292 system_buffer[0] = 0; |
| 293 DWORD len = ::GetCurrentDirectory(arraysize(system_buffer), | |
|
Lei Zhang
2016/06/15 22:50:45
Is the rest of the CL going to keep someone from l
ananta
2016/06/15 23:09:53
It won't. We are looking into addressing this by s
| |
| 294 system_buffer); | |
| 295 if (len == 0 || len > arraysize(system_buffer)) | |
| 295 return false; | 296 return false; |
| 296 | 297 |
| 297 *g_log_file_name = file_path.Append( | 298 *g_log_file_name = system_buffer; |
| 298 FILE_PATH_LITERAL("debug.log")).value(); | 299 // Append a trailing backslash if needed. |
| 300 if (g_log_file_name->back() != L'\\') | |
|
Lei Zhang
2016/06/15 22:50:45
Does it hurt if this check goes away and we just a
ananta
2016/06/15 23:09:53
That would work. I think it is better to avoid the
| |
| 301 *g_log_file_name += L"\\"; | |
| 302 *g_log_file_name += L"debug.log"; | |
| 299 | 303 |
| 300 g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA, | 304 g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA, |
| 301 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, | 305 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, |
| 302 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); | 306 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); |
| 303 if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) { | 307 if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) { |
| 304 g_log_file = nullptr; | 308 g_log_file = nullptr; |
| 305 return false; | 309 return false; |
| 306 } | 310 } |
| 307 } | 311 } |
| 308 #elif defined(OS_POSIX) | 312 #elif defined(OS_POSIX) |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 BASE_EXPORT void LogErrorNotReached(const char* file, int line) { | 916 BASE_EXPORT void LogErrorNotReached(const char* file, int line) { |
| 913 LogMessage(file, line, LOG_ERROR).stream() | 917 LogMessage(file, line, LOG_ERROR).stream() |
| 914 << "NOTREACHED() hit."; | 918 << "NOTREACHED() hit."; |
| 915 } | 919 } |
| 916 | 920 |
| 917 } // namespace logging | 921 } // namespace logging |
| 918 | 922 |
| 919 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { | 923 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { |
| 920 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); | 924 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); |
| 921 } | 925 } |
| OLD | NEW |