]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef __CEPH_LOG_GRAYLOG_H | |
5 | #define __CEPH_LOG_GRAYLOG_H | |
6 | ||
11fdf7f2 | 7 | #include <boost/asio.hpp> |
7c673cae FG |
8 | #include <boost/iostreams/filtering_stream.hpp> |
9 | #include <boost/iostreams/filter/zlib.hpp> | |
10 | ||
11fdf7f2 | 11 | #include "include/ceph_assert.h" // boost clobbers this |
7c673cae FG |
12 | |
13 | struct uuid_d; | |
14 | class LogEntry; | |
15 | ||
16 | namespace ceph { | |
17 | ||
18 | class Formatter; | |
19 | ||
20 | namespace logging { | |
21 | ||
11fdf7f2 | 22 | class Entry; |
7c673cae FG |
23 | class SubsystemMap; |
24 | ||
25 | // Graylog logging backend: Convert log datastructures (LogEntry, Entry) to | |
26 | // GELF (http://www.graylog2.org/resources/gelf/specification) and send it | |
27 | // to a GELF UDP receiver | |
28 | ||
29 | class Graylog | |
30 | { | |
31 | public: | |
32 | ||
33 | /** | |
34 | * Create Graylog with SubsystemMap. log_entry will resolve the subsystem | |
35 | * id to string. Logging will not be ready until set_destination is called | |
36 | * @param s SubsystemMap | |
37 | * @param logger Value for key "_logger" in GELF | |
38 | */ | |
11fdf7f2 | 39 | Graylog(const SubsystemMap * const s, const std::string &logger); |
7c673cae FG |
40 | |
41 | /** | |
42 | * Create Graylog without SubsystemMap. Logging will not be ready | |
43 | * until set_destination is called | |
44 | * @param logger Value for key "_logger" in GELF | |
45 | */ | |
11fdf7f2 | 46 | explicit Graylog(const std::string &logger); |
7c673cae FG |
47 | virtual ~Graylog(); |
48 | ||
49 | void set_hostname(const std::string& host); | |
50 | void set_fsid(const uuid_d& fsid); | |
51 | ||
52 | void set_destination(const std::string& host, int port); | |
53 | ||
11fdf7f2 | 54 | void log_entry(const Entry& e); |
7c673cae FG |
55 | void log_log_entry(LogEntry const * const e); |
56 | ||
11fdf7f2 | 57 | typedef std::shared_ptr<Graylog> Ref; |
7c673cae FG |
58 | |
59 | private: | |
60 | SubsystemMap const * const m_subs; | |
61 | ||
20effc67 | 62 | bool m_log_dst_valid = false; |
7c673cae FG |
63 | |
64 | std::string m_hostname; | |
65 | std::string m_fsid; | |
66 | std::string m_logger; | |
67 | ||
68 | boost::asio::ip::udp::endpoint m_endpoint; | |
69 | boost::asio::io_service m_io_service; | |
70 | ||
71 | std::unique_ptr<Formatter> m_formatter; | |
72 | std::unique_ptr<Formatter> m_formatter_section; | |
73 | std::stringstream m_ostream_section; | |
74 | std::stringstream m_ostream_compressed; | |
75 | boost::iostreams::filtering_ostream m_ostream; | |
76 | boost::iostreams::zlib_compressor m_compressor; | |
77 | ||
78 | }; | |
79 | ||
80 | } | |
81 | } | |
82 | ||
83 | #endif |