root/src/utils/noit_log.h

Revision 4bed82ba2ec9a01ba1c538c5f0f2d7c17e0bd687, 2.8 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

update the noit_log new API to allow passing of a context

  • 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 } logops_t;
25
26 typedef struct _noit_log_stream {
27   char *type;
28   char *name;
29   int enabled;
30   char *path;
31   logops_t *ops;
32   void *op_ctx;
33   noit_hash_table *config;
34   struct _noit_log_stream_outlet_list *outlets;
35 } * noit_log_stream_t;
36
37 extern noit_log_stream_t noit_stderr;
38 extern noit_log_stream_t noit_debug;
39 extern noit_log_stream_t noit_error;
40
41 API_EXPORT(void) noit_log_init();
42 API_EXPORT(void) noit_register_logops(const char *name, logops_t *ops);
43 API_EXPORT(noit_log_stream_t)
44   noit_log_stream_new(const char *, const char *, const char *,
45                       void *, noit_hash_table *);
46 API_EXPORT(noit_log_stream_t)
47   noit_log_stream_new_on_fd(const char *, int, noit_hash_table *);
48 API_EXPORT(noit_log_stream_t)
49   noit_log_stream_new_on_file(const char *, noit_hash_table *);
50 API_EXPORT(noit_log_stream_t) noit_log_stream_find(const char *);
51 API_EXPORT(void) noit_log_stream_remove(const char *name);
52 API_EXPORT(void) noit_log_stream_add_stream(noit_log_stream_t ls,
53                                             noit_log_stream_t outlet);
54 API_EXPORT(noit_log_stream_t)
55                  noit_log_stream_remove_stream(noit_log_stream_t ls,
56                                                const char *name);
57 API_EXPORT(void) noit_log_stream_reopen(noit_log_stream_t ls);
58 API_EXPORT(void) noit_log_stream_close(noit_log_stream_t ls);
59 API_EXPORT(void) noit_log_stream_free(noit_log_stream_t ls);
60 API_EXPORT(void) noit_vlog(noit_log_stream_t ls, struct timeval *,
61                            const char *file, int line,
62                            const char *format, va_list arg);
63 API_EXPORT(void) noit_log(noit_log_stream_t ls, struct timeval *,
64                           const char *file, int line,
65                           const char *format, ...)
66 #ifdef __GNUC__
67   __attribute__ ((format (printf, 5, 6)))
68 #endif
69   ;
70
71 #define noitLT(ls, t, args...) \
72   if(ls && ls->enabled) noit_log(ls, t, __FILE__, __LINE__, args)
73 #define noitL(ls, args...) do { \
74   if(ls && ls->enabled) { \
75     struct timeval __noitL_now; \
76     gettimeofday(&__noitL_now, NULL); \
77     noit_log(ls, &__noitL_now, __FILE__, __LINE__, args); \
78   } \
79 } while(0)
80
81 #define SETUP_LOG(a, b) do { if(!a##_log) a##_log = noit_log_stream_find(#a); \
82                              if(!a##_log) { b; } } while(0)
83
84 #endif
Note: See TracBrowser for help on using the browser.