root/src/utils/noit_log.h

Revision 84d6f13ffc15b3f1bb50df2ac835b56f70179b3e, 2.9 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 5 years ago)

closes #78

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  */
5
6 #ifndef _UTILS_NOIT_LOG_H
7 #define _UTILS_NOIT_LOG_H
8
9 #include "noit_defines.h"
10 #include <pthread.h>
11 #include <stdarg.h>
12 #include "utils/noit_hash.h"
13
14 struct _noit_log_stream_outlet_list {
15   struct _noit_log_stream *outlet;
16   struct _noit_log_stream_outlet_list *next;
17 };
18
19 typedef struct {
20   int (*openop)(struct _noit_log_stream *);
21   int (*reopenop)(struct _noit_log_stream *);
22   int (*writeop)(struct _noit_log_stream *, const void *, size_t);
23   int (*closeop)(struct _noit_log_stream *);
24   size_t (*sizeop)(struct _noit_log_stream *);
25 } logops_t;
26
27 typedef struct _noit_log_stream {
28   char *type;
29   char *name;
30   int enabled:1;
31   int debug:1;
32   char *path;
33   logops_t *ops;
34   void *op_ctx;
35   noit_hash_table *config;
36   struct _noit_log_stream_outlet_list *outlets;
37 } * noit_log_stream_t;
38
39 extern noit_log_stream_t noit_stderr;
40 extern noit_log_stream_t noit_debug;
41 extern noit_log_stream_t noit_error;
42
43 API_EXPORT(void) noit_log_init();
44 API_EXPORT(void) noit_register_logops(const char *name, logops_t *ops);
45 API_EXPORT(noit_log_stream_t)
46   noit_log_stream_new(const char *, const char *, const char *,
47                       void *, noit_hash_table *);
48 API_EXPORT(noit_log_stream_t)
49   noit_log_stream_new_on_fd(const char *, int, noit_hash_table *);
50 API_EXPORT(noit_log_stream_t)
51   noit_log_stream_new_on_file(const char *, noit_hash_table *);
52 API_EXPORT(noit_log_stream_t) noit_log_stream_find(const char *);
53 API_EXPORT(void) noit_log_stream_remove(const char *name);
54 API_EXPORT(void) noit_log_stream_add_stream(noit_log_stream_t ls,
55                                             noit_log_stream_t outlet);
56 API_EXPORT(noit_log_stream_t)
57                  noit_log_stream_remove_stream(noit_log_stream_t ls,
58                                                const char *name);
59 API_EXPORT(void) noit_log_stream_reopen(noit_log_stream_t ls);
60 API_EXPORT(void) noit_log_stream_close(noit_log_stream_t ls);
61 API_EXPORT(size_t) noit_log_stream_size(noit_log_stream_t ls);
62 API_EXPORT(void) noit_log_stream_free(noit_log_stream_t ls);
63 API_EXPORT(int) noit_vlog(noit_log_stream_t ls, struct timeval *,
64                           const char *file, int line,
65                           const char *format, va_list arg);
66 API_EXPORT(int) noit_log(noit_log_stream_t ls, struct timeval *,
67                          const char *file, int line,
68                          const char *format, ...)
69 #ifdef __GNUC__
70   __attribute__ ((format (printf, 5, 6)))
71 #endif
72   ;
73
74 #define noitLT(ls, t, args...) \
75   if(ls && ls->enabled) noit_log(ls, t, __FILE__, __LINE__, args)
76 #define noitL(ls, args...) do { \
77   if(ls && ls->enabled) { \
78     struct timeval __noitL_now; \
79     gettimeofday(&__noitL_now, NULL); \
80     noit_log(ls, &__noitL_now, __FILE__, __LINE__, args); \
81   } \
82 } while(0)
83
84 #define SETUP_LOG(a, b) do { if(!a##_log) a##_log = noit_log_stream_find(#a); \
85                              if(!a##_log) { b; } } while(0)
86
87 #endif
Note: See TracBrowser for help on using the browser.