"Fossies" - the Fresh Open Source Software Archive 
Member "memcached-1.6.15/logger.h" (30 Mar 2022, 5805 Bytes) of package /linux/www/memcached-1.6.15.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "logger.h" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
1.6.14_vs_1.6.15.
1 /* logging functions */
2 #ifndef LOGGER_H
3 #define LOGGER_H
4
5 #include "bipbuffer.h"
6
7 /* TODO: starttime tunable */
8 #define LOGGER_BUF_SIZE 1024 * 64
9 #define LOGGER_WATCHER_BUF_SIZE 1024 * 256
10 #define LOGGER_ENTRY_MAX_SIZE 2048
11 #define GET_LOGGER() ((logger *) pthread_getspecific(logger_key));
12
13 /* Inlined from memcached.h - should go into sub header */
14 typedef unsigned int rel_time_t;
15
16 enum log_entry_type {
17 LOGGER_ASCII_CMD = 0,
18 LOGGER_EVICTION,
19 LOGGER_ITEM_GET,
20 LOGGER_ITEM_STORE,
21 LOGGER_CRAWLER_STATUS,
22 LOGGER_SLAB_MOVE,
23 LOGGER_CONNECTION_NEW,
24 LOGGER_CONNECTION_CLOSE,
25 #ifdef EXTSTORE
26 LOGGER_EXTSTORE_WRITE,
27 LOGGER_COMPACT_START,
28 LOGGER_COMPACT_ABORT,
29 LOGGER_COMPACT_READ_START,
30 LOGGER_COMPACT_READ_END,
31 LOGGER_COMPACT_END,
32 LOGGER_COMPACT_FRAGINFO,
33 #endif
34 #ifdef PROXY
35 LOGGER_PROXY_CONFIG,
36 LOGGER_PROXY_RAW,
37 LOGGER_PROXY_ERROR,
38 LOGGER_PROXY_USER,
39 LOGGER_PROXY_BE_ERROR,
40 #endif
41 };
42
43 enum logger_ret_type {
44 LOGGER_RET_OK = 0,
45 LOGGER_RET_NOSPACE,
46 LOGGER_RET_ERR
47 };
48
49 enum logger_parse_entry_ret {
50 LOGGER_PARSE_ENTRY_OK = 0,
51 LOGGER_PARSE_ENTRY_FULLBUF,
52 LOGGER_PARSE_ENTRY_FAILED
53 };
54
55 typedef struct _logentry logentry;
56 typedef struct _entry_details entry_details;
57
58 typedef void (*entry_log_cb)(logentry *e, const entry_details *d, const void *entry, va_list ap);
59 typedef int (*entry_parse_cb)(logentry *e, char *scratch);
60
61 struct _entry_details {
62 int reqlen;
63 uint16_t eflags;
64 entry_log_cb log_cb;
65 entry_parse_cb parse_cb;
66 char *format;
67 };
68
69 /* log entry intermediary structures */
70 struct logentry_eviction {
71 long long int exptime;
72 int nbytes;
73 uint32_t latime;
74 uint16_t it_flags;
75 uint8_t nkey;
76 uint8_t clsid;
77 char key[];
78 };
79 #ifdef EXTSTORE
80 struct logentry_ext_write {
81 long long int exptime;
82 uint32_t latime;
83 uint16_t it_flags;
84 uint8_t nkey;
85 uint8_t clsid;
86 uint8_t bucket;
87 char key[];
88 };
89 #endif
90 struct logentry_item_get {
91 uint8_t was_found;
92 uint8_t nkey;
93 uint8_t clsid;
94 int nbytes;
95 int sfd;
96 char key[];
97 };
98
99 struct logentry_item_store {
100 int status;
101 int cmd;
102 rel_time_t ttl;
103 uint8_t nkey;
104 uint8_t clsid;
105 int nbytes;
106 int sfd;
107 char key[];
108 };
109
110 struct logentry_conn_event {
111 int transport;
112 int reason;
113 int sfd;
114 struct sockaddr_in6 addr;
115 };
116 #ifdef PROXY
117 struct logentry_proxy_raw {
118 unsigned short type;
119 unsigned short code;
120 long elapsed; // elapsed time in usec
121 char cmd[8];
122 };
123 #endif
124 /* end intermediary structures */
125
126 /* WARNING: cuddled items aren't compatible with warm restart. more code
127 * necessary to ensure log streams are all flushed/processed before stopping
128 */
129 struct _logentry {
130 enum log_entry_type event;
131 uint8_t pad;
132 uint16_t eflags;
133 uint64_t gid;
134 struct timeval tv; /* not monotonic! */
135 int size;
136 union {
137 char end;
138 } data[];
139 };
140
141 #define LOG_SYSEVENTS (1<<1) /* threads start/stop/working */
142 #define LOG_FETCHERS (1<<2) /* get/gets/etc */
143 #define LOG_MUTATIONS (1<<3) /* set/append/incr/etc */
144 #define LOG_SYSERRORS (1<<4) /* malloc/etc errors */
145 #define LOG_CONNEVENTS (1<<5) /* new client, closed, etc */
146 #define LOG_EVICTIONS (1<<6) /* details of evicted items */
147 #define LOG_STRICT (1<<7) /* block worker instead of drop */
148 #define LOG_RAWCMDS (1<<9) /* raw ascii commands */
149 #define LOG_PROXYCMDS (1<<10) /* command logs from proxy */
150 #define LOG_PROXYEVENTS (1<<11) /* error log stream from proxy */
151 #define LOG_PROXYUSER (1<<12) /* user generated logs from proxy */
152
153 typedef struct _logger {
154 struct _logger *prev;
155 struct _logger *next;
156 pthread_mutex_t mutex; /* guard for this + *buf */
157 uint64_t written; /* entries written to the buffer */
158 uint64_t dropped; /* entries dropped */
159 uint64_t blocked; /* times blocked instead of dropped */
160 uint16_t fetcher_ratio; /* log one out of every N fetches */
161 uint16_t mutation_ratio; /* log one out of every N mutations */
162 uint16_t eflags; /* flags this logger should log */
163 bipbuf_t *buf;
164 const entry_details *entry_map;
165 } logger;
166
167 enum logger_watcher_type {
168 LOGGER_WATCHER_STDERR = 0,
169 LOGGER_WATCHER_CLIENT = 1
170 };
171
172 typedef struct {
173 void *c; /* original connection structure. still with source thread attached */
174 int sfd; /* client fd */
175 int id; /* id number for watcher list */
176 uint64_t skipped; /* lines skipped since last successful print */
177 uint64_t min_gid; /* don't show log entries older than this GID */
178 bool failed_flush; /* recently failed to write out (EAGAIN), wait before retry */
179 enum logger_watcher_type t; /* stderr, client, syslog, etc */
180 uint16_t eflags; /* flags we are interested in */
181 bipbuf_t *buf; /* per-watcher output buffer */
182 } logger_watcher;
183
184
185 struct logger_stats {
186 uint64_t worker_dropped;
187 uint64_t worker_written;
188 uint64_t watcher_skipped;
189 uint64_t watcher_sent;
190 uint64_t watcher_count;
191 };
192
193 extern pthread_key_t logger_key;
194
195 /* public functions */
196
197 void logger_init(void);
198 void logger_stop(void);
199 logger *logger_create(void);
200
201 #define LOGGER_LOG(l, flag, type, ...) \
202 do { \
203 logger *myl = l; \
204 if (l == NULL) \
205 myl = GET_LOGGER(); \
206 if (myl->eflags & flag) \
207 logger_log(myl, type, __VA_ARGS__); \
208 } while (0)
209
210 enum logger_ret_type logger_log(logger *l, const enum log_entry_type event, const void *entry, ...);
211
212 enum logger_add_watcher_ret {
213 LOGGER_ADD_WATCHER_TOO_MANY = 0,
214 LOGGER_ADD_WATCHER_OK,
215 LOGGER_ADD_WATCHER_FAILED
216 };
217
218 enum logger_add_watcher_ret logger_add_watcher(void *c, const int sfd, uint16_t f);
219
220 /* functions used by restart system */
221 uint64_t logger_get_gid(void);
222 void logger_set_gid(uint64_t gid);
223
224 #endif