xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
xtd::diagnostics::console_trace_listener Class Reference

#include <console_trace_listener.h>

Definition

Directs tracing or debugging output to either the standard output or the standard error stream.

Namespace
xtd::diagnostics
Library
xtd.core
Examples
The following example shows how to use xtd::diagnostics::console_trace_listener class.
#define DEBUG // Force debug mode even if example is builded in release.
#include <memory>
#include <thread>
#include <xtd/xtd>
using namespace std;
using namespace std::literals;
using namespace std::this_thread;
using namespace xtd::diagnostics;
int main() {
debug::listeners({make_shared<console_trace_listener>()});
for (auto step = 1; step <= 10; step++) {
debug::write_line("working step {}...", step);
sleep_for(300ms);
}
}
// This code produces the following output :
//
// Begin
// working step 1...
// working step 2...
// working step 3...
// working step 4...
// working step 5...
// working step 6...
// working step 7...
// working step 8...
// working step 9...
// working step 10...
// End
static void indent()
Increases the current indent_level by one.
static void write_line()
Writes a line terminator to the trace listeners in the listeners collection.
Definition: debug.h:336
static listener_collection & listeners()
Gets the collection of listeners that is monitoring the trace output.
static void unindent()
Decreases the current indent_level by one.
The xtd::diagnostics namespace provides classes that allow you to interact with system processes,...
Definition: assert_dialog_result.h:10

Inherits xtd::diagnostics::ostream_trace_listener.

Public Member Functions

 console_trace_listener ()
 Initializes a new instance of the xtd::diagnostics::console_trace_listener class with trace output written to the standard output stream.
 
 console_trace_listener (bool use_error_stream)
 Initializes a new instance of the xtd::diagnostics::console_trace_listener class with an option to write trace output to the standard output stream or the standard error stream.
 
- Public Member Functions inherited from xtd::diagnostics::ostream_trace_listener
 ostream_trace_listener (const std::ostream &ostream)
 Initializes a new instance of the xtd::diagnostics::ostream_trace_listener class with a specified ostream.
 
void close () override
 When overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output.
 
void flush () override
 When overridden in a derived class, flushes the output buffer.
 
virtual const std::ostream & ostream () const
 Gets the underlying stream.
 
virtual void ostream (const std::ostream &ostream)
 Sets the underlying stream.
 
void write (const xtd::ustring &message) override
 Writes the message to the listener you create when you implement the trace_listener class.
 
void write_line (const xtd::ustring &message) override
 Writes the message to the listener you create when you implement the trace_listener class followed by a line terminator.followed by a line terminator.
 
- Public Member Functions inherited from xtd::diagnostics::trace_listener
 trace_listener ()=default
 Initializes a new instance of the trace_listener class.
 
 trace_listener (const xtd::ustring &name)
 Initializes a new instance of the trace_listener class using the specified name as the listener.
 
virtual void close ()
 When overridden in a derived class, closes the output stream so it no longer receives tracing or debugging output.
 
virtual void fail (const xtd::ustring &message)
 Emits an error message to the listener you create when you implement the TraceListener class.
 
virtual void fail (const xtd::ustring &message, const xtd::ustring &detail_message)
 Emits the specified error message.
 
virtual void flush ()
 When overridden in a derived class, flushes the output buffer.
 
unsigned int indent_level () const
 Gets the indent level.
 
void indent_level (unsigned int indent_level)
 Sets the indent level.
 
unsigned int indent_size () const
 Gets the number of spaces in an indent.
 
void indent_size (unsigned int indent_size)
 Sets the number of spaces in an indent.
 
virtual bool is_thread_safe () const
 Gets a value indicating whether the trace listener is thread safe.
 
const xtd::ustringname () const
 Gets or sets a name for this TraceListener.
 
void name (const xtd::ustring &name)
 Sets a name for this TraceListener.
 
template<typename object >
void trace_data (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::ustring &source, const xtd::diagnostics::trace_event_type &event_type, int id, const object &data)
 Writes trace information, a data object and event information to the listener specific output.
 
