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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 unlink(log_name.c_str()); | 157 unlink(log_name.c_str()); |
158 #endif | 158 #endif |
159 } | 159 } |
160 | 160 |
161 PathString GetDefaultLogFile() { | 161 PathString GetDefaultLogFile() { |
162 #if defined(OS_WIN) | 162 #if defined(OS_WIN) |
163 // On Windows we use the same path as the exe. | 163 // On Windows we use the same path as the exe. |
164 wchar_t module_name[MAX_PATH]; | 164 wchar_t module_name[MAX_PATH]; |
165 GetModuleFileName(NULL, module_name, MAX_PATH); | 165 GetModuleFileName(NULL, module_name, MAX_PATH); |
166 | 166 |
167 PathString log_file = module_name; | 167 PathString log_name = module_name; |
168 PathString::size_type last_backslash = | 168 PathString::size_type last_backslash = log_name.rfind('\\', log_name.size()); |
169 log_file.rfind('\\', log_file.size()); | |
170 if (last_backslash != PathString::npos) | 169 if (last_backslash != PathString::npos) |
171 log_file.erase(last_backslash + 1); | 170 log_name.erase(last_backslash + 1); |
172 log_file += L"debug.log"; | 171 log_name += L"debug.log"; |
173 return log_file; | 172 return log_name; |
174 #elif defined(OS_POSIX) | 173 #elif defined(OS_POSIX) |
175 // On other platforms we just use the current directory. | 174 // On other platforms we just use the current directory. |
176 return PathString("debug.log"); | 175 return PathString("debug.log"); |
177 #endif | 176 #endif |
178 } | 177 } |
179 | 178 |
180 // This class acts as a wrapper for locking the logging files. | 179 // This class acts as a wrapper for locking the logging files. |
181 // LoggingLock::Init() should be called from the main thread before any logging | 180 // LoggingLock::Init() should be called from the main thread before any logging |
182 // is done. Then whenever logging, be sure to have a local LoggingLock | 181 // is done. Then whenever logging, be sure to have a local LoggingLock |
183 // instance on the stack. This will ensure that the lock is unlocked upon | 182 // instance on the stack. This will ensure that the lock is unlocked upon |
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 return *log_file_name; | 801 return *log_file_name; |
803 return std::wstring(); | 802 return std::wstring(); |
804 } | 803 } |
805 #endif | 804 #endif |
806 | 805 |
807 } // namespace logging | 806 } // namespace logging |
808 | 807 |
809 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { | 808 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { |
810 return out << base::WideToUTF8(wstr); | 809 return out << base::WideToUTF8(wstr); |
811 } | 810 } |
OLD | NEW |