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