summaryrefslogtreecommitdiff
path: root/src/log/Entry.h
blob: a9dbebcaa30ed2f4e42d7752c3f70bf180edc20e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef __CEPH_LOG_ENTRY_H
#define __CEPH_LOG_ENTRY_H

#include <pthread.h>
#include <string>

#include "include/utime.h"
#include "common/PrebufferedStreambuf.h"

#define CEPH_LOG_ENTRY_PREALLOC 80

namespace ceph {
namespace log {

struct Entry {
  utime_t m_stamp;
  pthread_t m_thread;
  short m_prio, m_subsys;
  Entry *m_next;

  char m_static_buf[CEPH_LOG_ENTRY_PREALLOC];
  PrebufferedStreambuf m_streambuf;

  Entry()
    : m_thread(0), m_prio(0), m_subsys(0),
      m_next(NULL),
      m_streambuf(m_static_buf, sizeof(m_static_buf))
  {}
  Entry(utime_t s, pthread_t t, short pr, short sub,
	const char *msg = NULL)
    : m_stamp(s), m_thread(t), m_prio(pr), m_subsys(sub),
      m_next(NULL),
      m_streambuf(m_static_buf, sizeof(m_static_buf))
  {
    if (msg) {
      ostream os(&m_streambuf);
      os << msg;
    }
  }

  void set_str(const std::string s) {
    ostream os(&m_streambuf);
    os << s;
  }

  std::string get_str() const {
    return m_streambuf.get_str();
  }
};

}
}

#endif