OLD | NEW |
---|---|
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 Loading... | |
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 // Derive the LogMessageHandler that gets passed every log message before |
grt (UTC plus 2)
2016/08/01 21:17:44
Please review the style guide section on comments
wychen
2016/08/01 23:11:03
Done.
| |
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 class BASE_EXPORT LogMessageHandler { |
285 // should not be sent to other log destinations. | 285 public: |
286 typedef bool (*LogMessageHandlerFunction)(int severity, | 286 // Returns true to signal that it handled the message and the message |
287 const char* file, int line, size_t message_start, const std::string& str); | 287 // should not be sent to other log destinations, including other handlers |
288 BASE_EXPORT void SetLogMessageHandler(LogMessageHandlerFunction handler); | 288 // added before the current one. |
289 BASE_EXPORT LogMessageHandlerFunction GetLogMessageHandler(); | 289 virtual bool OnMessage(int severity, const char* file, int line, |
290 size_t message_start, const std::string& str) = 0; | |
291 virtual ~LogMessageHandler(); | |
grt (UTC plus 2)
2016/08/01 21:17:44
Move up; ctors and dtors precede other methods.
wychen
2016/08/01 23:11:04
Done.
| |
292 protected: | |
293 LogMessageHandler(); | |
294 }; | |
295 | |
296 BASE_EXPORT size_t LogMessageHandlerCountForTesting(); | |
grt (UTC plus 2)
2016/08/01 21:17:44
If this is only used by base_unittests, it should
wychen
2016/08/01 23:11:04
If I don't export it, component build would fail.
grt (UTC plus 2)
2016/08/02 07:25:46
Meh. I didn't realize base_unittests linked to bas
| |
297 | |
298 // Derive the LogMessageListener that gets passed every log message before | |
299 // it's sent to LogMessageHandler. If hijacking message is not | |
300 // needed, use this one instead of LogMessageHandler. | |
301 class BASE_EXPORT LogMessageListener { | |
302 public: | |
303 virtual void OnMessage(int severity, const char* file, int line, | |
304 size_t message_start, const std::string& str) = 0; | |
305 virtual ~LogMessageListener(); | |
306 protected: | |
307 LogMessageListener(); | |
308 }; | |
309 | |
310 BASE_EXPORT size_t LogMessageListenerCountForTesting(); | |
290 | 311 |
291 typedef int LogSeverity; | 312 typedef int LogSeverity; |
292 const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity | 313 const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity |
293 // Note: the log severities are used to index into the array of names, | 314 // Note: the log severities are used to index into the array of names, |
294 // see log_severity_names. | 315 // see log_severity_names. |
295 const LogSeverity LOG_INFO = 0; | 316 const LogSeverity LOG_INFO = 0; |
296 const LogSeverity LOG_WARNING = 1; | 317 const LogSeverity LOG_WARNING = 1; |
297 const LogSeverity LOG_ERROR = 2; | 318 const LogSeverity LOG_ERROR = 2; |
298 const LogSeverity LOG_FATAL = 3; | 319 const LogSeverity LOG_FATAL = 3; |
299 const LogSeverity LOG_NUM_SEVERITIES = 4; | 320 const LogSeverity LOG_NUM_SEVERITIES = 4; |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
997 #elif NOTIMPLEMENTED_POLICY == 5 | 1018 #elif NOTIMPLEMENTED_POLICY == 5 |
998 #define NOTIMPLEMENTED() do {\ | 1019 #define NOTIMPLEMENTED() do {\ |
999 static bool logged_once = false;\ | 1020 static bool logged_once = false;\ |
1000 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 1021 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
1001 logged_once = true;\ | 1022 logged_once = true;\ |
1002 } while(0);\ | 1023 } while(0);\ |
1003 EAT_STREAM_PARAMETERS | 1024 EAT_STREAM_PARAMETERS |
1004 #endif | 1025 #endif |
1005 | 1026 |
1006 #endif // BASE_LOGGING_H_ | 1027 #endif // BASE_LOGGING_H_ |
OLD | NEW |