|
TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
|
A thread-safe tracer for logging entry, exit, and custom messages. More...
#include <tec_trace.hpp>
Public Types | |
| using | Lock = std::lock_guard< std::mutex > |
| Alias for lock guard used for thread safety. | |
Public Member Functions | |
| Tracer (const char *name, std::ostream *out) | |
| Constructs a tracer with a name and output stream. | |
| ~Tracer () | |
| Destructor that logs the exit of the tracer. | |
| void | enter () |
| Logs an entry message for the tracer. | |
| template<typename T > | |
| void | trace (const T &arg) |
| Logs a single argument as a trace message. | |
| template<typename T , typename... Targs> | |
| void | trace (const char *fmt, const T &value, Targs &&... Args) |
| Logs variadic arguments as a formatted trace message. | |
A thread-safe tracer for logging entry, exit, and custom messages.
Logs messages to an output stream with timestamps, typically for debugging. Tracing is enabled only when the _TEC_TRACE_ON macro is defined. The tracer is thread-safe, using a global mutex for synchronized output.
| Duration | The duration type for timestamps (defaults to MilliSec). #include "tec/tec_status.hpp"
#include "tec/tec_trace.hpp"
void do_something() {
TEC_ENTER("do_something");
tec::Status status;
//
// Call some function that modifies `status` variable, like
// status = open_file(filename);
//
TEC_TRACE("open_file returned {}.", status)
}
// If _TEC_TRACE macro is defined, you get the following
// in the console if the file opened successfully:
//
// [681236363] * do_something entered.
// [681236365] do_something: open_files returned [Success].
#define TEC_ENTER(name) Logs an entry message for a named context (e.g., function). Definition tec_trace.hpp:211 Defines error handling types and utilities for the tec namespace. Provides a thread-safe tracing utility for debugging in the tec namespace. |
|
inline |
Constructs a tracer with a name and output stream.
Initializes the tracer with a name and an output stream for logging.
| name | The name of the tracer (e.g., function name). |
| out | Pointer to the output stream (e.g., std::cout). |
|
inline |
Destructor that logs the exit of the tracer.
Logs a message with the current timestamp and tracer name when the tracer is destroyed. The output is thread-safe, using the global trace mutex.
|
inline |
Logs an entry message for the tracer.
Outputs a message with the current timestamp and tracer name to indicate the start of a context. The output is thread-safe.
Logs variadic arguments as a formatted trace message.
Outputs a timestamped message with the tracer name and formatted arguments using the provided format string with "{}" placeholders. The output is thread-safe.
| T | The type of the first argument. |
| Targs | The types of additional arguments. |
| fmt | The format string containing "{}" placeholders. |
| value | The first argument to include in the trace message. |
| Args | The remaining arguments to include. |
|
inline |
Logs a single argument as a trace message.
Outputs a timestamped message with the tracer name and the provided argument. The output is thread-safe.
| T | The type of the argument to log. |
| arg | The argument to include in the trace message. |