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(MAX_PATH, system_buffer); |
| 294 if (len == 0 || len > arraysize(system_buffer)) |
295 return false; | 295 return false; |
296 | 296 |
297 *g_log_file_name = file_path.Append( | 297 *g_log_file_name = system_buffer; |
298 FILE_PATH_LITERAL("debug.log")).value(); | 298 // Append a trailing backslash if needed. |
| 299 if (g_log_file_name->back() != L'\\') |
| 300 *g_log_file_name += L"\\"; |
| 301 *g_log_file_name += L"debug.log"; |
299 | 302 |
300 g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA, | 303 g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA, |
301 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, | 304 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, |
302 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); | 305 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); |
303 if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) { | 306 if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) { |
304 g_log_file = nullptr; | 307 g_log_file = nullptr; |
305 return false; | 308 return false; |
306 } | 309 } |
307 } | 310 } |
308 #elif defined(OS_POSIX) | 311 #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) { | 915 BASE_EXPORT void LogErrorNotReached(const char* file, int line) { |
913 LogMessage(file, line, LOG_ERROR).stream() | 916 LogMessage(file, line, LOG_ERROR).stream() |
914 << "NOTREACHED() hit."; | 917 << "NOTREACHED() hit."; |
915 } | 918 } |
916 | 919 |
917 } // namespace logging | 920 } // namespace logging |
918 | 921 |
919 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { | 922 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { |
920 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); | 923 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); |
921 } | 924 } |
OLD | NEW |