Add function Tracer
This commit is contained in:
parent
7cfb304296
commit
f8c7c9c6ea
1 changed files with 30 additions and 0 deletions
30
src/log.hh
30
src/log.hh
|
@ -60,6 +60,18 @@ private:
|
|||
};
|
||||
|
||||
|
||||
struct Tracer
|
||||
{
|
||||
Tracer(const std::string& name,
|
||||
const std::string& function);
|
||||
~Tracer();
|
||||
|
||||
private:
|
||||
const std::string& mName;
|
||||
const std::string& mFunction;
|
||||
};
|
||||
|
||||
|
||||
std::ostream* Log::sOutput = nullptr;
|
||||
Log::LoggerMap Log::sLoggers;
|
||||
|
||||
|
@ -145,6 +157,22 @@ Log::Logger::Logger(unsigned int l)
|
|||
: level(l)
|
||||
{ }
|
||||
|
||||
#pragma mark Tracer
|
||||
|
||||
Tracer::Tracer(const std::string& name,
|
||||
const std::string& function)
|
||||
: mName(name),
|
||||
mFunction(function)
|
||||
{
|
||||
Log(mName, level::Trace) << "--> " << mFunction;
|
||||
}
|
||||
|
||||
|
||||
Tracer::~Tracer()
|
||||
{
|
||||
Log(mName, level::Trace) << "<-- " << mFunction;
|
||||
}
|
||||
|
||||
} /* namespace log */
|
||||
} /* namespace charles */
|
||||
|
||||
|
@ -156,4 +184,6 @@ Log::Logger::Logger(unsigned int l)
|
|||
#define LOG_DEBUG(name) LOG(name, charles::log::level::Debug)
|
||||
#define LOG_TRACE(name) LOG(name, charles::log::level::Trace)
|
||||
|
||||
#define TRACE_FUNC(name) auto __tracer = charles::log::Tracer((name), __PRETTY_FUNCTION__)
|
||||
|
||||
#endif /* __LOG_HH__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue