OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include <iostream> | 11 #include <iostream> |
12 #include <fstream> | 12 #include <fstream> |
13 | 13 |
14 #include "chrome/common/logging_chrome.h" | 14 #include "chrome/common/logging_chrome.h" |
15 | 15 |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/debug_util.h" | 18 #include "base/debug_util.h" |
| 19 #include "base/file_path.h" |
19 #include "base/file_util.h" | 20 #include "base/file_util.h" |
20 #include "base/logging.h" | 21 #include "base/logging.h" |
21 #include "base/path_service.h" | 22 #include "base/path_service.h" |
22 #include "base/string_util.h" | 23 #include "base/string_util.h" |
23 #include "base/sys_info.h" | 24 #include "base/sys_info.h" |
24 #include "chrome/common/chrome_paths.h" | 25 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/env_vars.h" | 27 #include "chrome/common/env_vars.h" |
27 #include "ipc/ipc_message.h" | 28 #include "ipc/ipc_message.h" |
28 | 29 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // Let --enable-logging=stderr force only stderr, particularly useful for | 108 // Let --enable-logging=stderr force only stderr, particularly useful for |
108 // non-debug builds where otherwise you can't get logs to stderr at all. | 109 // non-debug builds where otherwise you can't get logs to stderr at all. |
109 if (command_line.GetSwitchValue(switches::kEnableLogging) == L"stderr") | 110 if (command_line.GetSwitchValue(switches::kEnableLogging) == L"stderr") |
110 log_mode = logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG; | 111 log_mode = logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG; |
111 else | 112 else |
112 log_mode = kDefaultLoggingMode; | 113 log_mode = kDefaultLoggingMode; |
113 } else { | 114 } else { |
114 log_mode = logging::LOG_NONE; | 115 log_mode = logging::LOG_NONE; |
115 } | 116 } |
116 | 117 |
117 #if defined(OS_POSIX) | 118 logging::InitLogging(GetLogFileName().value().c_str(), |
118 std::string log_file_name = WideToUTF8(GetLogFileName()); | |
119 #elif defined(OS_WIN) | |
120 std::wstring log_file_name = GetLogFileName(); | |
121 #endif | |
122 | |
123 logging::InitLogging(log_file_name.c_str(), | |
124 log_mode, | 119 log_mode, |
125 logging::LOCK_LOG_FILE, | 120 logging::LOCK_LOG_FILE, |
126 delete_old_log_file); | 121 delete_old_log_file); |
127 | 122 |
128 // we want process and thread IDs because we have a lot of things running | 123 // we want process and thread IDs because we have a lot of things running |
129 logging::SetLogItems(true, true, false, true); | 124 logging::SetLogItems(true, true, false, true); |
130 | 125 |
131 // We call running in unattended mode "headless", and allow | 126 // We call running in unattended mode "headless", and allow |
132 // headless mode to be configured either by the Environment | 127 // headless mode to be configured either by the Environment |
133 // Variable or by the Command Line Switch. This is for | 128 // Variable or by the Command Line Switch. This is for |
(...skipping 24 matching lines...) Expand all Loading... |
158 // we need to do more cleanup in the future. | 153 // we need to do more cleanup in the future. |
159 void CleanupChromeLogging() { | 154 void CleanupChromeLogging() { |
160 DCHECK(chrome_logging_initialized_) << | 155 DCHECK(chrome_logging_initialized_) << |
161 "Attempted to clean up logging when it wasn't initialized."; | 156 "Attempted to clean up logging when it wasn't initialized."; |
162 | 157 |
163 CloseLogFile(); | 158 CloseLogFile(); |
164 | 159 |
165 chrome_logging_initialized_ = false; | 160 chrome_logging_initialized_ = false; |
166 } | 161 } |
167 | 162 |
168 std::wstring GetLogFileName() { | 163 FilePath GetLogFileName() { |
169 std::wstring filename = base::SysInfo::GetEnvVar(env_vars::kLogFileName); | 164 std::wstring filename = base::SysInfo::GetEnvVar(env_vars::kLogFileName); |
170 if (filename != L"") | 165 if (!filename.empty()) |
171 return filename; | 166 return FilePath::FromWStringHack(filename); |
172 | 167 |
173 const std::wstring log_filename(L"chrome_debug.log"); | 168 const FilePath log_filename(FILE_PATH_LITERAL("chrome_debug.log")); |
174 std::wstring log_path; | 169 FilePath log_path; |
175 | 170 |
176 if (PathService::Get(chrome::DIR_LOGS, &log_path)) { | 171 if (PathService::Get(chrome::DIR_LOGS, &log_path)) { |
177 file_util::AppendToPath(&log_path, log_filename); | 172 log_path = log_path.Append(log_filename); |
178 return log_path; | 173 return log_path; |
179 } else { | 174 } else { |
180 // error with path service, just use some default file somewhere | 175 // error with path service, just use some default file somewhere |
181 return log_filename; | 176 return log_filename; |
182 } | 177 } |
183 } | 178 } |
184 | 179 |
185 bool DialogsAreSuppressed() { | 180 bool DialogsAreSuppressed() { |
186 return dialogs_are_suppressed_; | 181 return dialogs_are_suppressed_; |
187 } | 182 } |
188 | 183 |
189 size_t GetFatalAssertions(AssertionList* assertions) { | 184 size_t GetFatalAssertions(AssertionList* assertions) { |
190 // In this function, we don't assume that assertions is non-null, so | 185 // In this function, we don't assume that assertions is non-null, so |
191 // that if you just want an assertion count, you can pass in NULL. | 186 // that if you just want an assertion count, you can pass in NULL. |
192 if (assertions) | 187 if (assertions) |
193 assertions->clear(); | 188 assertions->clear(); |
194 size_t assertion_count = 0; | 189 size_t assertion_count = 0; |
195 | 190 |
196 std::ifstream log_file; | 191 std::ifstream log_file; |
197 #if defined(OS_WIN) | 192 log_file.open(GetLogFileName().value().c_str()); |
198 log_file.open(GetLogFileName().c_str()); | |
199 #elif defined(OS_POSIX) | |
200 log_file.open(WideToUTF8(GetLogFileName()).c_str()); | |
201 #endif | |
202 if (!log_file.is_open()) | 193 if (!log_file.is_open()) |
203 return 0; | 194 return 0; |
204 | 195 |
205 std::string utf8_line; | 196 std::string utf8_line; |
206 std::wstring wide_line; | 197 std::wstring wide_line; |
207 while(!log_file.eof()) { | 198 while(!log_file.eof()) { |
208 getline(log_file, utf8_line); | 199 getline(log_file, utf8_line); |
209 if (utf8_line.find(":FATAL:") != std::string::npos) { | 200 if (utf8_line.find(":FATAL:") != std::string::npos) { |
210 wide_line = UTF8ToWide(utf8_line); | 201 wide_line = UTF8ToWide(utf8_line); |
211 if (assertions) | 202 if (assertions) |
212 assertions->push_back(wide_line); | 203 assertions->push_back(wide_line); |
213 ++assertion_count; | 204 ++assertion_count; |
214 } | 205 } |
215 } | 206 } |
216 log_file.close(); | 207 log_file.close(); |
217 | 208 |
218 return assertion_count; | 209 return assertion_count; |
219 } | 210 } |
220 | 211 |
221 } // namespace logging | 212 } // namespace logging |
OLD | NEW |