Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: base/logging.cc

Issue 8757002: Don't delete g_vlog_info (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Limit g_vlog_info to two instances and track both. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/logging.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #include "base/safe_strerror_posix.h" 57 #include "base/safe_strerror_posix.h"
58 #endif 58 #endif
59 59
60 #if defined(OS_ANDROID) 60 #if defined(OS_ANDROID)
61 #include <android/log.h> 61 #include <android/log.h>
62 #endif 62 #endif
63 63
64 namespace logging { 64 namespace logging {
65 65
66 DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; 66 DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS;
67
68 VlogInfo* g_vlog_info_first = NULL;
akalin 2011/12/01 17:03:24 static and/or anon namespace for these two? (I gue
stevenjb 2011/12/01 19:09:38 Done.
69 VlogInfo* g_vlog_info_second = NULL;
akalin 2011/12/01 17:03:24 might be clearer to just have "g_vlog_info" and "g
stevenjb 2011/12/01 19:09:38 Done.
67 VlogInfo* g_vlog_info = NULL; 70 VlogInfo* g_vlog_info = NULL;
68 71
69 const char* const log_severity_names[LOG_NUM_SEVERITIES] = { 72 const char* const log_severity_names[LOG_NUM_SEVERITIES] = {
70 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" }; 73 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" };
71 74
72 int min_log_level = 0; 75 int min_log_level = 0;
73 76
74 // The default set here for logging_destination will only be used if 77 // The default set here for logging_destination will only be used if
75 // InitLogging is not called. On Windows, use a file next to the exe; 78 // InitLogging is not called. On Windows, use a file next to the exe;
76 // on POSIX platforms, where it may not even be possible to locate the 79 // on POSIX platforms, where it may not even be possible to locate the
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 return true; 353 return true;
351 } 354 }
352 355
353 bool BaseInitLoggingImpl(const PathChar* new_log_file, 356 bool BaseInitLoggingImpl(const PathChar* new_log_file,
354 LoggingDestination logging_dest, 357 LoggingDestination logging_dest,
355 LogLockingState lock_log, 358 LogLockingState lock_log,
356 OldFileDeletionState delete_old, 359 OldFileDeletionState delete_old,
357 DcheckState dcheck_state) { 360 DcheckState dcheck_state) {
358 CommandLine* command_line = CommandLine::ForCurrentProcess(); 361 CommandLine* command_line = CommandLine::ForCurrentProcess();
359 g_dcheck_state = dcheck_state; 362 g_dcheck_state = dcheck_state;
360 delete g_vlog_info; 363
361 g_vlog_info = NULL; 364 // NOTE: If g_vlog_info has already been initialized, it might be in use
365 // by another thread. Don't delete the old VLogInfo, just abandon it and
366 // create a second one. We track both to avoid memory leak warnings.
367 CHECK(g_vlog_info_second == NULL);
akalin 2011/12/01 17:03:24 usual style is !g_vlog_info_second
368
369 VlogInfo* vlog_info = NULL;
oshima 2011/12/01 16:28:48 how about DCHECK(!vlog_info_second); vlog_info_s
stevenjb 2011/12/01 16:51:41 I'm not sure I understand your suggestion. I put t
stevenjb 2011/12/01 19:09:38 After chatting + fred's feedback, I think this wil
362 // Don't bother initializing g_vlog_info unless we use one of the 370 // Don't bother initializing g_vlog_info unless we use one of the
363 // vlog switches. 371 // vlog switches.
364 if (command_line->HasSwitch(switches::kV) || 372 if (command_line->HasSwitch(switches::kV) ||
365 command_line->HasSwitch(switches::kVModule)) { 373 command_line->HasSwitch(switches::kVModule)) {
366 g_vlog_info = 374 vlog_info =
367 new VlogInfo(command_line->GetSwitchValueASCII(switches::kV), 375 new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
368 command_line->GetSwitchValueASCII(switches::kVModule), 376 command_line->GetSwitchValueASCII(switches::kVModule),
369 &min_log_level); 377 &min_log_level);
370 } 378 }
371 379
380 if (!g_vlog_info_first) {
akalin 2011/12/01 17:03:24 rewrite to use positive test, i.e. if (g_vlog_info
381 g_vlog_info_first = vlog_info;
382 g_vlog_info = g_vlog_info_first;
akalin 2011/12/01 17:03:24 i couldn't understand what these two lines were do
stevenjb 2011/12/01 19:09:38 Re-factored with oshima's feedback also.
383 } else {
384 g_vlog_info_second = vlog_info;
385 g_vlog_info = g_vlog_info_second;
386 }
387
372 LoggingLock::Init(lock_log, new_log_file); 388 LoggingLock::Init(lock_log, new_log_file);
373 389
374 LoggingLock logging_lock; 390 LoggingLock logging_lock;
375 391
376 if (log_file) { 392 if (log_file) {
377 // calling InitLogging twice or after some log call has already opened the 393 // calling InitLogging twice or after some log call has already opened the
378 // default log file will re-initialize to the new options 394 // default log file will re-initialize to the new options
379 CloseFile(log_file); 395 CloseFile(log_file);
380 log_file = NULL; 396 log_file = NULL;
381 } 397 }
(...skipping 21 matching lines...) Expand all
403 int GetMinLogLevel() { 419 int GetMinLogLevel() {
404 return min_log_level; 420 return min_log_level;
405 } 421 }
406 422
407 int GetVlogVerbosity() { 423 int GetVlogVerbosity() {
408 return std::max(-1, LOG_INFO - GetMinLogLevel()); 424 return std::max(-1, LOG_INFO - GetMinLogLevel());
409 } 425 }
410 426
411 int GetVlogLevelHelper(const char* file, size_t N) { 427 int GetVlogLevelHelper(const char* file, size_t N) {
412 DCHECK_GT(N, 0U); 428 DCHECK_GT(N, 0U);
413 return g_vlog_info ? 429 VlogInfo* vlog_info = g_vlog_info;
414 g_vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) : 430 return vlog_info ?
431 vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) :
415 GetVlogVerbosity(); 432 GetVlogVerbosity();
416 } 433 }
417 434
418 void SetLogItems(bool enable_process_id, bool enable_thread_id, 435 void SetLogItems(bool enable_process_id, bool enable_thread_id,
419 bool enable_timestamp, bool enable_tickcount) { 436 bool enable_timestamp, bool enable_tickcount) {
420 log_process_id = enable_process_id; 437 log_process_id = enable_process_id;
421 log_thread_id = enable_thread_id; 438 log_thread_id = enable_thread_id;
422 log_timestamp = enable_timestamp; 439 log_timestamp = enable_timestamp;
423 log_tickcount = enable_tickcount; 440 log_tickcount = enable_tickcount;
424 } 441 }
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 862
846 // This was defined at the beginnig of this file. 863 // This was defined at the beginnig of this file.
847 #undef write 864 #undef write
848 865
849 std::ostream& operator<<(std::ostream& o, const StringPiece& piece) { 866 std::ostream& operator<<(std::ostream& o, const StringPiece& piece) {
850 o.write(piece.data(), static_cast<std::streamsize>(piece.size())); 867 o.write(piece.data(), static_cast<std::streamsize>(piece.size()));
851 return o; 868 return o;
852 } 869 }
853 870
854 } // namespace base 871 } // namespace base
OLDNEW
« no previous file with comments | « base/logging.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698