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

Side by Side Diff: base/logging.h

Issue 2034393004: Allow multiple logging::LogMessage{Handler,Listener}s Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments, deque for listeners, reentrant test Created 4 years, 4 months 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') | base/logging.cc » ('J')
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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include <cassert> 10 #include <cassert>
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // Dialogs are not shown by default. 272 // Dialogs are not shown by default.
273 BASE_EXPORT void SetShowErrorDialogs(bool enable_dialogs); 273 BASE_EXPORT void SetShowErrorDialogs(bool enable_dialogs);
274 274
275 // Sets the Log Assert Handler that will be used to notify of check failures. 275 // Sets the Log Assert Handler that will be used to notify of check failures.
276 // The default handler shows a dialog box and then terminate the process, 276 // The default handler shows a dialog box and then terminate the process,
277 // however clients can use this function to override with their own handling 277 // however clients can use this function to override with their own handling
278 // (e.g. a silent one for Unit Tests) 278 // (e.g. a silent one for Unit Tests)
279 typedef void (*LogAssertHandlerFunction)(const std::string& str); 279 typedef void (*LogAssertHandlerFunction)(const std::string& str);
280 BASE_EXPORT void SetLogAssertHandler(LogAssertHandlerFunction handler); 280 BASE_EXPORT void SetLogAssertHandler(LogAssertHandlerFunction handler);
281 281
282 // Sets the Log Message Handler that gets passed every log message before 282 // LogMessageHandler is the callback interface for log message handling.
283 // it's sent to other log destinations (if any). 283 // OnMessage() is called for every log message before it's sent to other log
284 // Returns true to signal that it handled the message and the message 284 // destinations (if any), but after LogMessageListener.
285 // should not be sent to other log destinations. 285 // Return true in OnMessage() to signal that it handled the message and the
286 typedef bool (*LogMessageHandlerFunction)(int severity, 286 // message should not be sent to other log destinations, including other
287 const char* file, int line, size_t message_start, const std::string& str); 287 // handlers added before the current one.
288 BASE_EXPORT void SetLogMessageHandler(LogMessageHandlerFunction handler); 288 class BASE_EXPORT LogMessageHandler {
289 BASE_EXPORT LogMessageHandlerFunction GetLogMessageHandler(); 289 public:
290 virtual ~LogMessageHandler();
291 virtual bool OnMessage(int severity,
292 const char* file,
293 int line,
294 size_t message_start,
295 const std::string& str) = 0;
296
297 protected:
298 LogMessageHandler();
299 };
300
301 BASE_EXPORT size_t LogMessageHandlerCountForTesting();
302
303 // LogMessageListener is similar to LogMessageHandler except that this
304 // interface doesn't support message hijacking, and is preferred over
305 // LogMessageHandler if hijacking is not needed.
306 class BASE_EXPORT LogMessageListener {
Mark Mentovai 2016/11/14 14:40:43 The difference between Handler and Listener will b
brettw 2016/11/14 22:01:31 I'm inclined to agree. What do you see as the cons
wychen 2016/11/15 23:52:27 The problem we want to solve in this CL is that ma
wychen 2016/11/18 21:14:00 Only keep listeners now.
307 public:
308 virtual ~LogMessageListener();
309 virtual void OnMessage(int severity,
310 const char* file,
311 int line,
312 size_t message_start,
313 const std::string& str) = 0;
314
315 protected:
316 LogMessageListener();
317 };
318
319 BASE_EXPORT size_t LogMessageListenerCountForTesting();
290 320
291 typedef int LogSeverity; 321 typedef int LogSeverity;
292 const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity 322 const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity
293 // Note: the log severities are used to index into the array of names, 323 // Note: the log severities are used to index into the array of names,
294 // see log_severity_names. 324 // see log_severity_names.
295 const LogSeverity LOG_INFO = 0; 325 const LogSeverity LOG_INFO = 0;
296 const LogSeverity LOG_WARNING = 1; 326 const LogSeverity LOG_WARNING = 1;
297 const LogSeverity LOG_ERROR = 2; 327 const LogSeverity LOG_ERROR = 2;
298 const LogSeverity LOG_FATAL = 3; 328 const LogSeverity LOG_FATAL = 3;
299 const LogSeverity LOG_NUM_SEVERITIES = 4; 329 const LogSeverity LOG_NUM_SEVERITIES = 4;
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 #elif NOTIMPLEMENTED_POLICY == 5 1015 #elif NOTIMPLEMENTED_POLICY == 5
986 #define NOTIMPLEMENTED() do {\ 1016 #define NOTIMPLEMENTED() do {\
987 static bool logged_once = false;\ 1017 static bool logged_once = false;\
988 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1018 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
989 logged_once = true;\ 1019 logged_once = true;\
990 } while(0);\ 1020 } while(0);\
991 EAT_STREAM_PARAMETERS 1021 EAT_STREAM_PARAMETERS
992 #endif 1022 #endif
993 1023
994 #endif // BASE_LOGGING_H_ 1024 #endif // BASE_LOGGING_H_
OLDNEW
« no previous file with comments | « no previous file | base/logging.cc » ('j') | base/logging.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698