template<typename ... objects>
void trace_data (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::ustring &source, const xtd::diagnostics::trace_event_type &event_type, int id, const objects &... data)
 Writes trace information, an array of data objects and event information to the listener specific output.
 
template<typename object >
void trace_data (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::ustring &source, const xtd::diagnostics::trace_event_type &event_type, int id, const std::vector< object > &data)
 Writes trace information, a data object and event information to the listener specific output.
 
virtual void trace_event (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::ustring &source, const xtd::diagnostics::trace_event_type &event_type, int id)
 Writes trace and event information to the listener specific output.
 
template<typename ... objects>
void trace_event (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::ustring &source, const xtd::diagnostics::trace_event_type &event_type, int id, const xtd::ustring &format, const objects &... args)
 Writes trace information, a formatted array of objects and event information to the listener specific output.
 
virtual void trace_event (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::ustring &source, const xtd::diagnostics::trace_event_type &event_type, int id, const xtd::ustring &message)
 Writes trace information, a message, and event information to the listener specific output.
 
const trace_optionstrace_output_options () const
 Gets the trace output options.
 
void trace_output_options (const trace_options &trace_output_options)
 Sets the trace output options.
 
template<typename activity_id_type >
void trace_transfer (const xtd::diagnostics::trace_event_cache &event_cache, const xtd::ustring &source, int id, const xtd::ustring &message, const activity_id_type &related_activity_id)
 Writes trace information, a message, a related activity identity and event information to the listener specific output.
 
template<typename object >
void write (const object &o)
 Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class.
 
template<typename object >
void write (const object &o, const xtd::ustring &category)
 Writes a category name and the value of the object's ToString method to the listener you create when you implement the TraceListener class.
 
virtual void write (const xtd::ustring &message)=0
 Writes the message to the listener you create when you implement the trace_listener class.
 
template<typename object >
void write_line (const object &o)
 Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class.
 
template<typename object >
void write_line (const object &o, const xtd::ustring &category)
 Writes a category name and the value of the object's ToString method to the listener you create when you implement the TraceListener class.
 
virtual void write_line (const xtd::ustring &message)=0
 Writes the message to the listener you create when you implement the trace_listener class followed by a line terminator.followed by a line terminator.
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance.
 
virtual xtd::ustring to_string () const noexcept
 Returns a std::string that represents the current object.
 

Additional Inherited Members

- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 
- Protected Member Functions inherited from xtd::diagnostics::trace_listener
bool need_indent () const
 Gets a value indicating whether to indent the output.
 
void need_indent (bool need_indent)
 Sets a value indicating whether to indent the output.
 
void thread_safe (bool thread_safe)
 Sets a value indicating whether the trace listener is thread safe.
 
virtual void write_indent ()
 Writes the indent to the listener you create when you implement this class, and resets the NeedIndent property to false.
 

Constructor & Destructor Documentation

◆ console_trace_listener() [1/2]

xtd::diagnostics::console_trace_listener::console_trace_listener ( )

Initializes a new instance of the xtd::diagnostics::console_trace_listener class with trace output written to the standard output stream.

Remarks
This constructor initializes a xtd::diagnostics::console_trace_listener object to write messages to either the std::cout or the std::cerr stream. Its xtd::diagnostics:console_trace_listener::name property is initialized to an empty string ("").

◆ console_trace_listener() [2/2]

xtd::diagnostics::console_trace_listener::console_trace_listener ( bool  use_error_stream)

Initializes a new instance of the xtd::diagnostics::console_trace_listener class with an option to write trace output to the standard output stream or the standard error stream.

Parameters
use_error_streamtrue to write tracing and debugging output to the standard error stream; false to write tracing and debugging output to the standard output stream.
Remarks
This constructor initializes a xtd::diagnostics::console_trace_listener object to write messages to either the std::cout or the std::cerr stream. Its xtd::diagnostics::console_trace_listener::name property is initialized to an empty string ("").

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