OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "base/command_line.h" | 44 #include "base/command_line.h" |
45 #include "base/debug_util.h" | 45 #include "base/debug_util.h" |
46 #include "base/eintr_wrapper.h" | 46 #include "base/eintr_wrapper.h" |
47 #include "base/lock_impl.h" | 47 #include "base/lock_impl.h" |
48 #if defined(OS_POSIX) | 48 #if defined(OS_POSIX) |
49 #include "base/safe_strerror_posix.h" | 49 #include "base/safe_strerror_posix.h" |
50 #endif | 50 #endif |
51 #include "base/process_util.h" | 51 #include "base/process_util.h" |
52 #include "base/string_piece.h" | 52 #include "base/string_piece.h" |
53 #include "base/utf_string_conversions.h" | 53 #include "base/utf_string_conversions.h" |
| 54 #include "base/vlog.h" |
54 | 55 |
55 namespace logging { | 56 namespace logging { |
56 | 57 |
57 bool g_enable_dcheck = false; | 58 bool g_enable_dcheck = false; |
| 59 VlogInfo* g_vlog_info = NULL; |
58 | 60 |
59 const char* const log_severity_names[LOG_NUM_SEVERITIES] = { | 61 const char* const log_severity_names[LOG_NUM_SEVERITIES] = { |
60 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" }; | 62 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" }; |
61 | 63 |
62 int min_log_level = 0; | 64 int min_log_level = 0; |
63 | 65 |
64 // The default set here for logging_destination will only be used if | 66 // The default set here for logging_destination will only be used if |
65 // InitLogging is not called. On Windows, use a file next to the exe; | 67 // InitLogging is not called. On Windows, use a file next to the exe; |
66 // on POSIX platforms, where it may not even be possible to locate the | 68 // on POSIX platforms, where it may not even be possible to locate the |
67 // executable on disk, use stderr. | 69 // executable on disk, use stderr. |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 #endif | 324 #endif |
323 } | 325 } |
324 | 326 |
325 return true; | 327 return true; |
326 } | 328 } |
327 | 329 |
328 void BaseInitLoggingImpl(const PathChar* new_log_file, | 330 void BaseInitLoggingImpl(const PathChar* new_log_file, |
329 LoggingDestination logging_dest, | 331 LoggingDestination logging_dest, |
330 LogLockingState lock_log, | 332 LogLockingState lock_log, |
331 OldFileDeletionState delete_old) { | 333 OldFileDeletionState delete_old) { |
| 334 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
332 g_enable_dcheck = | 335 g_enable_dcheck = |
333 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableDCHECK); | 336 command_line->HasSwitch(switches::kEnableDCHECK); |
| 337 delete g_vlog_info; |
| 338 g_vlog_info = NULL; |
| 339 // Don't bother initializing g_vlog_info unless we use one of the |
| 340 // vlog switches. |
| 341 if (command_line->HasSwitch(switches::kV) || |
| 342 command_line->HasSwitch(switches::kVModule)) { |
| 343 g_vlog_info = |
| 344 new VlogInfo(command_line->GetSwitchValueASCII(switches::kV), |
| 345 command_line->GetSwitchValueASCII(switches::kVModule)); |
| 346 } |
| 347 |
334 LoggingLock::Init(lock_log, new_log_file); | 348 LoggingLock::Init(lock_log, new_log_file); |
335 | 349 |
336 LoggingLock logging_lock; | 350 LoggingLock logging_lock; |
337 | 351 |
338 if (log_file) { | 352 if (log_file) { |
339 // calling InitLogging twice or after some log call has already opened the | 353 // calling InitLogging twice or after some log call has already opened the |
340 // default log file will re-initialize to the new options | 354 // default log file will re-initialize to the new options |
341 CloseFile(log_file); | 355 CloseFile(log_file); |
342 log_file = NULL; | 356 log_file = NULL; |
343 } | 357 } |
(...skipping 16 matching lines...) Expand all Loading... |
360 } | 374 } |
361 | 375 |
362 void SetMinLogLevel(int level) { | 376 void SetMinLogLevel(int level) { |
363 min_log_level = level; | 377 min_log_level = level; |
364 } | 378 } |
365 | 379 |
366 int GetMinLogLevel() { | 380 int GetMinLogLevel() { |
367 return min_log_level; | 381 return min_log_level; |
368 } | 382 } |
369 | 383 |
| 384 int GetVlogLevelHelper(const char* file, size_t N) { |
| 385 DCHECK_GT(N, 0U); |
| 386 return g_vlog_info ? |
| 387 g_vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) : |
| 388 VlogInfo::kDefaultVlogLevel; |
| 389 } |
| 390 |
370 void SetLogFilterPrefix(const char* filter) { | 391 void SetLogFilterPrefix(const char* filter) { |
371 if (log_filter_prefix) { | 392 if (log_filter_prefix) { |
372 delete log_filter_prefix; | 393 delete log_filter_prefix; |
373 log_filter_prefix = NULL; | 394 log_filter_prefix = NULL; |
374 } | 395 } |
375 | 396 |
376 if (filter) | 397 if (filter) |
377 log_filter_prefix = new std::string(filter); | 398 log_filter_prefix = new std::string(filter); |
378 } | 399 } |
379 | 400 |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 | 787 |
767 if (level == LOG_FATAL) | 788 if (level == LOG_FATAL) |
768 DebugUtil::BreakDebugger(); | 789 DebugUtil::BreakDebugger(); |
769 } | 790 } |
770 | 791 |
771 } // namespace logging | 792 } // namespace logging |
772 | 793 |
773 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { | 794 std::ostream& operator<<(std::ostream& out, const wchar_t* wstr) { |
774 return out << WideToUTF8(std::wstring(wstr)); | 795 return out << WideToUTF8(std::wstring(wstr)); |
775 } | 796 } |
OLD | NEW |