xtd - Reference Guide  0.1.0
Modern c++17 framework to create console, gui and unit test applications on Windows, macOS and Linux.
xtd::diagnostics::trace Class Reference

Provides a set of methods and properties that help you debug the execution of your code. This class cannot be inherited. More...

#include <trace.h>

Static Public Member Functions

static void assert (bool condition)
 Checks for a condition; if the condition is false, displays a message box that shows the call stack. More...
 
static void assert (bool condition, const std::string &message)
 Checks for a condition; if the condition is false, displays a message box that shows the call stack. More...
 
static bool auto_flush ()
 Get whether Flush should be called on the Listeners after every write. More...
 
static void auto_flush (bool auto_flush)
 Sets whether Flush should be called on the Listeners after every write. More...
 
static void fail (const std::string &message)
 
static void fail (const std::string &message, const std::string &detail_message)
 
static void flush ()
 
static void indent ()
 
static unsigned int indent_level ()
 Gets the indent level. More...
 
static void indent_level (unsigned int indent_level)
 Sets the indent level. More...
 
static unsigned int indent_size ()
 Gets the number of spaces in an indent. More...
 
static void indent_size (unsigned int indent_size)
 Sets the number of spaces in an indent. More...
 
static trace_listener_collection & listeners ()
 Gets the collection of listeners that is monitoring the trace output. More...
 
static void listeners (const trace_listener_collection &listeners)
 Sets the collection of listeners that is monitoring the trace output. More...
 
static void trace_error (const std::string &message)
 
template<typename ... objects>
static void trace_error (const std::string &message, const objects &... args)
 
static void trace_information (const std::string &message)
 
template<typename ... objects>
static void trace_information (const std::string &message, const objects &... args)
 
static void trace_warning (const std::string &message)
 
template<typename ... objects>
static void trace_warning (const std::string &message, const objects &... args)
 
static void unindent ()
 
static bool use_global_lock ()
 Gets a value indicating whether the global lock should be used. More...
 
static void use_global_lock (bool use_global_lock)
 Sets a value indicating whether the global lock should be used. More...
 
static void write (const std::string &message)
 
template<typename object >
static void write (const object &message)
 
template<typename object >
static void write (const object &message, const std::string &category)
 
template<typename ... args_t>
static void write (const std::string &format, args_t &&... args)
 
static void write_if (bool condition, const std::string &message)
 
template<typename object >
static void write_if (bool condition, const object &message)
 
template<typename object >
static void write_if (bool condition, const object &message, const std::string &category)
 
static void write_line ()
 
static void write_line (const std::string &message)
 
template<typename object >
static void write_line (const object &message)
 
template<typename object >
static void write_line (const object &message, const std::string &category)
 
template<typename ... args_t>
static void write_line (const std::string &format, args_t &&... args)
 
static void write_line_if (bool condition, const std::string &message)
 
template<typename object >
static void write_line_if (bool condition, const object &message)
 
template<typename object >
static void write_line_if (bool condition, const object &message, const std::string &category)
 

Detailed Description

Provides a set of methods and properties that help you debug the execution of your code. This class cannot be inherited.

Remarks
You can use the properties and methods in the debug class to instrument release builds. Instrumentation allows you to monitor the health of your application running in real-life settings. Tracing helps you isolate problems and fix them without disturbing a running system.
This class provides methods to display an assert dialog box, and to emit an assertion that will always Fail. This class provides write methods in the following variations: write, write_line, write_if, and write_line_if.
The boolean_switch and trace_switch classes provide means to dynamically control the tracing output. You can modify the values of these switches without recompiling your application. For information on using the configuration file to set a switch, see the switch class and the trace_switches topic.
You can customize the tracing output's target by adding trace_listener instances to or removing instances from the listeners collection. The listeners collection is shared by both the debug and the trace classes; adding a trace listener to either class adds the listener to both. By default, trace output is emitted using the default_trace_listener class.
Note
Adding a trace listener to the listeners collection can cause an exception to be thrown while tracing, if a resource used by the trace listener is not available. The conditions and the exception thrown depend on the trace listener and cannot be enumerated in this topic. It may be useful to place calls to the debug methods in try/catch blocks to detect and handle any exceptions from trace listeners.
Remarks
The debug class provides properties to get or set the level of indent, the indent_size, and whether to auto_flush after each write.
You must enable debug mode to use a trace listener. The syntax is compiler specific. If you use other than cmake to manage your build, refer to the documentation of your build nanager.
  • To enable debug mode with cmake, add the add_definitions(-DDEBUG) command line in the CMakeLists.txt of your porject, or you can add #define DEBUG to the top of your file.
To activete your code if DEBUG is defined, you must enclose calls to the methods of Debug in an #if defined(DEBUG) ... #endif block, and add the /DDEBUG option to the compiler command line or add #define DEBUG to the file.
Examples
The following example uses debug to indicate the beginning and the end of a program's execution. The example also uses the debug::indent and debug::unindent methods to distinguish the tracing output.

The documentation for this class was generated from the following file: