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

Side by Side Diff: base/logging.h

Issue 1499693002: Don't evaluate args to LOG(INFO) and LOG(WARNING) in release builds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: clarify comment Created 5 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
« no previous file with comments | « no previous file | base/logging.cc » ('j') | 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) 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 #ifndef BASE_LOGGING_H_ 5 #ifndef BASE_LOGGING_H_
6 #define BASE_LOGGING_H_ 6 #define BASE_LOGGING_H_
7 7
8 #include <cassert> 8 #include <cassert>
9 #include <string> 9 #include <string>
10 #include <cstring> 10 #include <cstring>
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // log file/displayed to the user (if applicable). Anything below this level 231 // log file/displayed to the user (if applicable). Anything below this level
232 // will be silently ignored. The log level defaults to 0 (everything is logged 232 // will be silently ignored. The log level defaults to 0 (everything is logged
233 // up to level INFO) if this function is not called. 233 // up to level INFO) if this function is not called.
234 // Note that log messages for VLOG(x) are logged at level -x, so setting 234 // Note that log messages for VLOG(x) are logged at level -x, so setting
235 // the min log level to negative values enables verbose logging. 235 // the min log level to negative values enables verbose logging.
236 BASE_EXPORT void SetMinLogLevel(int level); 236 BASE_EXPORT void SetMinLogLevel(int level);
237 237
238 // Gets the current log level. 238 // Gets the current log level.
239 BASE_EXPORT int GetMinLogLevel(); 239 BASE_EXPORT int GetMinLogLevel();
240 240
241 // Used by LOG_IS_ON to lazy-evaluate stream arguments.
242 BASE_EXPORT bool ShouldCreateLogMessage(int severity);
243
241 // Gets the VLOG default verbosity level. 244 // Gets the VLOG default verbosity level.
242 BASE_EXPORT int GetVlogVerbosity(); 245 BASE_EXPORT int GetVlogVerbosity();
243 246
244 // Gets the current vlog level for the given file (usually taken from 247 // Gets the current vlog level for the given file (usually taken from
245 // __FILE__). 248 // __FILE__).
246 249
247 // Note that |N| is the size *with* the null terminator. 250 // Note that |N| is the size *with* the null terminator.
248 BASE_EXPORT int GetVlogLevelHelper(const char* file_start, size_t N); 251 BASE_EXPORT int GetVlogLevelHelper(const char* file_start, size_t N);
249 252
250 template <size_t N> 253 template <size_t N>
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 COMPACT_GOOGLE_LOG_EX_ERROR(ClassName , ##__VA_ARGS__) 336 COMPACT_GOOGLE_LOG_EX_ERROR(ClassName , ##__VA_ARGS__)
334 #define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR 337 #define COMPACT_GOOGLE_LOG_0 COMPACT_GOOGLE_LOG_ERROR
335 // Needed for LOG_IS_ON(ERROR). 338 // Needed for LOG_IS_ON(ERROR).
336 const LogSeverity LOG_0 = LOG_ERROR; 339 const LogSeverity LOG_0 = LOG_ERROR;
337 #endif 340 #endif
338 341
339 // As special cases, we can assume that LOG_IS_ON(FATAL) always holds. Also, 342 // As special cases, we can assume that LOG_IS_ON(FATAL) always holds. Also,
340 // LOG_IS_ON(DFATAL) always holds in debug mode. In particular, CHECK()s will 343 // LOG_IS_ON(DFATAL) always holds in debug mode. In particular, CHECK()s will
341 // always fire if they fail. 344 // always fire if they fail.
342 #define LOG_IS_ON(severity) \ 345 #define LOG_IS_ON(severity) \
343 ((::logging::LOG_ ## severity) >= ::logging::GetMinLogLevel()) 346 (::logging::ShouldCreateLogMessage(::logging::LOG_##severity))
344 347
345 // We can't do any caching tricks with VLOG_IS_ON() like the 348 // We can't do any caching tricks with VLOG_IS_ON() like the
346 // google-glog version since it requires GCC extensions. This means 349 // google-glog version since it requires GCC extensions. This means
347 // that using the v-logging functions in conjunction with --vmodule 350 // that using the v-logging functions in conjunction with --vmodule
348 // may be slow. 351 // may be slow.
349 #define VLOG_IS_ON(verboselevel) \ 352 #define VLOG_IS_ON(verboselevel) \
350 ((verboselevel) <= ::logging::GetVlogLevel(__FILE__)) 353 ((verboselevel) <= ::logging::GetVlogLevel(__FILE__))
351 354
352 // Helper macro which avoids evaluating the arguments to a stream if 355 // Helper macro which avoids evaluating the arguments to a stream if
353 // the condition doesn't hold. Condition is evaluated once and only once. 356 // the condition doesn't hold. Condition is evaluated once and only once.
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 #elif NOTIMPLEMENTED_POLICY == 5 965 #elif NOTIMPLEMENTED_POLICY == 5
963 #define NOTIMPLEMENTED() do {\ 966 #define NOTIMPLEMENTED() do {\
964 static bool logged_once = false;\ 967 static bool logged_once = false;\
965 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 968 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
966 logged_once = true;\ 969 logged_once = true;\
967 } while(0);\ 970 } while(0);\
968 EAT_STREAM_PARAMETERS 971 EAT_STREAM_PARAMETERS
969 #endif 972 #endif
970 973
971 #endif // BASE_LOGGING_H_ 974 #endif // BASE_LOGGING_H_
OLDNEW
« no previous file with comments | « no previous file | base/logging.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698