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> |
11 #include <cstring> | 11 #include <cstring> |
12 #include <sstream> | 12 #include <sstream> |
13 #include <string> | 13 #include <string> |
14 #include <type_traits> | 14 #include <type_traits> |
15 #include <utility> | 15 #include <utility> |
16 | 16 |
17 #include "base/base_export.h" | 17 #include "base/base_export.h" |
| 18 #include "base/callback_forward.h" |
18 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
19 #include "base/debug/debugger.h" | 20 #include "base/debug/debugger.h" |
20 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/strings/string_piece_forward.h" |
21 #include "base/template_util.h" | 23 #include "base/template_util.h" |
22 #include "build/build_config.h" | 24 #include "build/build_config.h" |
23 | 25 |
24 // | 26 // |
25 // Optional message capabilities | 27 // Optional message capabilities |
26 // ----------------------------- | 28 // ----------------------------- |
27 // Assertion failed messages and fatal errors are displayed in a dialog box | 29 // Assertion failed messages and fatal errors are displayed in a dialog box |
28 // before the application exits. However, running this UI creates a message | 30 // before the application exits. However, running this UI creates a message |
29 // loop, which causes application messages to be processed and potentially | 31 // loop, which causes application messages to be processed and potentially |
30 // dispatched to existing application windows. Since the application is in a | 32 // dispatched to existing application windows. Since the application is in a |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // only. | 269 // only. |
268 BASE_EXPORT void SetLogItems(bool enable_process_id, bool enable_thread_id, | 270 BASE_EXPORT void SetLogItems(bool enable_process_id, bool enable_thread_id, |
269 bool enable_timestamp, bool enable_tickcount); | 271 bool enable_timestamp, bool enable_tickcount); |
270 | 272 |
271 // Sets whether or not you'd like to see fatal debug messages popped up in | 273 // Sets whether or not you'd like to see fatal debug messages popped up in |
272 // a dialog box or not. | 274 // a dialog box or not. |
273 // Dialogs are not shown by default. | 275 // Dialogs are not shown by default. |
274 BASE_EXPORT void SetShowErrorDialogs(bool enable_dialogs); | 276 BASE_EXPORT void SetShowErrorDialogs(bool enable_dialogs); |
275 | 277 |
276 // Sets the Log Assert Handler that will be used to notify of check failures. | 278 // Sets the Log Assert Handler that will be used to notify of check failures. |
| 279 // Resets Log Assert Handler on object destruction. |
277 // The default handler shows a dialog box and then terminate the process, | 280 // The default handler shows a dialog box and then terminate the process, |
278 // however clients can use this function to override with their own handling | 281 // however clients can use this function to override with their own handling |
279 // (e.g. a silent one for Unit Tests) | 282 // (e.g. a silent one for Unit Tests) |
280 typedef void (*LogAssertHandlerFunction)(const std::string& str); | 283 using LogAssertHandlerFunction = |
281 BASE_EXPORT void SetLogAssertHandler(LogAssertHandlerFunction handler); | 284 base::Callback<void(const char* file, |
| 285 int line, |
| 286 const base::StringPiece message, |
| 287 const base::StringPiece stack_trace)>; |
| 288 |
| 289 class BASE_EXPORT ScopedLogAssertHandler { |
| 290 public: |
| 291 explicit ScopedLogAssertHandler(LogAssertHandlerFunction handler); |
| 292 ~ScopedLogAssertHandler(); |
| 293 |
| 294 private: |
| 295 DISALLOW_COPY_AND_ASSIGN(ScopedLogAssertHandler); |
| 296 }; |
282 | 297 |
283 // Sets the Log Message Handler that gets passed every log message before | 298 // Sets the Log Message Handler that gets passed every log message before |
284 // it's sent to other log destinations (if any). | 299 // it's sent to other log destinations (if any). |
285 // Returns true to signal that it handled the message and the message | 300 // Returns true to signal that it handled the message and the message |
286 // should not be sent to other log destinations. | 301 // should not be sent to other log destinations. |
287 typedef bool (*LogMessageHandlerFunction)(int severity, | 302 typedef bool (*LogMessageHandlerFunction)(int severity, |
288 const char* file, int line, size_t message_start, const std::string& str); | 303 const char* file, int line, size_t message_start, const std::string& str); |
289 BASE_EXPORT void SetLogMessageHandler(LogMessageHandlerFunction handler); | 304 BASE_EXPORT void SetLogMessageHandler(LogMessageHandlerFunction handler); |
290 BASE_EXPORT LogMessageHandlerFunction GetLogMessageHandler(); | 305 BASE_EXPORT LogMessageHandlerFunction GetLogMessageHandler(); |
291 | 306 |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 #elif NOTIMPLEMENTED_POLICY == 5 | 1154 #elif NOTIMPLEMENTED_POLICY == 5 |
1140 #define NOTIMPLEMENTED() do {\ | 1155 #define NOTIMPLEMENTED() do {\ |
1141 static bool logged_once = false;\ | 1156 static bool logged_once = false;\ |
1142 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 1157 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
1143 logged_once = true;\ | 1158 logged_once = true;\ |
1144 } while(0);\ | 1159 } while(0);\ |
1145 EAT_STREAM_PARAMETERS | 1160 EAT_STREAM_PARAMETERS |
1146 #endif | 1161 #endif |
1147 | 1162 |
1148 #endif // BASE_LOGGING_H_ | 1163 #endif // BASE_LOGGING_H_ |
OLD | NEW |