]> granicus.if.org Git - icinga2/blob - lib/base/context.hpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / context.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef CONTEXT_H
4 #define CONTEXT_H
5
6 #include "base/i2-base.hpp"
7 #include "base/string.hpp"
8 #include <list>
9
10 namespace icinga
11 {
12
13 class ContextTrace
14 {
15 public:
16         ContextTrace();
17
18         void Print(std::ostream& fp) const;
19
20         size_t GetLength() const;
21
22 private:
23         std::list<String> m_Frames;
24 };
25
26 std::ostream& operator<<(std::ostream& stream, const ContextTrace& trace);
27
28 /**
29  * A context frame.
30  *
31  * @ingroup base
32  */
33 class ContextFrame
34 {
35 public:
36         ContextFrame(const String& message);
37         ~ContextFrame();
38
39 private:
40         static std::list<String>& GetFrames();
41
42         friend class ContextTrace;
43 };
44
45 /* The currentContextFrame variable has to be volatile in order to prevent
46  * the compiler from optimizing it away. */
47 #define CONTEXT(message) volatile icinga::ContextFrame currentContextFrame(message)
48 }
49
50 #endif /* CONTEXT_H */