xtd 0.2.0
Loading...
Searching...
No Matches
trace.h
Go to the documentation of this file.
1
4#pragma once
5#include "debug.h"
6
8namespace xtd {
10 namespace diagnostics {
39 public:
41
46
48
54 static bool auto_flush() noexcept;
59 static void auto_flush(bool auto_flush) noexcept;
60
64 static uint32 indent_level() noexcept;
68 static void indent_level(uint32 indent_level) noexcept;
69
73 static uint32 indent_size() noexcept;
77 static void indent_size(uint32 indent_size) noexcept;
78
83 static listener_collection& listeners() noexcept;
88 static void listeners(const listener_collection& listeners) noexcept;
89
95 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0")]]
96 static bool show_assert_dialog() noexcept;
102 [[deprecated("Replaced by xtd::diagnostics::default_trace_listener::assert_ui_enabled - Will be removed in version 0.4.0")]]
103 static void show_assert_dialog(bool show_assert_dialog) noexcept;
104
108 static bool use_global_lock() noexcept;
112 static void use_global_lock(bool use_global_lock) noexcept;
114
116
123 static void cassert(bool condition);
127 static void cassert(bool condition, const xtd::ustring& message);
132 static void cassert(bool condition, const xtd::ustring& message, const xtd::diagnostics::stack_frame& stack_frame);
137 static void cassert(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message);
143 static void cassert(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message, const xtd::diagnostics::stack_frame& stack_frame);
147 static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame);
148
153 static void fail(const xtd::ustring& message) {
154 #if defined(TRACE)
155 fail__(message);
156 #endif
157 }
163 static void fail(const xtd::ustring& message, const xtd::ustring& detail_message) {
164 #if defined(TRACE)
165 fail__(message, detail_message);
166 #endif
167 }
168
170 static void flush() {
171 #if defined(TRACE)
172 flush_();
173 #endif
174 }
175
177 static void indent() noexcept;
178
182 static void print(const xtd::ustring& message) {
183 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
184 write_line_(message);
185 #endif
186 }
191 template<typename ...args_t>
192 static void print(const xtd::ustring& format, args_t&& ... args) {
193 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
194 write_line_(xtd::ustring::format(format, args...));
195 #endif
196 }
198 template<typename ...args_t>
199 static void print(const char* format, args_t&& ... args) {
200 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
201 write_line_(xtd::ustring::format(format, args...));
202 #endif
203 }
205
209 static void trace_error(const xtd::ustring& message) {
210 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
211 trace_event_(trace_event_type::error, message);
212 #endif
213 }
218 template<typename ...objects>
219 static void trace_error(const xtd::ustring& message, const objects& ... args) {
220 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
221 trace_event_(trace_event_type::error, message, args...);
222 #endif
223 }
224
228 static void trace_information(const xtd::ustring& message) {
229 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
230 trace_event_(trace_event_type::information, message);
231 #endif
232 }
237 template<typename ...objects>
238 static void trace_information(const xtd::ustring& message, const objects& ... args) {
239 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
240 trace_event_(trace_event_type::information, xtd::ustring::format(message, args...));
241 #endif
242 }
243
247 static void trace_warning(const xtd::ustring& message) {
248 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
249 trace_event_(trace_event_type::warning, message);
250 #endif
251 }
256 template<typename ...objects>
257 static void trace_warning(const xtd::ustring& message, const objects& ... args) {
258 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
259 trace_event_(trace_event_type::warning, xtd::ustring::format(message, args...));
260 #endif
261 }
262
264 static void unindent() noexcept;
265
270 static void write(const xtd::ustring& message) {
271 #if defined(TRACE)
272 write_(message);
273 #endif
274 }
275
280 template<typename object_t>
281 static void write(const object_t& message) {
282 #if defined(TRACE)
283 write_(xtd::ustring::format("{}", message));
284 #endif
285 }
292 template<typename object_t>
293 static void write(const object_t& message, const xtd::ustring& category) {
294 #if defined(TRACE)
295 write_(xtd::ustring::format("{}", message), category);
296 #endif
297 }
303 template<typename ...args_t>
304 static void write(const xtd::ustring& format, args_t&& ... args) {
305 #if defined(TRACE)
306 write_(ustring::format(format, args...));
307 #endif
308 }
310 template<typename ...args_t>
311 static void write(const char* format, args_t&& ... args) {
312 #if defined(TRACE)
313 write_(ustring::format(format, args...));
314 #endif
315 }
317
323 static void write_if(bool condition, const xtd::ustring& message) {
324 #if defined(TRACE)
325 if (condition) write_(message);
326 #endif
327 }
333 template<typename object_t>
334 static void write_if(bool condition, const object_t& message) {
335 #if defined(TRACE)
336 if (condition) write_(xtd::ustring::format("{}", message));
337 #endif
338 }
345 template<typename object_t>
346 static void write_if(bool condition, const object_t& message, const xtd::ustring& category) {
347 #if defined(TRACE)
348 if (condition) write_(xtd::ustring::format("{}", message), category);
349 #endif
350 }
351
356 static void write_line() {
357 #if defined(TRACE)
358 write_line_("");
359 #endif
360 }
365 static void write_line(const xtd::ustring& message) {
366 #if defined(TRACE)
367 write_line_(message);
368 #endif
369 }
374 template<typename object_t>
375 static void write_line(const object_t& message) {
376 #if defined(TRACE)
377 write_line_(xtd::ustring::format("{}", message));
378 #endif
379 }
386 template<typename object_t>
387 static void write_line(const object_t& message, const xtd::ustring& category) {
388 #if defined(TRACE)
389 write_line_(xtd::ustring::format("{}", message), category);
390 #endif
391 }
396 template<typename ...args_t>
397 static void write_line(const xtd::ustring& format, args_t&& ... args) {
398 #if defined(TRACE)
399 write_line_(xtd::ustring::format(format, args...));
400 #endif
401 }
403 template<typename ...args_t>
404 static void write_line(const char* format, args_t&& ... args) {
405 #if defined(TRACE)
406 write_line_(xtd::ustring::format(format, args...));
407 #endif
408 }
410
416 static void write_line_if(bool condition, const xtd::ustring& message) {
417 #if defined(TRACE)
418 if (condition) write_line_(message);
419 #endif
420 }
426 template<typename object_t>
427 static void write_line_if(bool condition, const object_t& message) {
428 #if defined(TRACE)
429 if (condition) write_line_(xtd::ustring::format("{}", message));
430 #endif
431 }
438 template<typename object_t>
439 static void write_line_if(bool condition, const object_t& message, const xtd::ustring& category) {
440 #if defined(TRACE)
441 if (condition) write_line_(xtd::ustring::format("{}", message), category);
442 #endif
443 }
445
447 static inline bool __should_aborted__(bool condition) { return __should_aborted__(condition, "", csf_); }
448 static inline bool __should_aborted__(bool condition, const xtd::ustring& message) {return __should_aborted__(condition, message, csf_);}
449 static inline bool __should_aborted__(bool condition, const xtd::diagnostics::stack_frame& stack_frame) {return __should_aborted__(condition, "", stack_frame);}
450 static inline bool __should_aborted__(bool condition, const xtd::ustring& message, const xtd::diagnostics::stack_frame& stack_frame) {return __should_aborted__(condition, message, "", stack_frame);}
451 static inline bool __should_aborted__(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message) {return __should_aborted__(condition, message, detail_message, csf_);}
452 static inline bool __should_aborted__(bool condition, const xtd::ustring& message, const xtd::ustring& detail_message, const xtd::diagnostics::stack_frame& stack_frame) {
453 #if defined(TRACE)
454 auto result = xtd::diagnostics::debug::assert_dialog(condition, message, detail_message, stack_frame);
456 if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
457 #endif
458 return false;
459 }
461
462 private:
463 static void fail__(const xtd::ustring& message);
464 static void fail__(const xtd::ustring& message, const xtd::ustring& detail_message);
465 static void flush_();
466 static void trace_event_(trace_event_type trace_event_type, const xtd::ustring& message);
467 static void write_(const xtd::ustring& message);
468 static void write_(const xtd::ustring& message, const xtd::ustring& category);
469 static void write_line_(const xtd::ustring& message);
470 static void write_line_(const xtd::ustring& message, const xtd::ustring& category);
471
472 inline static bool auto_flush_ = false;
473 inline static uint32 indent_level_ = 0;
474 inline static uint32 indent_size_ = 4;
475 static listener_collection& listeners_;
476 inline static bool use_global_lock_ = true;
477 static xtd::ustring source_name_;
478 };
479 }
480}
Provides the default output methods and behavior for tracing.
Definition default_trace_listener.h:31
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition stack_frame.h:37
Represents a collection of xtd::diagnostics::trace_listener.
Definition trace_listener_collection.h:27
Provides a set of methods and properties that help you debug the execution of your code....
Definition trace.h:38
static void write(const object_t &message, const xtd::ustring &category)
Writes a category name and message to the trace listeners in the listeners collection.
Definition trace.h:293
static void write_line()
Writes a line terminator to the trace listeners in the listeners collection.
Definition trace.h:356
static void write(const xtd::ustring &format, args_t &&... args)
Writes a formatted string to the trace listeners in the listeners collection.
Definition trace.h:304
static void trace_information(const xtd::ustring &message, const objects &... args)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition trace.h:238
static bool auto_flush() noexcept
Gets whether Flush should be called on the Listeners after every write.
static void fail(const xtd::ustring &message, const xtd::ustring &detail_message)
Emits an error message and a detailed error message.
Definition trace.h:163
static void write_line_if(bool condition, const object_t &message)
Writes a message followed by a line terminator to the trace listeners in the Listeners collection if ...
Definition trace.h:427
static void trace_error(const xtd::ustring &message, const objects &... args)
Writes an error message to the trace listeners in the listeners collection using the specified array ...
Definition trace.h:219
static void write_line(const xtd::ustring &message)
Writes a message followed by a line terminator to the trace listeners in the listeners collection.
Definition trace.h:365
static void trace_warning(const xtd::ustring &message)
Writes a warning message to the trace listeners in the listeners collection using the specified messa...
Definition trace.h:247
static void trace_error(const xtd::ustring &message)
Writes an error message to the trace listeners in the Listeners collection using the specified messag...
Definition trace.h:209
static void write(const object_t &message)
Writes a message to the trace listeners in the listeners collection.
Definition trace.h:281
static void write_if(bool condition, const object_t &message)
Writes a message to the trace listeners in the Listeners collection if a condition is true.
Definition trace.h:334
static void write_if(bool condition, const object_t &message, const xtd::ustring &category)
Writes a category name and message to the trace listeners in the Listeners collection if a condition ...
Definition trace.h:346
static void print(const xtd::ustring &format, args_t &&... args)
Writes a formatted string followed by a line terminator to the trace listeners in the listeners colle...
Definition trace.h:192
static void trace_warning(const xtd::ustring &message, const objects &... args)
Writes a warning message to the trace listeners in the listeners collection using the specified array...
Definition trace.h:257
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition trace.h:170
static void write_line(const object_t &message, const xtd::ustring &category)
Writes a category name and message followed by a line terminator to the trace listeners in the listen...
Definition trace.h:387
static void unindent() noexcept
Decreases the current indent_level by one.
static void indent() noexcept
Increases the current indent_level by one.
static void trace_information(const xtd::ustring &message)
Writes an informational message to the trace listeners in the listeners collection using the specifie...
Definition trace.h:228
static void write_line_if(bool condition, const xtd::ustring &message)
Writes a message followed by a line terminator to the trace listeners in the Listeners collection if ...
Definition trace.h:416
static void write_line_if(bool condition, const object_t &message, const xtd::ustring &category)
Writes a category name and message followed by a line terminator to the trace listeners in the Listen...
Definition trace.h:439
static void write_line(const object_t &message)
Writes a message followed by a line terminator to the trace listeners in the listeners collection.
Definition trace.h:375
static void write_if(bool condition, const xtd::ustring &message)
Writes a message to the trace listeners in the Listeners collection if a condition is true.
Definition trace.h:323
static void write_line(const xtd::ustring &format, args_t &&... args)
Writes a formatted string followed by a line terminator to the trace listeners in the listeners colle...
Definition trace.h:397
static void exit()
Terminates this process and returns an exit code to the operating system.
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
Represents the version number of an assembly, operating system, or the xtd. This class cannot be inhe...
Definition version.h:110
Contains xtd::diagnostics::debug class.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition ustring.h:1131
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.h:37
#define core_export_
Define shared library export.
Definition core_export.h:13
#define csf_
Provides information about the current stack frame.
Definition current_stack_frame.h:30
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition types.h:241
@ retry
The assert dialog return value is Retry (usually sent from a button labeled Retry).
@ abort
The assert dialog return value is Abort (usually sent from a button labeled Abort).
@ print
The PRINT key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10