1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef __CEPH_LOG_GRAYLOG_H
5 #define __CEPH_LOG_GRAYLOG_H
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>
12 #include "include/memory.h"
13 #include "include/assert.h" // boost clobbers this
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
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
41 Graylog(const SubsystemMap
* const s
, std::string logger
);
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
48 explicit Graylog(std::string logger
);
51 void set_hostname(const std::string
& host
);
52 void set_fsid(const uuid_d
& fsid
);
54 void set_destination(const std::string
& host
, int port
);
56 void log_entry(Entry
const * const e
);
57 void log_log_entry(LogEntry
const * const e
);
59 typedef ceph::shared_ptr
<Graylog
> Ref
;
62 SubsystemMap
const * const m_subs
;
66 std::string m_hostname
;
70 boost::asio::ip::udp::endpoint m_endpoint
;
71 boost::asio::io_service m_io_service
;
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
;