| 60 | } |
| 61 | |
| 62 | void Graylog::log_entry(const Entry& e) |
| 63 | { |
| 64 | if (m_log_dst_valid) { |
| 65 | auto s = e.strv(); |
| 66 | |
| 67 | m_formatter->open_object_section(""); |
| 68 | m_formatter->dump_string("version", "1.1"); |
| 69 | m_formatter->dump_string("host", m_hostname); |
| 70 | m_formatter->dump_string("short_message", s); |
| 71 | m_formatter->dump_string("_app", "ceph"); |
| 72 | auto t = ceph::logging::log_clock::to_timeval(e.m_stamp); |
| 73 | m_formatter->dump_float("timestamp", t.tv_sec + (t.tv_usec / 1000000.0)); |
| 74 | m_formatter->dump_unsigned("_thread", (uint64_t)e.m_thread); |
| 75 | m_formatter->dump_int("_level", e.m_prio); |
| 76 | if (m_subs != NULL) |
| 77 | m_formatter->dump_string("_subsys_name", m_subs->get_name(e.m_subsys)); |
| 78 | m_formatter->dump_int("_subsys_id", e.m_subsys); |
| 79 | m_formatter->dump_string("_fsid", m_fsid); |
| 80 | m_formatter->dump_string("_logger", m_logger); |
| 81 | m_formatter->close_section(); |
| 82 | |
| 83 | m_ostream_compressed.clear(); |
| 84 | m_ostream_compressed.str(""); |
| 85 | |
| 86 | m_ostream.reset(); |
| 87 | |
| 88 | m_ostream.push(m_compressor); |
| 89 | m_ostream.push(m_ostream_compressed); |
| 90 | |
| 91 | m_formatter->flush(m_ostream); |
| 92 | m_ostream << std::endl; |
| 93 | |
| 94 | m_ostream.reset(); |
| 95 | |
| 96 | try { |
| 97 | boost::asio::ip::udp::socket socket(m_io_service); |
| 98 | socket.open(m_endpoint.protocol()); |
| 99 | socket.send_to(boost::asio::buffer(m_ostream_compressed.str()), m_endpoint); |
| 100 | } catch (boost::system::system_error const& e) { |
| 101 | cerr << "Error sending graylog message: " << e.what() << std::endl; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | void Graylog::log_log_entry(LogEntry const * const e) |
| 107 | { |