1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_LOGENTRY_H
16 #define CEPH_LOGENTRY_H
18 #include "include/utime.h"
19 #include "msg/msg_types.h" // for entity_inst_t
20 #include "common/entity_name.h"
35 static const std::string CLOG_CHANNEL_NONE
= "none";
36 static const std::string CLOG_CHANNEL_DEFAULT
= "cluster";
37 static const std::string CLOG_CHANNEL_CLUSTER
= "cluster";
38 static const std::string CLOG_CHANNEL_AUDIT
= "audit";
40 // this is the key name used in the config options for the default, e.g.
41 // default=true foo=false bar=false
42 static const std::string CLOG_CONFIG_DEFAULT_KEY
= "default";
45 * Given a clog log_type, return the equivalent syslog priority
47 int clog_type_to_syslog_level(clog_type t
);
49 clog_type
string_to_clog_type(const string
& s
);
50 int string_to_syslog_level(string s
);
51 int string_to_syslog_facility(string s
);
53 string
clog_type_to_string(clog_type t
);
61 hash
<entity_inst_t
> h
;
71 LogEntryKey(const entity_inst_t
& w
, utime_t t
, uint64_t s
)
72 : who(w
), stamp(t
), seq(s
) {
76 uint64_t get_hash() const {
80 void encode(bufferlist
& bl
, uint64_t features
) const;
81 void decode(bufferlist::iterator
& bl
);
82 void dump(Formatter
*f
) const;
83 static void generate_test_instances(list
<LogEntryKey
*>& o
);
85 friend bool operator==(const LogEntryKey
& l
, const LogEntryKey
& r
) {
86 return l
.who
== r
.who
&& l
.stamp
== r
.stamp
&& l
.seq
== r
.seq
;
89 WRITE_CLASS_ENCODER_FEATURES(LogEntryKey
)
92 template<> struct hash
<LogEntryKey
> {
93 size_t operator()(const LogEntryKey
& r
) const {
108 LogEntry() : seq(0), prio(CLOG_DEBUG
) {}
110 LogEntryKey
key() const { return LogEntryKey(who
, stamp
, seq
); }
112 void log_to_syslog(string level
, string facility
);
114 void encode(bufferlist
& bl
, uint64_t features
) const;
115 void decode(bufferlist::iterator
& bl
);
116 void dump(Formatter
*f
) const;
117 static void generate_test_instances(list
<LogEntry
*>& o
);
119 WRITE_CLASS_ENCODER_FEATURES(LogEntry
)
124 ceph::unordered_set
<LogEntryKey
> keys
;
126 LogSummary() : version(0) {}
128 void add(const LogEntry
& e
) {
130 keys
.insert(tail
.back().key());
132 void prune(size_t max
) {
133 while (tail
.size() > max
) {
134 keys
.erase(tail
.front().key());
138 bool contains(const LogEntryKey
& k
) const {
139 return keys
.count(k
);
142 void encode(bufferlist
& bl
, uint64_t features
) const;
143 void decode(bufferlist::iterator
& bl
);
144 void dump(Formatter
*f
) const;
145 static void generate_test_instances(list
<LogSummary
*>& o
);
147 WRITE_CLASS_ENCODER_FEATURES(LogSummary
)
149 inline ostream
& operator<<(ostream
& out
, const clog_type t
)
153 return out
<< "[DBG]";
155 return out
<< "[INF]";
157 return out
<< "[SEC]";
159 return out
<< "[WRN]";
161 return out
<< "[ERR]";
163 return out
<< "[???]";
167 inline ostream
& operator<<(ostream
& out
, const LogEntry
& e
)
169 return out
<< e
.stamp
<< " " << e
.name
<< " " << e
.who
170 << " " << e
.seq
<< " : "
171 << e
.channel
<< " " << e
.prio
<< " " << e
.msg
;