]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/Graylog.h
update sources to v12.2.3
[ceph.git] / ceph / src / common / Graylog.h
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
7 #include <boost/asio/ip/udp.hpp>
8 #include <boost/asio/io_service.hpp>
9 #include <boost/iostreams/filtering_stream.hpp>
10 #include <boost/iostreams/filter/zlib.hpp>
11
12 #include "include/memory.h"
13 #include "include/assert.h" // boost clobbers this
14
15 struct uuid_d;
16 class LogEntry;
17
18 namespace ceph {
19
20 class Formatter;
21
22 namespace logging {
23
24 struct Entry;
25 class SubsystemMap;
26
27 // Graylog logging backend: Convert log datastructures (LogEntry, Entry) to
28 // GELF (http://www.graylog2.org/resources/gelf/specification) and send it
29 // to a GELF UDP receiver
30
31 class Graylog
32 {
33 public:
34
35 /**
36 * Create Graylog with SubsystemMap. log_entry will resolve the subsystem
37 * id to string. Logging will not be ready until set_destination is called
38 * @param s SubsystemMap
39 * @param logger Value for key "_logger" in GELF
40 */
41 Graylog(const SubsystemMap * const s, std::string logger);
42
43 /**
44 * Create Graylog without SubsystemMap. Logging will not be ready
45 * until set_destination is called
46 * @param logger Value for key "_logger" in GELF
47 */
48 explicit Graylog(std::string logger);
49 virtual ~Graylog();
50
51 void set_hostname(const std::string& host);
52 void set_fsid(const uuid_d& fsid);
53
54 void set_destination(const std::string& host, int port);
55
56 void log_entry(Entry const * const e);
57 void log_log_entry(LogEntry const * const e);
58
59 typedef ceph::shared_ptr<Graylog> Ref;
60
61 private:
62 SubsystemMap const * const m_subs;
63
64 bool m_log_dst_valid;
65
66 std::string m_hostname;
67 std::string m_fsid;
68 std::string m_logger;
69
70 boost::asio::ip::udp::endpoint m_endpoint;
71 boost::asio::io_service m_io_service;
72
73 std::unique_ptr<Formatter> m_formatter;
74 std::unique_ptr<Formatter> m_formatter_section;
75 std::stringstream m_ostream_section;
76 std::stringstream m_ostream_compressed;
77 boost::iostreams::filtering_ostream m_ostream;
78 boost::iostreams::zlib_compressor m_compressor;
79
80 };
81
82 }
83 }
84
85 #endif