root/src/utils/noit_log.h

Revision 1648bed76d308479cdd5f492ca2a697c4df97812, 2.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

configurable logging and untested jlog hookup

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