glusterfs  8.2
About: GlusterFS is a network/cluster filesystem. The storage server (or each in a cluster) runs glusterfsd and the clients use mount command or glusterfs client to mount the exported filesystem. Release series 8.x (latest version).
  Fossies Dox: glusterfs-8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

logging.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
3  This file is part of GlusterFS.
4 
5  This file is licensed to you under your choice of the GNU Lesser
6  General Public License, version 3 or any later version (LGPLv3 or
7  later), or the GNU General Public License, version 2 (GPLv2), in all
8  cases as published by the Free Software Foundation.
9 */
10 
11 #ifndef __LOGGING_H__
12 #define __LOGGING_H__
13 
14 #include <sys/time.h>
15 #include <stdint.h>
16 #include <stdio.h>
17 #include <stdarg.h>
18 #include <pthread.h>
19 #include "glusterfs/list.h"
20 
21 #ifdef GF_DARWIN_HOST_OS
22 #define GF_PRI_FSBLK "u"
23 #define GF_PRI_DEV PRId32
24 #define GF_PRI_INODE PRIu64
25 #define GF_PRI_NLINK PRIu32
26 #define GF_PRI_SECOND "ld"
27 #define GF_PRI_SUSECONDS "06d"
28 #define GF_PRI_SNSECONDS "09ld"
29 #define GF_PRI_USEC "d"
30 #else
31 #define GF_PRI_FSBLK PRIu64
32 #define GF_PRI_DEV PRIu64
33 #define GF_PRI_INODE PRIu64
34 #define GF_PRI_NLINK PRIu32
35 #define GF_PRI_SECOND "lu"
36 #define GF_PRI_SUSECONDS "06ld"
37 #define GF_PRI_SNSECONDS "09ld"
38 #define GF_PRI_USEC "ld"
39 #endif
40 #define GF_PRI_BLKSIZE PRId32
41 #define GF_PRI_SIZET "zu"
42 #define GF_PRI_ATOMIC PRIu64
43 
44 #ifdef GF_DARWIN_HOST_OS
45 #define GF_PRI_TIME "ld"
46 #else
47 #define GF_PRI_TIME PRIu64
48 #endif
49 
50 #if 0
51 /* Syslog definitions :-) */
52 #define LOG_EMERG 0 /* system is unusable */
53 #define LOG_ALERT 1 /* action must be taken immediately */
54 #define LOG_CRIT 2 /* critical conditions */
55 #define LOG_ERR 3 /* error conditions */
56 #define LOG_WARNING 4 /* warning conditions */
57 #define LOG_NOTICE 5 /* normal but significant condition */
58 #define LOG_INFO 6 /* informational */
59 #define LOG_DEBUG 7 /* debug-level messages */
60 #endif
61 
62 #define GF_LOG_FORMAT_NO_MSG_ID "no-msg-id"
63 #define GF_LOG_FORMAT_WITH_MSG_ID "with-msg-id"
64 
65 #define GF_LOGGER_GLUSTER_LOG "gluster-log"
66 #define GF_LOGGER_SYSLOG "syslog"
67 
68 typedef enum {
72  GF_LOG_CRITICAL, /* fatal errors */
73  GF_LOG_ERROR, /* major failures (not necessarily fatal) */
74  GF_LOG_WARNING, /* info about normal operation */
76  GF_LOG_INFO, /* Normal information */
77  GF_LOG_DEBUG, /* internal errors */
78  GF_LOG_TRACE, /* full trace of operation */
80 
81 /* format for the logs */
82 typedef enum {
83  gf_logformat_traditional = 0, /* Format as in gluster 3.5 */
84  gf_logformat_withmsgid, /* Format enhanced with MsgID, ident, errstr */
85  gf_logformat_cee /* log enhanced format in cee */
87 
88 /* log infrastructure to log to */
89 typedef enum {
90  gf_logger_glusterlog = 0, /* locations and files as in gluster 3.5 */
91  gf_logger_syslog /* log to (r)syslog, based on (r)syslog conf */
92  /* NOTE: In the future journald, lumberjack, next new thing here */
94 
95 #define DEFAULT_LOG_FILE_DIRECTORY DATADIR "/log/glusterfs"
96 #define DEFAULT_QUOTA_CRAWL_LOG_DIRECTORY DATADIR "/log/glusterfs/quota_crawl"
97 #define DEFAULT_LOG_LEVEL GF_LOG_INFO
98 
99 typedef struct gf_log_handle_ {
100  pthread_mutex_t logfile_mutex;
104  char *filename;
105  FILE *logfile;
108  FILE *cmdlogfile;
111  char *ident;
113  struct list_head lru_queue;
114  pthread_mutex_t log_buf_lock;
117  uint32_t lru_size;
118  uint32_t lru_cur_size;
119  uint32_t timeout;
120  uint8_t logrotate;
123 
124 typedef struct log_buf_ {
125  char *msg;
126  uint64_t msg_id;
127  int errnum;
128  struct timeval oldest;
129  struct timeval latest;
130  char *domain;
131  char *file;
132  char *function;
133  int32_t line;
135  int refcount;
136  int graph_id;
137  struct list_head msg_list;
139 
140 void
141 gf_log_globals_init(void *ctx, gf_loglevel_t level);
142 int
143 gf_log_init(void *data, const char *filename, const char *ident);
144 
145 void
146 gf_log_logrotate(int signum);
147 
148 void
150 
151 /* Internal interfaces to log messages with message IDs */
152 int
153 _gf_msg(const char *domain, const char *file, const char *function,
154  int32_t line, gf_loglevel_t level, int errnum, int trace,
155  uint64_t msgid, const char *fmt, ...)
156  __attribute__((__format__(__printf__, 9, 10)));
157 
158 void
159 _gf_msg_backtrace_nomem(gf_loglevel_t level, int stacksize);
160 
161 int
162 _gf_msg_plain(gf_loglevel_t level, const char *fmt, ...)
163  __attribute__((__format__(__printf__, 2, 3)));
164 
165 int
166 _gf_msg_plain_nomem(gf_loglevel_t level, const char *msg);
167 
168 int
169 _gf_msg_vplain(gf_loglevel_t level, const char *fmt, va_list ap);
170 
171 int
172 _gf_msg_nomem(const char *domain, const char *file, const char *function,
173  int line, gf_loglevel_t level, size_t size);
174 
175 int
176 _gf_log(const char *domain, const char *file, const char *function,
177  int32_t line, gf_loglevel_t level, const char *fmt, ...)
178  __attribute__((__format__(__printf__, 6, 7)));
179 
180 int
181 _gf_log_callingfn(const char *domain, const char *file, const char *function,
182  int32_t line, gf_loglevel_t level, const char *fmt, ...)
183  __attribute__((__format__(__printf__, 6, 7)));
184 
185 int
186 _gf_log_eh(const char *function, const char *fmt, ...)
187  __attribute__((__format__(__printf__, 2, 3)));
188 
189 /* treat GF_LOG_TRACE and GF_LOG_NONE as LOG_DEBUG and
190  * other level as is */
191 #define SET_LOG_PRIO(level, priority) \
192  do { \
193  if (GF_LOG_TRACE == (level) || GF_LOG_NONE == (level)) { \
194  priority = LOG_DEBUG; \
195  } else { \
196  priority = (level)-1; \
197  } \
198  } while (0)
199 
200 /* extract just the file name from the path */
201 #define GET_FILE_NAME_TO_LOG(file, basename) \
202  do { \
203  basename = strrchr((file), '/'); \
204  if (basename) \
205  basename++; \
206  else \
207  basename = (file); \
208  } while (0)
209 
210 #define PRINT_SIZE_CHECK(ret, label, strsize) \
211  do { \
212  if (ret < 0) \
213  goto label; \
214  if ((strsize - ret) > 0) { \
215  strsize -= ret; \
216  } else { \
217  ret = 0; \
218  goto label; \
219  } \
220  } while (0)
221 
222 #define FMT_WARN(fmt...) \
223  do { \
224  if (0) \
225  printf(fmt); \
226  } while (0)
227 
228 /* Interface to log messages with message IDs */
229 #define gf_msg(dom, level, errnum, msgid, fmt...) \
230  do { \
231  _gf_msg(dom, __FILE__, __FUNCTION__, __LINE__, level, errnum, 0, \
232  msgid, ##fmt); \
233  } while (0)
234 
235 /* no frills, no thrills, just a vanilla message, used to print the graph */
236 #define gf_msg_plain(level, fmt...) \
237  do { \
238  _gf_msg_plain(level, ##fmt); \
239  } while (0)
240 
241 #define gf_msg_plain_nomem(level, msg) \
242  do { \
243  _gf_msg_plain_nomem(level, msg); \
244  } while (0)
245 
246 #define gf_msg_vplain(level, fmt, va) \
247  do { \
248  _gf_msg_vplain(level, fmt, va); \
249  } while (0)
250 
251 #define gf_msg_backtrace_nomem(level, stacksize) \
252  do { \
253  _gf_msg_backtrace_nomem(level, stacksize); \
254  } while (0)
255 
256 #define gf_msg_callingfn(dom, level, errnum, msgid, fmt...) \
257  do { \
258  _gf_msg(dom, __FILE__, __FUNCTION__, __LINE__, level, errnum, 1, \
259  msgid, ##fmt); \
260  } while (0)
261 
262 /* No malloc or calloc should be called in this function */
263 #define gf_msg_nomem(dom, level, size) \
264  do { \
265  _gf_msg_nomem(dom, __FILE__, __FUNCTION__, __LINE__, level, size); \
266  } while (0)
267 
268 /* Debug or trace messages do not need message IDs as these are more developer
269  * related. Hence, the following abstractions are provided for the same */
270 #define gf_msg_debug(dom, errnum, fmt...) \
271  do { \
272  _gf_msg(dom, __FILE__, __FUNCTION__, __LINE__, GF_LOG_DEBUG, errnum, \
273  0, 0, ##fmt); \
274  } while (0)
275 
276 #define gf_msg_trace(dom, errnum, fmt...) \
277  do { \
278  _gf_msg(dom, __FILE__, __FUNCTION__, __LINE__, GF_LOG_TRACE, errnum, \
279  0, 0, ##fmt); \
280  } while (0)
281 
282 #define gf_log(dom, level, fmt...) \
283  do { \
284  FMT_WARN(fmt); \
285  _gf_log(dom, __FILE__, __FUNCTION__, __LINE__, level, ##fmt); \
286  } while (0)
287 
288 #define gf_log_eh(fmt...) \
289  do { \
290  FMT_WARN(fmt); \
291  _gf_log_eh(__FUNCTION__, ##fmt); \
292  } while (0)
293 
294 #define gf_log_callingfn(dom, level, fmt...) \
295  do { \
296  FMT_WARN(fmt); \
297  _gf_log_callingfn(dom, __FILE__, __FUNCTION__, __LINE__, level, \
298  ##fmt); \
299  } while (0)
300 
301 /* Log once in GF_UNIVERSAL_ANSWER times */
302 #define GF_LOG_OCCASIONALLY(var, args...) \
303  if (var++ == 0 || !((var - 1) % GF_UNIVERSAL_ANSWER)) { \
304  gf_log(args); \
305  }
306 
307 struct _glusterfs_ctx;
308 
309 void
311 void
314 gf_log_get_loglevel(void);
315 void
317 int
319 void
321 void
322 gf_log_flush(void);
324 gf_log_get_xl_loglevel(void *xl);
325 void
326 gf_log_set_xl_loglevel(void *xl, gf_loglevel_t level);
327 
328 int
329 gf_cmd_log(const char *domain, const char *fmt, ...)
330  __attribute__((__format__(__printf__, 2, 3)));
331 
332 int
333 gf_cmd_log_init(const char *filename);
334 
335 void
337 
338 int
339 gf_log_fini(void *data);
340 
341 void
343 
344 void
346 
347 void
348 gf_log_set_log_buf_size(uint32_t buf_size);
349 
350 void
351 gf_log_set_log_flush_timeout(uint32_t timeout);
352 
353 void
354 gf_log_flush_msgs(struct _glusterfs_ctx *ctx);
355 
356 int
358 
359 void
361 
362 #define GF_DEBUG(xl, format, args...) \
363  gf_log((xl)->name, GF_LOG_DEBUG, format, ##args)
364 #define GF_INFO(xl, format, args...) \
365  gf_log((xl)->name, GF_LOG_INFO, format, ##args)
366 #define GF_WARNING(xl, format, args...) \
367  gf_log((xl)->name, GF_LOG_WARNING, format, ##args)
368 #define GF_ERROR(xl, format, args...) \
369  gf_log((xl)->name, GF_LOG_ERROR, format, ##args)
370 
371 int
372 _gf_smsg(const char *domain, const char *file, const char *function,
373  int32_t line, gf_loglevel_t level, int errnum, int trace,
374  uint64_t msgid, const char *event, ...);
375 
376 /* Interface to log messages with message IDs */
377 #define gf_smsg(dom, level, errnum, msgid, event...) \
378  do { \
379  _gf_smsg(dom, __FILE__, __FUNCTION__, __LINE__, level, errnum, 0, \
380  msgid, msgid##_STR, ##event); \
381  } while (0)
382 
383 #endif /* __LOGGING_H__ */
_gf_msg_plain
int _gf_msg_plain(gf_loglevel_t level, const char *fmt,...)
Definition: logging.c:914
_gf_log
int _gf_log(const char *domain, const char *file, const char *function, int32_t line, gf_loglevel_t level, const char *fmt,...)
gf_log_handle_::log_control_file_found
int log_control_file_found
Definition: logging.h:112
log_buf_::graph_id
int graph_id
Definition: logging.h:136
log_buf_::msg
char * msg
Definition: logging.h:125
_glusterfs_ctx
Definition: glusterfs.h:618
_gf_smsg
int _gf_smsg(const char *domain, const char *file, const char *function, int32_t line, gf_loglevel_t level, int errnum, int trace, uint64_t msgid, const char *event,...)
Definition: logging.c:2435
gf_log_handle_::timeout
uint32_t timeout
Definition: logging.h:119
_gf_msg_vplain
int _gf_msg_vplain(gf_loglevel_t level, const char *fmt, va_list ap)
Definition: logging.c:947
gf_log_set_logformat
void gf_log_set_logformat(gf_log_format_t format)
Definition: logging.c:180
gf_log_set_localtime
void gf_log_set_localtime(int)
Definition: logging.c:131
gf_log_globals_init
void gf_log_globals_init(void *ctx, gf_loglevel_t level)
Definition: logging.c:577
log_buf_::level
gf_loglevel_t level
Definition: logging.h:134
gf_log_set_log_flush_timeout
void gf_log_set_log_flush_timeout(uint32_t timeout)
Definition: logging.c:229
_gf_log_callingfn
int _gf_log_callingfn(const char *domain, const char *file, const char *function, int32_t line, gf_loglevel_t level, const char *fmt,...)
gf_log_handle_::logger
gf_log_logger_t logger
Definition: logging.h:109
set_sys_log_level
void set_sys_log_level(gf_loglevel_t level)
Definition: logging.c:729
gf_log_handle_::logfile
FILE * logfile
Definition: logging.h:105
gf_log_handle_::lru_queue
struct list_head lru_queue
Definition: logging.h:113
log_buf_::refcount
int refcount
Definition: logging.h:135
GF_LOG_TRACE
@ GF_LOG_TRACE
Definition: logging.h:78
gf_log_set_xl_loglevel
void gf_log_set_xl_loglevel(void *xl, gf_loglevel_t level)
Definition: logging.c:153
src.utils.logger
logger
Definition: utils.py:50
gf_cmd_log
int gf_cmd_log(const char *domain, const char *fmt,...)
Definition: logging.c:2225
GF_LOG_EMERG
@ GF_LOG_EMERG
Definition: logging.h:70
gf_log_flush
void gf_log_flush(void)
Definition: logging.c:138
GF_LOG_ALERT
@ GF_LOG_ALERT
Definition: logging.h:71
gf_log_handle_
Definition: logging.h:99
log_buf_::msg_list
struct list_head msg_list
Definition: logging.h:137
gf_log_get_localtime
int gf_log_get_localtime(void)
Definition: logging.c:121
log_buf_::msg_id
uint64_t msg_id
Definition: logging.h:126
gf_log_handle_::log_flush_timer
struct _gf_timer * log_flush_timer
Definition: logging.h:115
_gf_log_eh
int _gf_log_eh(const char *function, const char *fmt,...)
Definition: logging.c:2144
gf_log_handle_::cmd_history_logrotate
uint8_t cmd_history_logrotate
Definition: logging.h:121
gf_log_cleanup
void gf_log_cleanup(void)
GF_LOG_WARNING
@ GF_LOG_WARNING
Definition: logging.h:74
_gf_msg_nomem
int _gf_msg_nomem(const char *domain, const char *file, const char *function, int line, gf_loglevel_t level, size_t size)
Definition: logging.c:1078
GF_LOG_DEBUG
@ GF_LOG_DEBUG
Definition: logging.h:77
gf_log_disable_syslog
void gf_log_disable_syslog(void)
Definition: logging.c:97
gf_log_set_loglevel
void gf_log_set_loglevel(struct _glusterfs_ctx *ctx, gf_loglevel_t level)
Definition: logging.c:114
gf_log_get_loglevel
gf_loglevel_t gf_log_get_loglevel(void)
Definition: logging.c:104
gf_log_handle_::loglevel
gf_loglevel_t loglevel
Definition: logging.h:101
log_buf_::file
char * file
Definition: logging.h:131
gf_log_handle_::gf_log_logfile
FILE * gf_log_logfile
Definition: logging.h:106
list_head
Definition: list.h:14
gf_log_handle_::sys_log_level
gf_loglevel_t sys_log_level
Definition: logging.h:102
gf_logger_glusterlog
@ gf_logger_glusterlog
Definition: logging.h:90
gf_logger_syslog
@ gf_logger_syslog
Definition: logging.h:91
log_buf_t
struct log_buf_ log_buf_t
gf_log_handle_::logformat
gf_log_format_t logformat
Definition: logging.h:110
GF_LOG_CRITICAL
@ GF_LOG_CRITICAL
Definition: logging.h:72
_gf_msg_plain_nomem
int _gf_msg_plain_nomem(gf_loglevel_t level, const char *msg)
Definition: logging.c:976
GF_LOG_NOTICE
@ GF_LOG_NOTICE
Definition: logging.h:75
gf_log_get_xl_loglevel
gf_loglevel_t gf_log_get_xl_loglevel(void *xl)
Definition: logging.c:194
gf_log_handle_t
struct gf_log_handle_ gf_log_handle_t
gf_log_handle_::lru_size
uint32_t lru_size
Definition: logging.h:117
gf_log_set_log_buf_size
void gf_log_set_log_buf_size(uint32_t buf_size)
Definition: logging.c:203
gf_loglevel_t
gf_loglevel_t
Definition: logging.h:68
gf_log_handle_::gf_log_syslog
int gf_log_syslog
Definition: logging.h:103
gf_log_fini
int gf_log_fini(void *data)
Definition: logging.c:384
gf_log_handle_::cmdlogfile
FILE * cmdlogfile
Definition: logging.h:108
gf_log_init
int gf_log_init(void *data, const char *filename, const char *ident)
Definition: logging.c:604
GF_LOG_NONE
@ GF_LOG_NONE
Definition: logging.h:69
log_buf_::errnum
int errnum
Definition: logging.h:127
GF_LOG_ERROR
@ GF_LOG_ERROR
Definition: logging.h:73
gf_logformat_cee
@ gf_logformat_cee
Definition: logging.h:85
gf_log_handle_::log_buf_lock
pthread_mutex_t log_buf_lock
Definition: logging.h:114
_gf_msg
int _gf_msg(const char *domain, const char *file, const char *function, int32_t line, gf_loglevel_t level, int errnum, int trace, uint64_t msgid, const char *fmt,...)
Definition: logging.c:1924
log_buf_::oldest
struct timeval oldest
Definition: logging.h:128
_gf_timer
Definition: timer.h:21
gf_log_handle_::localtime
int localtime
Definition: logging.h:116
gf_log_handle_::ident
char * ident
Definition: logging.h:111
gf_log_handle_::logfile_mutex
pthread_mutex_t logfile_mutex
Definition: logging.h:100
gf_log_set_logger
void gf_log_set_logger(gf_log_logger_t logger)
Definition: logging.c:187
gf_log_disable_suppression_before_exit
void gf_log_disable_suppression_before_exit(struct _glusterfs_ctx *ctx)
Definition: logging.c:356
gf_log_logrotate
void gf_log_logrotate(int signum)
Definition: logging.c:81
gf_log_handle_::cmd_log_filename
char * cmd_log_filename
Definition: logging.h:107
log_buf_::line
int32_t line
Definition: logging.h:133
gf_log_handle_::lru_cur_size
uint32_t lru_cur_size
Definition: logging.h:118
_gf_msg_backtrace_nomem
void _gf_msg_backtrace_nomem(gf_loglevel_t level, int stacksize)
Definition: logging.c:998
gf_log_logger_t
gf_log_logger_t
Definition: logging.h:89
gf_logformat_traditional
@ gf_logformat_traditional
Definition: logging.h:83
log_buf_::latest
struct timeval latest
Definition: logging.h:129
list.h
GF_LOG_INFO
@ GF_LOG_INFO
Definition: logging.h:76
gf_log_flush_msgs
void gf_log_flush_msgs(struct _glusterfs_ctx *ctx)
Definition: logging.c:1617
gf_cmd_log_init
int gf_cmd_log_init(const char *filename)
Definition: logging.c:2178
gf_log_format_t
gf_log_format_t
Definition: logging.h:82
gf_log_handle_::filename
char * filename
Definition: logging.h:104
gf_log_inject_timer_event
int gf_log_inject_timer_event(struct _glusterfs_ctx *ctx)
Definition: logging.c:1719
gf_logformat_withmsgid
@ gf_logformat_withmsgid
Definition: logging.h:84
gf_log_enable_syslog
void gf_log_enable_syslog(void)
Definition: logging.c:90
log_buf_
Definition: logging.h:124
log_buf_::domain
char * domain
Definition: logging.h:130
gf_log_handle_::logrotate
uint8_t logrotate
Definition: logging.h:120