xtd - Reference Guide 0.2.0
trace.h
Go to the documentation of this file.
1 #pragma once
5 #include "debug.h"
6 
8 namespace xtd {
10  namespace diagnostics {
36  class core_export_ trace static_ {
37  public:
39 
44 
46 
52  static bool auto_flush();
57  static void auto_flush(bool auto_flush);
58 
62  static uint32_t indent_level();
66  static void indent_level(uint32_t indent_level);
67 
71  static uint32_t indent_size();
75  static void indent_size(uint32_t indent_size);
76 
81  static listener_collection& listeners();
86  static void listeners(const listener_collection& listeners);
87 
92  static bool show_assert_dialog();
97  static void show_assert_dialog(bool show_assert_dialog);
98 
102  static bool use_global_lock();
106  static void use_global_lock(bool use_global_lock);
108 
110 
117  static void cassert(bool condition);
121  static void cassert(bool condition, const xtd::ustring& message);
126  static void cassert(bool condition, const xtd::ustring& message, const xtd::diagnostics::stack_frame& stack_frame);
130  static void cassert(bool condition, const xtd::diagnostics::stack_frame& stack_frame);
131 
136  static void fail(const xtd::ustring& message) {
137  #if defined(TRACE)
138  fail__(message);
139  #endif
140  }
146  static void fail(const xtd::ustring& message, const xtd::ustring& detail_message) {
147  #if defined(TRACE)
148  fail__(message, detail_message);
149  #endif
150  }
151 
153  static void flush() {
154  #if defined(TRACE)
155  flush_();
156  #endif
157  }
158 
160  static void indent();
161 
165  static void print(const xtd::ustring& message) {
166  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
167  write_line_(message);
168  #endif
169  }
174  template<typename ...args_t>
175  static void print(const xtd::ustring& format, args_t&& ... args) {
176  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
177  write_line_(xtd::ustring::format(format, args...));
178  #endif
179  }
181  template<typename ...args_t>
182  static void print(const char* format, args_t&& ... args) {
183  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
184  write_line_(xtd::ustring::format(format, args...));
185  #endif
186  }
188 
192  static void trace_error(const xtd::ustring& message) {
193  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
194  trace_event_(trace_event_type::error, message);
195  #endif
196  }
201  template<typename ...objects>
202  static void trace_error(const xtd::ustring& message, const objects& ... args) {
203  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
204  trace_event_(trace_event_type::error, message, args...);
205  #endif
206  }
207 
211  static void trace_information(const xtd::ustring& message) {
212  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
213  trace_event_(trace_event_type::information, message);
214  #endif
215  }
220  template<typename ...objects>
221  static void trace_information(const xtd::ustring& message, const objects& ... args) {
222  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
223  trace_event_(trace_event_type::information, xtd::ustring::format(message, args...));
224  #endif
225  }
226 
230  static void trace_warning(const xtd::ustring& message) {
231  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
232  trace_event_(trace_event_type::warning, message);
233  #endif
234  }
239  template<typename ...objects>
240  static void trace_warning(const xtd::ustring& message, const objects& ... args) {
241  #if !defined(NDEBUG) || defined(DEBUG) || defined(TRACE)
242  trace_event_(trace_event_type::warning, xtd::ustring::format(message, args...));
243  #endif
244  }
245 
247  static void unindent();
248 
253  static void write(const xtd::ustring& message) {
254  #if defined(TRACE)
255  write_(message);
256  #endif
257  }
258 
263  template<typename object>
264  static void write(const object& message) {
265  #if defined(TRACE)
266  write_(xtd::ustring::format("", message));
267  #endif
268  }
275  template<typename object>
276  static void write(const object& message, const xtd::ustring& category) {
277  #if defined(TRACE)
278  write_(xtd::ustring::format("", message), category);
279  #endif
280  }
286  template<typename ...args_t>
287  static void write(const xtd::ustring& format, args_t&& ... args) {
288  #if defined(TRACE)
289  write_(ustring::format(format, args...));
290  #endif
291  }
293  template<typename ...args_t>
294  static void write(const char* format, args_t&& ... args) {
295  #if defined(TRACE)
296  write_(ustring::format(format, args...));
297  #endif
298  }
300 
306  static void write_if(bool condition, const xtd::ustring& message) {
307  #if defined(TRACE)
308  if (condition) write_(message);
309  #endif
310  }
316  template<typename object>
317  static void write_if(bool condition, const object& message) {
318  #if defined(TRACE)
319  if (condition) write_(xtd::ustring::format("", message));
320  #endif
321  }
328  template<typename object>
329  static void write_if(bool condition, const object& message, const xtd::ustring& category) {
330  #if defined(TRACE)
331  if (condition) write_(xtd::ustring::format("", message), category);
332  #endif
333  }
334 
339  static void write_line() {
340  #if defined(TRACE)
341  write_line_("");
342  #endif
343  }
348  static void write_line(const xtd::ustring& message) {
349  #if defined(TRACE)
350  write_line_(message);
351  #endif
352  }
357  template<typename object>
358  static void write_line(const object& message) {
359  #if defined(TRACE)
360  write_line_(xtd::ustring::format("", message));
361  #endif
362  }
369  template<typename object>
370  static void write_line(const object& message, const xtd::ustring& category) {
371  #if defined(TRACE)
372  write_line_(xtd::ustring::format("", message), category);
373  #endif
374  }
379  template<typename ...args_t>
380  static void write_line(const xtd::ustring& format, args_t&& ... args) {
381  #if defined(TRACE)
382  write_line_(xtd::ustring::format(format, args...));
383  #endif
384  }
386  template<typename ...args_t>
387  static void write_line(const char* format, args_t&& ... args) {
388  #if defined(TRACE)
389  write_line_(xtd::ustring::format(format, args...));
390  #endif
391  }
393 
399  static void write_line_if(bool condition, const xtd::ustring& message) {
400  #if defined(TRACE)
401  if (condition) write_line_(message);
402  #endif
403  }
409  template<typename object>
410  static void write_line_if(bool condition, const object& message) {
411  #if defined(TRACE)
412  if (condition) write_line_(xtd::ustring::format("", message));
413  #endif
414  }
421  template<typename object>
422  static void write_line_if(bool condition, const object& message, const xtd::ustring& category) {
423  #if defined(TRACE)
424  if (condition) write_line_(xtd::ustring::format("", message), category);
425  #endif
426  }
428 
430  static inline bool __should_aborted__(bool condition) { return __should_aborted__(condition, "", csf_); }
431  static inline bool __should_aborted__(bool condition, const xtd::ustring& message) { return __should_aborted__(condition, message, csf_); }
432  static inline bool __should_aborted__(bool condition, const xtd::diagnostics::stack_frame& stack_frame) { return __should_aborted__(condition, "", stack_frame); }
433  static inline bool __should_aborted__(bool condition, const xtd::ustring& message, const xtd::diagnostics::stack_frame& stack_frame) {
434  #if defined(TRACE)
435  auto result = xtd::diagnostics::debug::assert_dialog(condition, message, stack_frame);
437  if (result == xtd::diagnostics::assert_dialog_result::retry) return true;
438  #endif
439  return false;
440  }
442 
443  private:
444  static void fail__(const xtd::ustring& message);
445  static void fail__(const xtd::ustring& message, const xtd::ustring& detail_message);
446  static void flush_();
447  static void trace_event_(trace_event_type trace_event_type, const xtd::ustring& message);
448  static void write_(const xtd::ustring& message);
449  static void write_(const xtd::ustring& message, const xtd::ustring& category);
450  static void write_line_(const xtd::ustring& message);
451  static void write_line_(const xtd::ustring& message, const xtd::ustring& category);
452 
453  inline static bool auto_flush_ = false;
454  inline static unsigned int indent_level_ = 0;
455  inline static unsigned int indent_size_ = 4;
456  static listener_collection& listeners_;
457  static bool& show_assert_dialog_;
458  inline static bool use_global_lock_ = true;
459  static std::mutex global_lock_;
460  static xtd::ustring source_name_;
461  };
462  }
463 }
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:287
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:380
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:221
static void write(const object &message)
Writes a message to the trace listeners in the listeners collection.
Definition: trace.h:264
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:240
static void flush()
Flushes the output buffer and causes buffered data to write to the listeners collection.
Definition: trace.h:153
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:211
#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:202
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:136
#define csf_
Provides information about the current stack frame.
Definition: stack_frame.h:231
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:50
Warning Noncritical problem.
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:306
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:317
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:399
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:165
static void write_line()
Writes a line terminator to the trace listeners in the listeners collection.
Definition: trace.h:339
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:410
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:422
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:358
static void exit(int exit_code)
Terminates this process and returns an exit code to the operating system.
Definition: environment.h:342
Represents a collection of xtd::diagnostics::trace_listener.
Definition: trace_listener_collection.h:24
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:230
Provides information about a xtd::diagnostics::stack_frame, which represents a function call on the c...
Definition: stack_frame.h:34
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:276
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:329
Provides a set of methods and properties that help you debug the execution of your code...
Definition: trace.h:36
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:708
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:175
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:192
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:348
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:370
static void write(const xtd::ustring &message)
Writes a message to the trace listeners in the listeners collection.
Definition: trace.h:253
static void fail(const xtd::ustring &message, const xtd::ustring &detail_message)
Emits an error message and a detailed error message.
Definition: trace.h:146
trace_event_type
Identifies the type of event that has caused the trace.
Definition: trace_event_type.h:21