Doxygen
Loading...
Searching...
No Matches
AutoTrace Class Reference

Helper class to trace an entry statement at creation and another one at destruction. More...

#include <src/trace.h>

Public Member Functions

 AutoTrace (spdlog::source_loc loc)
 
template<typename... Args>
 AutoTrace (spdlog::source_loc loc, const std::string &fmt, Args &&...args)
 
 ~AutoTrace ()
 
template<typename... Args>
void add (spdlog::source_loc loc, const std::string &fmt, Args &&...args)
 
template<typename... Args>
void setExit (const std::string &msg, Args &&...args)
 

Private Attributes

spdlog::source_loc m_loc
 
std::string m_exitMessage
 

Detailed Description

Helper class to trace an entry statement at creation and another one at destruction.

Definition at line 81 of file trace.h.

Constructor & Destructor Documentation

◆ AutoTrace() [1/2]

AutoTrace::AutoTrace ( spdlog::source_loc loc)
inlineexplicit

Definition at line 84 of file trace.h.

84 : m_loc(loc)
85 {
86 if (g_tracer)
87 {
88 g_tracer->log(m_loc,spdlog::level::trace,">");
89 }
90 }
spdlog::source_loc m_loc
Definition trace.h:138
std::shared_ptr< spdlog::logger > g_tracer
Definition trace.cpp:20

References g_tracer, and m_loc.

◆ AutoTrace() [2/2]

template<typename... Args>
AutoTrace::AutoTrace ( spdlog::source_loc loc,
const std::string & fmt,
Args &&... args )
inlineexplicit

Definition at line 92 of file trace.h.

93 : m_loc(loc)
94 {
95 if (g_tracer)
96 {
97 if (fmt.empty())
98 {
99 g_tracer->log(m_loc,spdlog::level::trace,">");
100 }
101 else
102 {
103 g_tracer->log(m_loc,spdlog::level::trace,"> "+fmt,std::forward<Args>(args)...);
104 }
105 }
106 }

References g_tracer, and m_loc.

◆ ~AutoTrace()

AutoTrace::~AutoTrace ( )
inline

Definition at line 107 of file trace.h.

108 {
109 if (g_tracer)
110 {
111 if (m_exitMessage.empty())
112 {
113 g_tracer->log(m_loc,spdlog::level::trace,"<");
114 }
115 else
116 {
117 g_tracer->log(m_loc,spdlog::level::trace,"< "+m_exitMessage);
118 }
119 }
120 }
std::string m_exitMessage
Definition trace.h:139

References g_tracer, m_exitMessage, and m_loc.

Member Function Documentation

◆ add()

template<typename... Args>
void AutoTrace::add ( spdlog::source_loc loc,
const std::string & fmt,
Args &&... args )
inline

Definition at line 124 of file trace.h.

126 {
127 if (g_tracer)
128 {
129 g_tracer->log(loc,spdlog::level::trace,": "+fmt,std::forward<Args>(args)...);
130 }
131 }

References g_tracer.

◆ setExit()

template<typename... Args>
void AutoTrace::setExit ( const std::string & msg,
Args &&... args )
inline

Definition at line 133 of file trace.h.

134 {
135 m_exitMessage = fmt::format(msg,std::forward<Args>(args)...);
136 }
void msg(const char *fmt,...)
Definition message.cpp:98

References m_exitMessage, and msg().

Member Data Documentation

◆ m_exitMessage

std::string AutoTrace::m_exitMessage
private

Definition at line 139 of file trace.h.

Referenced by setExit(), and ~AutoTrace().

◆ m_loc

spdlog::source_loc AutoTrace::m_loc
private

Definition at line 138 of file trace.h.

Referenced by AutoTrace(), AutoTrace(), and ~AutoTrace().


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