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

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: clean up, MockLog uses listener Created 4 years, 5 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_win.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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Sets the Log Message Handler that gets passed every log message before
283 // it's sent to other log destinations (if any). 283 // it's sent to other log destinations (if any).
284 // Returns true to signal that it handled the message and the message 284 // Returns true to signal that it handled the message and the message
285 // should not be sent to other log destinations. 285 // should not be sent to other log destinations, including other handlers
286 // below the current one in the stack.
286 typedef bool (*LogMessageHandlerFunction)(int severity, 287 typedef bool (*LogMessageHandlerFunction)(int severity,
287 const char* file, int line, size_t message_start, const std::string& str); 288 const char* file, int line, size_t message_start, const std::string& str);
288 BASE_EXPORT void SetLogMessageHandler(LogMessageHandlerFunction handler); 289 BASE_EXPORT void PushLogMessageHandler(LogMessageHandlerFunction handler);
289 BASE_EXPORT LogMessageHandlerFunction GetLogMessageHandler(); 290 // When popping, GetTopLogMessageHandler() is supposed to be |expected|.
291 BASE_EXPORT void PopLogMessageHandler(LogMessageHandlerFunction expected);
292 BASE_EXPORT LogMessageHandlerFunction GetTopLogMessageHandler();
293
294 // Sets the Log Message Listener that gets passed every log message before
295 // it's sent to LogMessageHandlerFunctions. If hijacking message is not
296 // needed, use this one instead of LogMessageHandlerFunction.
297 typedef void (*LogMessageListenerFunction)(int severity,
298 const char* file, int line, size_t message_start, const std::string& str);
299
300 class BASE_EXPORT ScopedLogMessageListener {
301 public:
302 ScopedLogMessageListener(LogMessageListenerFunction listener);
wychen 2016/07/09 21:21:19 explicit?
wychen 2016/07/18 15:44:12 Done.
303 ~ScopedLogMessageListener();
304 private:
305 LogMessageListenerFunction listener_;
306 };
307
308 BASE_EXPORT void AddLogMessageListener(LogMessageListenerFunction listener);
309 BASE_EXPORT void RemoveLogMessageListener(LogMessageListenerFunction listener);
290 310
291 typedef int LogSeverity; 311 typedef int LogSeverity;
292 const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity 312 const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity
293 // Note: the log severities are used to index into the array of names, 313 // Note: the log severities are used to index into the array of names,
294 // see log_severity_names. 314 // see log_severity_names.
295 const LogSeverity LOG_INFO = 0; 315 const LogSeverity LOG_INFO = 0;
296 const LogSeverity LOG_WARNING = 1; 316 const LogSeverity LOG_WARNING = 1;
297 const LogSeverity LOG_ERROR = 2; 317 const LogSeverity LOG_ERROR = 2;
298 const LogSeverity LOG_FATAL = 3; 318 const LogSeverity LOG_FATAL = 3;
299 const LogSeverity LOG_NUM_SEVERITIES = 4; 319 const LogSeverity LOG_NUM_SEVERITIES = 4;
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 #elif NOTIMPLEMENTED_POLICY == 5 1008 #elif NOTIMPLEMENTED_POLICY == 5
989 #define NOTIMPLEMENTED() do {\ 1009 #define NOTIMPLEMENTED() do {\
990 static bool logged_once = false;\ 1010 static bool logged_once = false;\
991 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1011 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
992 logged_once = true;\ 1012 logged_once = true;\
993 } while(0);\ 1013 } while(0);\
994 EAT_STREAM_PARAMETERS 1014 EAT_STREAM_PARAMETERS
995 #endif 1015 #endif
996 1016
997 #endif // BASE_LOGGING_H_ 1017 #endif // BASE_LOGGING_H_
OLDNEW
« no previous file with comments | « no previous file | base/logging.cc » ('j') | base/logging_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698