X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fcommon%2FGraylog.h;fp=src%2Fceph%2Fsrc%2Fcommon%2FGraylog.h;h=7e802a899572feb4f34aa2ebf461460ed95edad0;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/common/Graylog.h b/src/ceph/src/common/Graylog.h new file mode 100644 index 0000000..7e802a8 --- /dev/null +++ b/src/ceph/src/common/Graylog.h @@ -0,0 +1,84 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef __CEPH_LOG_GRAYLOG_H +#define __CEPH_LOG_GRAYLOG_H + +#include +#include +#include + +#include "include/memory.h" +#include "include/assert.h" // boost clobbers this + +struct uuid_d; +class LogEntry; + +namespace ceph { + +class Formatter; + +namespace logging { + +struct Entry; +class SubsystemMap; + +// Graylog logging backend: Convert log datastructures (LogEntry, Entry) to +// GELF (http://www.graylog2.org/resources/gelf/specification) and send it +// to a GELF UDP receiver + +class Graylog +{ + public: + + /** + * Create Graylog with SubsystemMap. log_entry will resolve the subsystem + * id to string. Logging will not be ready until set_destination is called + * @param s SubsystemMap + * @param logger Value for key "_logger" in GELF + */ + Graylog(const SubsystemMap * const s, std::string logger); + + /** + * Create Graylog without SubsystemMap. Logging will not be ready + * until set_destination is called + * @param logger Value for key "_logger" in GELF + */ + explicit Graylog(std::string logger); + virtual ~Graylog(); + + void set_hostname(const std::string& host); + void set_fsid(const uuid_d& fsid); + + void set_destination(const std::string& host, int port); + + void log_entry(Entry const * const e); + void log_log_entry(LogEntry const * const e); + + typedef ceph::shared_ptr Ref; + + private: + SubsystemMap const * const m_subs; + + bool m_log_dst_valid; + + std::string m_hostname; + std::string m_fsid; + std::string m_logger; + + boost::asio::ip::udp::endpoint m_endpoint; + boost::asio::io_service m_io_service; + + std::unique_ptr m_formatter; + std::unique_ptr m_formatter_section; + std::stringstream m_ostream_section; + std::stringstream m_ostream_compressed; + boost::iostreams::filtering_ostream m_ostream; + boost::iostreams::zlib_compressor m_compressor; + +}; + +} +} + +#endif