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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 if ((g_logging_destination & LOG_TO_FILE) != 0) { | 280 if ((g_logging_destination & LOG_TO_FILE) != 0) { |
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) { |
| 290 // We are intentionally not using FilePath or FileUtil here to reduce the |
| 291 // dependencies of the logging implementation. For e.g. FilePath and |
| 292 // FileUtil depend on shell32 and user32.dll. This is not acceptable for |
| 293 // some consumers of base logging like chrome_elf, etc. |
| 294 // Please don't change the code below to use FilePath. |
292 // try the current directory | 295 // try the current directory |
293 base::FilePath file_path; | 296 wchar_t system_buffer[MAX_PATH]; |
294 if (!base::GetCurrentDirectory(&file_path)) | 297 system_buffer[0] = 0; |
| 298 DWORD len = ::GetCurrentDirectory(arraysize(system_buffer), |
| 299 system_buffer); |
| 300 if (len == 0 || len > arraysize(system_buffer)) |
295 return false; | 301 return false; |
296 | 302 |
297 *g_log_file_name = file_path.Append( | 303 *g_log_file_name = system_buffer; |
298 FILE_PATH_LITERAL("debug.log")).value(); | 304 // Append a trailing backslash if needed. |
| 305 if (g_log_file_name->back() != L'\\') |
| 306 *g_log_file_name += L"\\"; |
| 307 *g_log_file_name += L"debug.log"; |
299 | 308 |
300 g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA, | 309 g_log_file = CreateFile(g_log_file_name->c_str(), FILE_APPEND_DATA, |
301 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, | 310 FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, |
302 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); | 311 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); |
303 if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) { | 312 if (g_log_file == INVALID_HANDLE_VALUE || g_log_file == nullptr) { |
304 g_log_file = nullptr; | 313 g_log_file = nullptr; |
305 return false; | 314 return false; |
306 } | 315 } |
307 } | 316 } |
308 #elif defined(OS_POSIX) | 317 #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) { | 921 BASE_EXPORT void LogErrorNotReached(const char* file, int line) { |
913 LogMessage(file, line, LOG_ERROR).stream() | 922 LogMessage(file, line, LOG_ERROR).stream() |
914 << "NOTREACHED() hit."; | 923 << "NOTREACHED() hit."; |
915 } | 924 } |
916 | 925 |
917 } // namespace logging | 926 } // namespace logging |
918 | 927 |
919 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { | 928 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { |
920 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); | 929 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); |
921 } | 930 } |
OLD | NEW |