2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-11-19 07:49:41 +01:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/context.hpp"
|
2013-11-19 07:49:41 +01:00
|
|
|
#include <boost/thread/tss.hpp>
|
2018-01-04 18:24:45 +01:00
|
|
|
#include <iostream>
|
2013-11-19 07:49:41 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
static boost::thread_specific_ptr<std::list<String> > l_Frames;
|
|
|
|
|
|
|
|
ContextFrame::ContextFrame(const String& message)
|
|
|
|
{
|
|
|
|
GetFrames().push_front(message);
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ContextFrame::~ContextFrame()
|
2013-11-19 07:49:41 +01:00
|
|
|
{
|
|
|
|
GetFrames().pop_front();
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
std::list<String>& ContextFrame::GetFrames()
|
2013-11-19 07:49:41 +01:00
|
|
|
{
|
2017-12-14 15:37:20 +01:00
|
|
|
if (!l_Frames.get())
|
2013-11-19 07:49:41 +01:00
|
|
|
l_Frames.reset(new std::list<String>());
|
|
|
|
|
|
|
|
return *l_Frames;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ContextTrace::ContextTrace()
|
2013-11-19 07:49:41 +01:00
|
|
|
: m_Frames(ContextFrame::GetFrames())
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void ContextTrace::Print(std::ostream& fp) const
|
|
|
|
{
|
2016-09-02 08:51:51 +02:00
|
|
|
if (m_Frames.empty())
|
|
|
|
return;
|
|
|
|
|
2018-01-04 18:24:45 +01:00
|
|
|
fp << "\n";
|
2013-11-19 07:49:41 +01:00
|
|
|
|
|
|
|
int i = 0;
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const String& frame : m_Frames) {
|
2018-01-04 18:24:45 +01:00
|
|
|
fp << "\t(" << i << ") " << frame << "\n";
|
2013-11-19 07:49:41 +01:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
size_t ContextTrace::GetLength() const
|
2013-11-19 07:49:41 +01:00
|
|
|
{
|
|
|
|
return m_Frames.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream& icinga::operator<<(std::ostream& stream, const ContextTrace& trace)
|
|
|
|
{
|
|
|
|
trace.Print(stream);
|
|
|
|
return stream;
|
|
|
|
}
|