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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#ifndef CEPH_LOGENTRY_H
#define CEPH_LOGENTRY_H
#include "include/types.h"
#include "msg/msg_types.h" // for entity_inst_t
#include "include/utime.h"
#include "include/encoding.h"
namespace ceph {
class Formatter;
}
typedef enum {
CLOG_DEBUG = 0,
CLOG_INFO = 1,
CLOG_SEC = 2,
CLOG_WARN = 3,
CLOG_ERROR = 4,
} clog_type;
/*
* Given a clog log_type, return the equivalent syslog priority
*/
int clog_type_to_syslog_prio(clog_type t);
struct LogEntryKey {
entity_inst_t who;
utime_t stamp;
uint64_t seq;
LogEntryKey() : seq(0) {}
LogEntryKey(const entity_inst_t& w, utime_t t, uint64_t s) : who(w), stamp(t), seq(s) {}
void encode(bufferlist& bl) const;
void decode(bufferlist::iterator& bl);
void dump(Formatter *f) const;
static void generate_test_instances(list<LogEntryKey*>& o);
};
WRITE_CLASS_ENCODER(LogEntryKey)
static inline bool operator==(const LogEntryKey& l, const LogEntryKey& r) {
return l.who == r.who && l.stamp == r.stamp && l.seq == r.seq;
}
struct LogEntry {
entity_inst_t who;
utime_t stamp;
uint64_t seq;
clog_type type;
string msg;
LogEntryKey key() const { return LogEntryKey(who, stamp, seq); }
void encode(bufferlist& bl) const;
void decode(bufferlist::iterator& bl);
void dump(Formatter *f) const;
static void generate_test_instances(list<LogEntry*>& o);
};
WRITE_CLASS_ENCODER(LogEntry)
struct LogSummary {
version_t version;
list<LogEntry> tail;
LogSummary() : version(0) {}
void add(const LogEntry& e) {
tail.push_back(e);
while (tail.size() > 50)
tail.pop_front();
}
bool contains(const LogEntryKey& k) const {
for (list<LogEntry>::const_iterator p = tail.begin();
p != tail.end();
p++)
if (p->key() == k)
return true;
return false;
}
void encode(bufferlist& bl) const;
void decode(bufferlist::iterator& bl);
void dump(Formatter *f) const;
static void generate_test_instances(list<LogSummary*>& o);
};
WRITE_CLASS_ENCODER(LogSummary)
inline ostream& operator<<(ostream& out, clog_type t)
{
switch (t) {
case CLOG_DEBUG:
return out << "[DBG]";
case CLOG_INFO:
return out << "[INF]";
case CLOG_WARN:
return out << "[WRN]";
case CLOG_ERROR:
return out << "[ERR]";
case CLOG_SEC:
return out << "[SEC]";
default:
return out << "[???]";
}
}
inline ostream& operator<<(ostream& out, const LogEntry& e)
{
return out << e.stamp << " " << e.who << " " << e.seq << " : " << e.type << " " << e.msg;
}
#endif
|