xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
trace.h
Go to the documentation of this file.
1 #pragma once
5 #include "debug.h"
6 
8 namespace xtd {
10  namespace diagnostics {
31  class core_export_ trace static_ {
32  public:
35 
40  static bool auto_flush();
45  static void auto_flush(bool auto_flush);
46 
50  static uint32_t indent_level();
54  static void indent_level(uint32_t indent_level);
55 
59  static uint32_t indent_size();
63  static void indent_size(uint32_t indent_size);
64 
69  static listener_collection& listeners();
74  static void listeners(const listener_collection& listeners);
75 
80  static bool show_assert_dialog();
85  static void show_assert_dialog(bool show_assert_dialog);
86 
90  static bool use_global_lock();
94  static void use_global_lock(bool use_global_lock);
95 
101  static void cassert(bool condition);
105  static void cassert(bool condition, const xtd::ustring& message);
110  static void cassert(bool condition, const xtd::ustring& message, const xtd::diagnostics::stack_frame& stack_frame);
114  static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame);
115 
120  static void fail(const xtd::ustring& message) {
121 #if defined(TRACE)
122  fail__(message);
123 #endif
124  }
130  static void fail(const xtd::ustring& message, const xtd::ustring& detail_message) {
131 #if defined(TRACE)
132  fail__(message, detail_message);
133 #endif
134  }
135 
137  static void flush() {
138 #if defined(TRACE)
139  flush_();
140 #endif
141  }
142 
144  static void indent();
145 
149  static void print(const xtd::ustring& message) {
150 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
151  write_line_(message);
152 #endif
153  }
158  template<typename ...args_t>
159  static void print(const xtd::ustring& format, args_t&&... args) {
160 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
161  write_line_(xtd::ustring::format(format, args...));
162 #endif
163  }
165  template<typename ...args_t>
166  static void print(const char* format, args_t&&... args) {
167 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
168  write_line_(xtd::ustring::format(format, args...));
169 #endif
170  }
172 
176  static void trace_error(const xtd::ustring& message) {
177 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
178  trace_event_(trace_event_type::error, message);
179 #endif
180  }
185  template<typename ...objects>
186  static void trace_error(const xtd::ustring& message, const objects& ... args) {
187 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
188  trace_event_(trace_event_type::error, message, args...);
189 #endif
190  }
191 
195  static void trace_information(const xtd::ustring& message) {
196 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
197  trace_event_(trace_event_type::information, message);
198 #endif
199  }
204  template<typename ...objects>
205  static void trace_information(const xtd::ustring& message, const objects& ... args) {
206 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
207  trace_event_(trace_event_type::information, xtd::ustring::format(message, args...));
208 #endif
209  }
210 
214  static void trace_warning(const xtd::ustring& message) {
215 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
216  trace_event_(trace_event_type::warning, message);
217 #endif
218  }
223  template<typename ...objects>
224  static void trace_warning(const xtd::ustring& message, const objects& ... args) {
225 #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
226  trace_event_(trace_event_type::warning, xtd::ustring::format(message, args...));
227 #endif
228  }
229 
231  static void unindent();
232 
237  static void write(const xtd::ustring& message) {
238 #if defined(TRACE)
239  write_(message);
240 #endif
241  }
242 
247  template<typename object>
248  static void write(const object& message) {
249 #if defined(TRACE)
250  write_(xtd::ustring::format("", message));
251 #endif
252  }
259  template<typename object>
260  static void write(const object& message, const xtd::ustring& category) {
261 #if defined(TRACE)
262  write_(xtd::ustring::format("", message), category);
263 #endif
264  }
270  template<typename ...args_t>
271  static void write(const xtd::ustring& format, args_t&&... args) {
272 #if defined(TRACE)
273  write_(ustring::format(format, args...));
274 #endif
275  }
277  template<typename ...args_t>
278  static void write(const char* format, args_t&&... args) {
279 #if defined(TRACE)
280  write_(ustring::format(format, args...));
281 #endif
282  }
284 
290  static void write_if(bool condition, const xtd::ustring& message) {
291 #if defined(TRACE)
292  if (condition) write_(message);
293 #endif
294  }
300  template<typename object>
301  static void write_if(bool condition, const object& message) {
302 #if defined(TRACE)
303  if (condition) write_(xtd::ustring::format("", message));
304 #endif
305  }
312  template<typename object>
313  static void write_if(bool condition, const object& message, const xtd::ustring& category) {
314 #if defined(TRACE)
315  if (condition) write_(xtd::ustring::format("", message), category);
316 #endif
317  }
318 
323  static void write_line() {
324 #if defined(TRACE)
325  write_line_("");
326 #endif
327  }
332  static void write_line(const xtd::ustring& message) {
333 #if defined(TRACE)
334  write_line_(message);
335 #endif
336  }
341  template<typename object>
342  static void write_line(const object& message) {
343 #if defined(TRACE)
344  write_line_(xtd::ustring::format("", message));
345 #endif
346  }
353  template<typename object>
354  static void write_line(const object& message, const xtd::ustring& category) {
355 #if defined(TRACE)
356  write_line_(xtd::ustring::format("", message), category);
357 #endif
358  }
363  template<typename ...args_t>
364  static void write_line(const xtd::ustring& format, args_t&&... args) {
365 #if defined(TRACE)
366  write_line_(xtd::ustring::format(format, args...));
367 #endif
368  }
370  template<typename ...args_t>
371  static void write_line(const char* format, args_t&&... args) {
372 #if defined(TRACE)
373  write_line_(xtd::ustring::format(format, args...));
374 #endif
375  }
377 
383  static void write_line_if(bool condition, const xtd::ustring& message) {
384 #if defined(TRACE)
385  if (condition) write_line_(message);
386 #endif
387  }
393  template<typename object>
394  static void write_line_if(bool condition, const object& message) {
395 #if defined(TRACE)
396  if (condition) write_line_(xtd::ustring::format("", message));
397 #endif
398  }
405  template<typename object>
406  static void write_line_if(bool condition, const object& message, const xtd::ustring& category) {
407 #if defined(TRACE)
408  if (condition) write_line_(xtd::ustring::format("", message), category);
409 #endif
410  }
411 
413  static inline bool __should_aborted__(bool condition) { return __should_aborted__(condition, "", csf_); }
414  static inline bool __should_aborted__(bool condition, const xtd::ustring& message) { return __should_aborted__(condition, message, csf_); }
415  static inline bool __should_aborted__(bool condition, const xtd::diagnostics::stack_frame& stack_frame) { return __should_aborted__(condition, "", stack_frame); }
416  static inline bool __should_aborted__(bool condition, const xtd::ustring& message, const xtd::diagnostics::stack_frame& stack_frame) {
417 #if defined(TRACE)
418  auto result = xtd::diagnostics::debug::assert_dialog(condition, message, stack_frame);
420  if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
421 #endif
422  return false;
423  }
425 
426  private:
427  static void fail__(const xtd::ustring& message);
428  static void fail__(const xtd::ustring& message, const xtd::ustring& detail_message);
429  static void flush_();
430  static void trace_event_(trace_event_type trace_event_type, const xtd::ustring& message);
431  static void write_(const xtd::ustring& message);
432  static void write_(const xtd::ustring& message, const xtd::ustring& category);
433  static void write_line_(const xtd::ustring& message);
434  static void write_line_(const xtd::ustring& message, const xtd::ustring& category);
435 
436  inline static bool auto_flush_ = false;
437  inline static unsigned int indent_level_ = 0;
438  inline static unsigned int indent_size_ = 4;
439  static listener_collection& listeners_;
440  static bool& show_assert_dialog_;
441  inline static bool use_global_lock_ = true;
442  static std::mutex global_lock_;
443  static xtd::ustring source_name_;
444  };
445  }
446 }
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:271
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:364
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:205
static void write(const object &message)
Writes a message to the trace listeners in the listeners collection.
Definition: trace.h:248
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:224
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition: trace.h:137
Contains xtd::diagnostics::debug class.
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:195
#define static_
This keyword is use to represent a static object. A static object can&#39;t be instantiated (constructors...
Definition: static.h:38
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:186
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
static void fail(const xtd::ustring &message)
Emits the specified error message.
Definition: trace.h:120
#define csf_
Provides information about the current stack frame.
Definition: stack_frame.h:213
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
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:290
The assert dialog return value is Abort (usually sent from a button labeled Abort).
static void write_if(bool condition, const object &message)
Writes a message to the trace listeners in the Listeners collection if a condition is true...
Definition: trace.h:301
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:383
Allows critical, error, and warning events through.
static void print(const xtd::ustring &message)
Writes a message followed by a line terminator to the trace listeners in the listeners collection...
Definition: trace.h:149
static void write_line()
Writes a line terminator to the trace listeners in the listeners collection.
Definition: trace.h:323
static void write_line_if(bool condition, const object &message)
Writes a message followed by a line terminator to the trace listeners in the Listeners collection if ...
Definition: trace.h:394
static void write_line_if(bool condition, const object &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:406
static void write_line(const object &message)
Writes a message followed by a line terminator to the trace listeners in the listeners collection...
Definition: trace.h:342
static void exit(int exit_code)
Terminates this process and returns an exit code to the operating system.
Definition: environment.h:321
Represents a collection of xtd::diagnostics::trace_listener.
Definition: trace_listener_collection.h:19
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:214
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition: stack_frame.h:29
The assert dialog return value is Retry (usually sent from a button labeled Retry).
static void write(const object &message, const xtd::ustring &category)
Writes a category name and message to the trace listeners in the listeners collection.
Definition: trace.h:260
static void write_if(bool condition, const object &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:313
Provides a set of methods and properties that help you debug the execution of your code...
Definition: trace.h:31
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:689
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:159
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:176
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:332
static void write_line(const object &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:354
static void write(const xtd::ustring &message)
Writes a message to the trace listeners in the listeners collection.
Definition: trace.h:237
static void fail(const xtd::ustring &message, const xtd::ustring &detail_message)
Emits an error message and a detailed error message.
Definition: trace.h:130
trace_event_type
Identifies the type of event that has caused the trace.
Definition: trace_event_type.h:18