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

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: Add anon namespace and simplify logic 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #if defined(OS_POSIX) 56 #if defined(OS_POSIX)
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 namespace {
67
66 DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS; 68 DcheckState g_dcheck_state = DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS;
69
67 VlogInfo* g_vlog_info = NULL; 70 VlogInfo* g_vlog_info = NULL;
71 VlogInfo* g_vlog_info_prev = NULL;
68 72
69 const char* const log_severity_names[LOG_NUM_SEVERITIES] = { 73 const char* const log_severity_names[LOG_NUM_SEVERITIES] = {
70 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" }; 74 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" };
71 75
72 int min_log_level = 0; 76 int min_log_level = 0;
73 77
74 // The default set here for logging_destination will only be used if 78 // 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; 79 // 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 80 // on POSIX platforms, where it may not even be possible to locate the
77 // executable on disk, use stderr. 81 // executable on disk, use stderr.
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 #elif defined(OS_POSIX) 347 #elif defined(OS_POSIX)
344 log_file = fopen(log_file_name->c_str(), "a"); 348 log_file = fopen(log_file_name->c_str(), "a");
345 if (log_file == NULL) 349 if (log_file == NULL)
346 return false; 350 return false;
347 #endif 351 #endif
348 } 352 }
349 353
350 return true; 354 return true;
351 } 355 }
352 356
357 } // namespace
358
359
353 bool BaseInitLoggingImpl(const PathChar* new_log_file, 360 bool BaseInitLoggingImpl(const PathChar* new_log_file,
354 LoggingDestination logging_dest, 361 LoggingDestination logging_dest,
355 LogLockingState lock_log, 362 LogLockingState lock_log,
356 OldFileDeletionState delete_old, 363 OldFileDeletionState delete_old,
357 DcheckState dcheck_state) { 364 DcheckState dcheck_state) {
358 CommandLine* command_line = CommandLine::ForCurrentProcess(); 365 CommandLine* command_line = CommandLine::ForCurrentProcess();
359 g_dcheck_state = dcheck_state; 366 g_dcheck_state = dcheck_state;
360 delete g_vlog_info; 367
361 g_vlog_info = NULL;
362 // Don't bother initializing g_vlog_info unless we use one of the 368 // Don't bother initializing g_vlog_info unless we use one of the
363 // vlog switches. 369 // vlog switches.
364 if (command_line->HasSwitch(switches::kV) || 370 if (command_line->HasSwitch(switches::kV) ||
365 command_line->HasSwitch(switches::kVModule)) { 371 command_line->HasSwitch(switches::kVModule)) {
372 // NOTE: If g_vlog_info has already been initialized, it might be in use
373 // by another thread. Don't delete the old VLogInfo, just create a second
374 // one. We keep track of both to avoid memory leak warnings.
375 CHECK(!g_vlog_info_prev);
376 g_vlog_info_prev = g_vlog_info;
377
366 g_vlog_info = 378 g_vlog_info =
367 new VlogInfo(command_line->GetSwitchValueASCII(switches::kV), 379 new VlogInfo(command_line->GetSwitchValueASCII(switches::kV),
368 command_line->GetSwitchValueASCII(switches::kVModule), 380 command_line->GetSwitchValueASCII(switches::kVModule),
369 &min_log_level); 381 &min_log_level);
370 } 382 }
371 383
372 LoggingLock::Init(lock_log, new_log_file); 384 LoggingLock::Init(lock_log, new_log_file);
373 385
374 LoggingLock logging_lock; 386 LoggingLock logging_lock;
375 387
(...skipping 27 matching lines...) Expand all
403 int GetMinLogLevel() { 415 int GetMinLogLevel() {
404 return min_log_level; 416 return min_log_level;
405 } 417 }
406 418
407 int GetVlogVerbosity() { 419 int GetVlogVerbosity() {
408 return std::max(-1, LOG_INFO - GetMinLogLevel()); 420 return std::max(-1, LOG_INFO - GetMinLogLevel());
409 } 421 }
410 422
411 int GetVlogLevelHelper(const char* file, size_t N) { 423 int GetVlogLevelHelper(const char* file, size_t N) {
412 DCHECK_GT(N, 0U); 424 DCHECK_GT(N, 0U);
413 return g_vlog_info ? 425 VlogInfo* vlog_info = g_vlog_info;
akalin 2011/12/01 19:31:19 did you mean to change this? I don't know if this
414 g_vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) : 426 return vlog_info ?
427 vlog_info->GetVlogLevel(base::StringPiece(file, N - 1)) :
415 GetVlogVerbosity(); 428 GetVlogVerbosity();
416 } 429 }
417 430
418 void SetLogItems(bool enable_process_id, bool enable_thread_id, 431 void SetLogItems(bool enable_process_id, bool enable_thread_id,
419 bool enable_timestamp, bool enable_tickcount) { 432 bool enable_timestamp, bool enable_tickcount) {
420 log_process_id = enable_process_id; 433 log_process_id = enable_process_id;
421 log_thread_id = enable_thread_id; 434 log_thread_id = enable_thread_id;
422 log_timestamp = enable_timestamp; 435 log_timestamp = enable_timestamp;
423 log_tickcount = enable_tickcount; 436 log_tickcount = enable_tickcount;
424 } 437 }
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 858
846 // This was defined at the beginnig of this file. 859 // This was defined at the beginnig of this file.
847 #undef write 860 #undef write
848 861
849 std::ostream& operator<<(std::ostream& o, const StringPiece& piece) { 862 std::ostream& operator<<(std::ostream& o, const StringPiece& piece) {
850 o.write(piece.data(), static_cast<std::streamsize>(piece.size())); 863 o.write(piece.data(), static_cast<std::streamsize>(piece.size()));
851 return o; 864 return o;
852 } 865 }
853 866
854 } // namespace base 867 } // 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