| 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 "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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 } // anonymous namespace | 126 } // anonymous namespace |
| 127 | 127 |
| 128 namespace logging { | 128 namespace logging { |
| 129 | 129 |
| 130 LoggingDestination DetermineLogMode(const CommandLine& command_line) { | 130 LoggingDestination DetermineLogMode(const CommandLine& command_line) { |
| 131 // only use OutputDebugString in debug mode | 131 // only use OutputDebugString in debug mode |
| 132 #ifdef NDEBUG | 132 #ifdef NDEBUG |
| 133 bool enable_logging = false; | 133 bool enable_logging = false; |
| 134 const char *kInvertLoggingSwitch = switches::kEnableLogging; | 134 const char *kInvertLoggingSwitch = switches::kEnableLogging; |
| 135 const logging::LoggingDestination kDefaultLoggingMode = | 135 const logging::LoggingDestination kDefaultLoggingMode = logging::LOG_TO_FILE; |
| 136 logging::LOG_ONLY_TO_FILE; | |
| 137 #else | 136 #else |
| 138 bool enable_logging = true; | 137 bool enable_logging = true; |
| 139 const char *kInvertLoggingSwitch = switches::kDisableLogging; | 138 const char *kInvertLoggingSwitch = switches::kDisableLogging; |
| 140 const logging::LoggingDestination kDefaultLoggingMode = | 139 const logging::LoggingDestination kDefaultLoggingMode = logging::LOG_TO_ALL; |
| 141 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG; | |
| 142 #endif | 140 #endif |
| 143 | 141 |
| 144 if (command_line.HasSwitch(kInvertLoggingSwitch)) | 142 if (command_line.HasSwitch(kInvertLoggingSwitch)) |
| 145 enable_logging = !enable_logging; | 143 enable_logging = !enable_logging; |
| 146 | 144 |
| 147 logging::LoggingDestination log_mode; | 145 logging::LoggingDestination log_mode; |
| 148 if (enable_logging) { | 146 if (enable_logging) { |
| 149 // Let --enable-logging=stderr force only stderr, particularly useful for | 147 // Let --enable-logging=stderr force only stderr, particularly useful for |
| 150 // non-debug builds where otherwise you can't get logs to stderr at all. | 148 // non-debug builds where otherwise you can't get logs to stderr at all. |
| 151 if (command_line.GetSwitchValueASCII(switches::kEnableLogging) == "stderr") | 149 if (command_line.GetSwitchValueASCII(switches::kEnableLogging) == "stderr") |
| 152 log_mode = logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG; | 150 log_mode = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
| 153 else | 151 else |
| 154 log_mode = kDefaultLoggingMode; | 152 log_mode = kDefaultLoggingMode; |
| 155 } else { | 153 } else { |
| 156 log_mode = logging::LOG_NONE; | 154 log_mode = logging::LOG_NONE; |
| 157 } | 155 } |
| 158 return log_mode; | 156 return log_mode; |
| 159 } | 157 } |
| 160 | 158 |
| 161 #if defined(OS_CHROMEOS) | 159 #if defined(OS_CHROMEOS) |
| 162 namespace { | 160 namespace { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // Always force a new symlink when redirecting. | 243 // Always force a new symlink when redirecting. |
| 246 base::FilePath target_path = SetUpSymlinkIfNeeded(log_path, true); | 244 base::FilePath target_path = SetUpSymlinkIfNeeded(log_path, true); |
| 247 | 245 |
| 248 logging::DcheckState dcheck_state = | 246 logging::DcheckState dcheck_state = |
| 249 command_line.HasSwitch(switches::kEnableDCHECK) ? | 247 command_line.HasSwitch(switches::kEnableDCHECK) ? |
| 250 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS : | 248 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS : |
| 251 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; | 249 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; |
| 252 | 250 |
| 253 // ChromeOS always logs through the symlink, so it shouldn't be | 251 // ChromeOS always logs through the symlink, so it shouldn't be |
| 254 // deleted if it already exists. | 252 // deleted if it already exists. |
| 255 if (!InitLogging(log_path.value().c_str(), | 253 logging::LoggingSettings settings; |
| 256 DetermineLogMode(command_line), | 254 settings.logging_dest = DetermineLogMode(command_line); |
| 257 logging::LOCK_LOG_FILE, | 255 settings.log_file = log_path.value().c_str(); |
| 258 logging::APPEND_TO_OLD_LOG_FILE, | 256 settings.dcheck_state = dcheck_state; |
| 259 dcheck_state)) { | 257 if (!logging::InitLogging(settings)) { |
| 260 DLOG(ERROR) << "Unable to initialize logging to " << log_path.value(); | 258 DLOG(ERROR) << "Unable to initialize logging to " << log_path.value(); |
| 261 RemoveSymlinkAndLog(log_path, target_path); | 259 RemoveSymlinkAndLog(log_path, target_path); |
| 262 } else { | 260 } else { |
| 263 chrome_logging_redirected_ = true; | 261 chrome_logging_redirected_ = true; |
| 264 } | 262 } |
| 265 } | 263 } |
| 266 | 264 |
| 267 #endif // OS_CHROMEOS | 265 #endif // OS_CHROMEOS |
| 268 | 266 |
| 269 void InitChromeLogging(const CommandLine& command_line, | 267 void InitChromeLogging(const CommandLine& command_line, |
| 270 OldFileDeletionState delete_old_log_file) { | 268 OldFileDeletionState delete_old_log_file) { |
| 271 DCHECK(!chrome_logging_initialized_) << | 269 DCHECK(!chrome_logging_initialized_) << |
| 272 "Attempted to initialize logging when it was already initialized."; | 270 "Attempted to initialize logging when it was already initialized."; |
| 273 | 271 |
| 274 LoggingDestination logging_dest = DetermineLogMode(command_line); | 272 LoggingDestination logging_dest = DetermineLogMode(command_line); |
| 275 LogLockingState log_locking_state = LOCK_LOG_FILE; | 273 LogLockingState log_locking_state = LOCK_LOG_FILE; |
| 276 base::FilePath log_path; | 274 base::FilePath log_path; |
| 277 #if defined(OS_CHROMEOS) | 275 #if defined(OS_CHROMEOS) |
| 278 base::FilePath target_path; | 276 base::FilePath target_path; |
| 279 #endif | 277 #endif |
| 280 | 278 |
| 281 // Don't resolve the log path unless we need to. Otherwise we leave an open | 279 // Don't resolve the log path unless we need to. Otherwise we leave an open |
| 282 // ALPC handle after sandbox lockdown on Windows. | 280 // ALPC handle after sandbox lockdown on Windows. |
| 283 if (logging_dest == LOG_ONLY_TO_FILE || | 281 if ((logging_dest & LOG_TO_FILE) != 0) { |
| 284 logging_dest == LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG) { | |
| 285 log_path = GetLogFileName(); | 282 log_path = GetLogFileName(); |
| 286 | 283 |
| 287 #if defined(OS_CHROMEOS) | 284 #if defined(OS_CHROMEOS) |
| 288 // For BWSI (Incognito) logins, we want to put the logs in the user | 285 // For BWSI (Incognito) logins, we want to put the logs in the user |
| 289 // profile directory that is created for the temporary session instead | 286 // profile directory that is created for the temporary session instead |
| 290 // of in the system log directory, for privacy reasons. | 287 // of in the system log directory, for privacy reasons. |
| 291 if (command_line.HasSwitch(chromeos::switches::kGuestSession)) | 288 if (command_line.HasSwitch(chromeos::switches::kGuestSession)) |
| 292 log_path = GetSessionLogFile(command_line); | 289 log_path = GetSessionLogFile(command_line); |
| 293 | 290 |
| 294 // On ChromeOS we log to the symlink. We force creation of a new | 291 // On ChromeOS we log to the symlink. We force creation of a new |
| 295 // symlink if we've been asked to delete the old log, since that | 292 // symlink if we've been asked to delete the old log, since that |
| 296 // indicates the start of a new session. | 293 // indicates the start of a new session. |
| 297 target_path = SetUpSymlinkIfNeeded( | 294 target_path = SetUpSymlinkIfNeeded( |
| 298 log_path, delete_old_log_file == logging::DELETE_OLD_LOG_FILE); | 295 log_path, delete_old_log_file == logging::DELETE_OLD_LOG_FILE); |
| 299 | 296 |
| 300 // Because ChromeOS manages the move to a new session by redirecting | 297 // Because ChromeOS manages the move to a new session by redirecting |
| 301 // the link, it shouldn't remove the old file in the logging code, | 298 // the link, it shouldn't remove the old file in the logging code, |
| 302 // since that will remove the newly created link instead. | 299 // since that will remove the newly created link instead. |
| 303 delete_old_log_file = logging::APPEND_TO_OLD_LOG_FILE; | 300 delete_old_log_file = logging::APPEND_TO_OLD_LOG_FILE; |
| 304 #endif | 301 #endif |
| 305 } else { | 302 } else { |
| 306 log_locking_state = DONT_LOCK_LOG_FILE; | 303 log_locking_state = DONT_LOCK_LOG_FILE; |
| 307 } | 304 } |
| 308 | 305 |
| 309 logging::DcheckState dcheck_state = | 306 logging::DcheckState dcheck_state = |
| 310 command_line.HasSwitch(switches::kEnableDCHECK) ? | 307 command_line.HasSwitch(switches::kEnableDCHECK) ? |
| 311 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS : | 308 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS : |
| 312 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; | 309 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; |
| 313 | 310 |
| 314 bool success = InitLogging(log_path.value().c_str(), | 311 logging::LoggingSettings settings; |
| 315 logging_dest, | 312 settings.logging_dest = logging_dest; |
| 316 log_locking_state, | 313 settings.log_file = log_path.value().c_str(); |
| 317 delete_old_log_file, | 314 settings.lock_log = log_locking_state; |
| 318 dcheck_state); | 315 settings.delete_old = delete_old_log_file; |
| 316 settings.dcheck_state = dcheck_state; |
| 317 bool success = logging::InitLogging(settings); |
| 319 | 318 |
| 320 #if defined(OS_CHROMEOS) | 319 #if defined(OS_CHROMEOS) |
| 321 if (!success) { | 320 if (!success) { |
| 322 DPLOG(ERROR) << "Unable to initialize logging to " << log_path.value() | 321 DPLOG(ERROR) << "Unable to initialize logging to " << log_path.value() |
| 323 << " (which should be a link to " << target_path.value() << ")"; | 322 << " (which should be a link to " << target_path.value() << ")"; |
| 324 RemoveSymlinkAndLog(log_path, target_path); | 323 RemoveSymlinkAndLog(log_path, target_path); |
| 325 chrome_logging_failed_ = true; | 324 chrome_logging_failed_ = true; |
| 326 return; | 325 return; |
| 327 } | 326 } |
| 328 #else | 327 #else |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 time_deets.year, | 455 time_deets.year, |
| 457 time_deets.month, | 456 time_deets.month, |
| 458 time_deets.day_of_month, | 457 time_deets.day_of_month, |
| 459 time_deets.hour, | 458 time_deets.hour, |
| 460 time_deets.minute, | 459 time_deets.minute, |
| 461 time_deets.second); | 460 time_deets.second); |
| 462 return base_path.InsertBeforeExtensionASCII(suffix); | 461 return base_path.InsertBeforeExtensionASCII(suffix); |
| 463 } | 462 } |
| 464 | 463 |
| 465 } // namespace logging | 464 } // namespace logging |
| OLD | NEW |