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_ENTRY_H
5 #define __CEPH_LOG_ENTRY_H
7 #include "include/utime.h"
8 #include "common/PrebufferedStreambuf.h"
19 short m_prio, m_subsys;
22 PrebufferedStreambuf m_streambuf;
28 : m_thread(0), m_prio(0), m_subsys(0),
30 m_streambuf(m_static_buf, sizeof(m_static_buf)),
31 m_buf_len(sizeof(m_static_buf)),
34 Entry(utime_t s, pthread_t t, short pr, short sub,
35 const char *msg = NULL)
36 : m_stamp(s), m_thread(t), m_prio(pr), m_subsys(sub),
38 m_streambuf(m_static_buf, sizeof(m_static_buf)),
39 m_buf_len(sizeof(m_static_buf)),
43 ostream os(&m_streambuf);
47 Entry(utime_t s, pthread_t t, short pr, short sub, char* buf, size_t buf_len, size_t* exp_len,
48 const char *msg = NULL)
49 : m_stamp(s), m_thread(t), m_prio(pr), m_subsys(sub),
51 m_streambuf(buf, buf_len),
56 ostream os(&m_streambuf);
61 // function improves estimate for expected size of message
63 if (m_exp_len != NULL) {
64 size_t size = m_streambuf.size();
65 if (size > __atomic_load_n(m_exp_len, __ATOMIC_RELAXED)) {
66 //log larger then expected, just expand
67 __atomic_store_n(m_exp_len, size + 10, __ATOMIC_RELAXED);
70 //asymptotically adapt expected size to message size
71 __atomic_store_n(m_exp_len, (size + 10 + m_buf_len*31) / 32, __ATOMIC_RELAXED);
76 void set_str(const std::string &s) {
77 ostream os(&m_streambuf);
81 std::string get_str() const {
82 return m_streambuf.get_str();
85 // returns current size of content
87 return m_streambuf.size();
90 // extracts up to avail chars of content
91 int snprintf(char* dst, size_t avail) const {
92 return m_streambuf.snprintf(dst, avail);