OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Need to include this before most other files because it defines | 7 // Need to include this before most other files because it defines |
8 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define | 8 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define |
9 // IPC_MESSAGE_MACROS_LOG_ENABLED so render_messages.h will generate the | 9 // IPC_MESSAGE_MACROS_LOG_ENABLED so render_messages.h will generate the |
10 // ViewMsgLog et al. functions. | 10 // ViewMsgLog et al. functions. |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // starting a new log, then delete the old symlink and make a new | 180 // starting a new log, then delete the old symlink and make a new |
181 // one to a fresh log file. | 181 // one to a fresh log file. |
182 FilePath target_path; | 182 FilePath target_path; |
183 bool symlink_exists = file_util::PathExists(symlink_path); | 183 bool symlink_exists = file_util::PathExists(symlink_path); |
184 if (new_log || !symlink_exists) { | 184 if (new_log || !symlink_exists) { |
185 target_path = GenerateTimestampedName(symlink_path, base::Time::Now()); | 185 target_path = GenerateTimestampedName(symlink_path, base::Time::Now()); |
186 | 186 |
187 // We don't care if the unlink fails; we're going to continue anyway. | 187 // We don't care if the unlink fails; we're going to continue anyway. |
188 if (::unlink(symlink_path.value().c_str()) == -1) { | 188 if (::unlink(symlink_path.value().c_str()) == -1) { |
189 if (symlink_exists) // only warn if we might expect it to succeed. | 189 if (symlink_exists) // only warn if we might expect it to succeed. |
190 PLOG(WARNING) << "Unable to unlink " << symlink_path.value(); | 190 DPLOG(WARNING) << "Unable to unlink " << symlink_path.value(); |
191 } | 191 } |
192 if (!file_util::CreateSymbolicLink(target_path, symlink_path)) { | 192 if (!file_util::CreateSymbolicLink(target_path, symlink_path)) { |
193 PLOG(ERROR) << "Unable to create symlink " << symlink_path.value() | 193 DPLOG(ERROR) << "Unable to create symlink " << symlink_path.value() |
194 << " pointing at " << target_path.value(); | 194 << " pointing at " << target_path.value(); |
195 } | 195 } |
196 } else { | 196 } else { |
197 if (!file_util::ReadSymbolicLink(symlink_path, &target_path)) | 197 if (!file_util::ReadSymbolicLink(symlink_path, &target_path)) |
198 PLOG(ERROR) << "Unable to read symlink " << symlink_path.value(); | 198 DPLOG(ERROR) << "Unable to read symlink " << symlink_path.value(); |
199 } | 199 } |
200 return target_path; | 200 return target_path; |
201 } | 201 } |
202 | 202 |
203 void RemoveSymlinkAndLog(const FilePath& link_path, | 203 void RemoveSymlinkAndLog(const FilePath& link_path, |
204 const FilePath& target_path) { | 204 const FilePath& target_path) { |
205 if (::unlink(link_path.value().c_str()) == -1) | 205 if (::unlink(link_path.value().c_str()) == -1) |
206 PLOG(WARNING) << "Unable to unlink symlink " << link_path.value(); | 206 DPLOG(WARNING) << "Unable to unlink symlink " << link_path.value(); |
207 if (::unlink(target_path.value().c_str()) == -1) | 207 if (::unlink(target_path.value().c_str()) == -1) |
208 PLOG(WARNING) << "Unable to unlink log file " << target_path.value(); | 208 DPLOG(WARNING) << "Unable to unlink log file " << target_path.value(); |
209 } | 209 } |
210 | 210 |
211 } // anonymous namespace | 211 } // anonymous namespace |
212 | 212 |
213 FilePath GetSessionLogFile(const CommandLine& command_line) { | 213 FilePath GetSessionLogFile(const CommandLine& command_line) { |
214 FilePath log_dir; | 214 FilePath log_dir; |
215 std::string log_dir_str; | 215 std::string log_dir_str; |
216 scoped_ptr<base::Environment> env(base::Environment::Create()); | 216 scoped_ptr<base::Environment> env(base::Environment::Create()); |
217 if (env->GetVar(env_vars::kSessionLogDir, &log_dir_str) && | 217 if (env->GetVar(env_vars::kSessionLogDir, &log_dir_str) && |
218 !log_dir_str.empty()) { | 218 !log_dir_str.empty()) { |
(...skipping 26 matching lines...) Expand all Loading... |
245 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS : | 245 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS : |
246 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; | 246 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; |
247 | 247 |
248 // ChromeOS always logs through the symlink, so it shouldn't be | 248 // ChromeOS always logs through the symlink, so it shouldn't be |
249 // deleted if it already exists. | 249 // deleted if it already exists. |
250 if (!InitLogging(log_path.value().c_str(), | 250 if (!InitLogging(log_path.value().c_str(), |
251 DetermineLogMode(command_line), | 251 DetermineLogMode(command_line), |
252 logging::LOCK_LOG_FILE, | 252 logging::LOCK_LOG_FILE, |
253 logging::APPEND_TO_OLD_LOG_FILE, | 253 logging::APPEND_TO_OLD_LOG_FILE, |
254 dcheck_state)) { | 254 dcheck_state)) { |
255 LOG(ERROR) << "Unable to initialize logging to " << log_path.value(); | 255 DLOG(ERROR) << "Unable to initialize logging to " << log_path.value(); |
256 RemoveSymlinkAndLog(log_path, target_path); | 256 RemoveSymlinkAndLog(log_path, target_path); |
257 } else { | 257 } else { |
258 chrome_logging_redirected_ = true; | 258 chrome_logging_redirected_ = true; |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 #endif // OS_CHROMEOS | 262 #endif // OS_CHROMEOS |
263 | 263 |
264 void InitChromeLogging(const CommandLine& command_line, | 264 void InitChromeLogging(const CommandLine& command_line, |
265 OldFileDeletionState delete_old_log_file) { | 265 OldFileDeletionState delete_old_log_file) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; | 307 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; |
308 | 308 |
309 bool success = InitLogging(log_path.value().c_str(), | 309 bool success = InitLogging(log_path.value().c_str(), |
310 logging_dest, | 310 logging_dest, |
311 logging::LOCK_LOG_FILE, | 311 logging::LOCK_LOG_FILE, |
312 delete_old_log_file, | 312 delete_old_log_file, |
313 dcheck_state); | 313 dcheck_state); |
314 | 314 |
315 #if defined(OS_CHROMEOS) | 315 #if defined(OS_CHROMEOS) |
316 if (!success) { | 316 if (!success) { |
317 PLOG(ERROR) << "Unable to initialize logging to " << log_path.value() | 317 DPLOG(ERROR) << "Unable to initialize logging to " << log_path.value() |
318 << " (which should be a link to " << target_path.value() << ")"; | 318 << " (which should be a link to " << target_path.value() << ")"; |
319 RemoveSymlinkAndLog(log_path, target_path); | 319 RemoveSymlinkAndLog(log_path, target_path); |
320 chrome_logging_failed_ = true; | 320 chrome_logging_failed_ = true; |
321 return; | 321 return; |
322 } | 322 } |
323 #else | 323 #else |
324 if (!success) { | 324 if (!success) { |
325 PLOG(ERROR) << "Unable to initialize logging to " << log_path.value(); | 325 DPLOG(ERROR) << "Unable to initialize logging to " << log_path.value(); |
326 chrome_logging_failed_ = true; | 326 chrome_logging_failed_ = true; |
327 return; | 327 return; |
328 } | 328 } |
329 #endif | 329 #endif |
330 | 330 |
331 // Default to showing error dialogs. | 331 // Default to showing error dialogs. |
332 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoErrorDialogs)) | 332 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoErrorDialogs)) |
333 logging::SetShowErrorDialogs(true); | 333 logging::SetShowErrorDialogs(true); |
334 | 334 |
335 // we want process and thread IDs because we have a lot of things running | 335 // we want process and thread IDs because we have a lot of things running |
(...skipping 14 matching lines...) Expand all Loading... |
350 // Use a minimum log level if the command line asks for one, | 350 // Use a minimum log level if the command line asks for one, |
351 // otherwise leave it at the default level (INFO). | 351 // otherwise leave it at the default level (INFO). |
352 if (command_line.HasSwitch(switches::kLoggingLevel)) { | 352 if (command_line.HasSwitch(switches::kLoggingLevel)) { |
353 std::string log_level = command_line.GetSwitchValueASCII( | 353 std::string log_level = command_line.GetSwitchValueASCII( |
354 switches::kLoggingLevel); | 354 switches::kLoggingLevel); |
355 int level = 0; | 355 int level = 0; |
356 if (base::StringToInt(log_level, &level) && | 356 if (base::StringToInt(log_level, &level) && |
357 level >= 0 && level < LOG_NUM_SEVERITIES) { | 357 level >= 0 && level < LOG_NUM_SEVERITIES) { |
358 logging::SetMinLogLevel(level); | 358 logging::SetMinLogLevel(level); |
359 } else { | 359 } else { |
360 LOG(WARNING) << "Bad log level: " << log_level; | 360 DLOG(WARNING) << "Bad log level: " << log_level; |
361 } | 361 } |
362 } | 362 } |
363 | 363 |
364 #if defined(OS_WIN) | 364 #if defined(OS_WIN) |
365 // Enable trace control and transport through event tracing for Windows. | 365 // Enable trace control and transport through event tracing for Windows. |
366 if (env->HasVar(env_vars::kEtwLogging)) | 366 if (env->HasVar(env_vars::kEtwLogging)) |
367 logging::LogEventProvider::Initialize(kChromeTraceProviderName); | 367 logging::LogEventProvider::Initialize(kChromeTraceProviderName); |
368 #endif | 368 #endif |
369 | 369 |
370 #ifdef NDEBUG | 370 #ifdef NDEBUG |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 void DumpWithoutCrashing() { | 453 void DumpWithoutCrashing() { |
454 #if defined(OS_WIN) | 454 #if defined(OS_WIN) |
455 std::string str; | 455 std::string str; |
456 DumpProcessAssertHandler(str); | 456 DumpProcessAssertHandler(str); |
457 #else | 457 #else |
458 NOTIMPLEMENTED(); | 458 NOTIMPLEMENTED(); |
459 #endif // OS_WIN | 459 #endif // OS_WIN |
460 } | 460 } |
461 | 461 |
462 } // namespace logging | 462 } // namespace logging |
OLD | NEW |