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 |
|
---|
13 |
struct _noit_log_stream_outlet_list { |
---|
14 |
struct _noit_log_stream *outlet; |
---|
15 |
struct _noit_log_stream_outlet_list *next; |
---|
16 |
}; |
---|
17 |
|
---|
18 |
typedef struct { |
---|
19 |
int (*openop)(struct _noit_log_stream *); |
---|
20 |
int (*reopenop)(struct _noit_log_stream *); |
---|
21 |
int (*writeop)(struct _noit_log_stream *, const void *, size_t); |
---|
22 |
int (*closeop)(struct _noit_log_stream *); |
---|
23 |
} logops_t; |
---|
24 |
|
---|
25 |
typedef struct _noit_log_stream { |
---|
26 |
char *name; |
---|
27 |
int enabled; |
---|
28 |
char *path; |
---|
29 |
logops_t *ops; |
---|
30 |
void *op_ctx; |
---|
31 |
struct _noit_log_stream_outlet_list *outlets; |
---|
32 |
} * noit_log_stream_t; |
---|
33 |
|
---|
34 |
extern noit_log_stream_t noit_stderr; |
---|
35 |
extern noit_log_stream_t noit_debug; |
---|
36 |
extern noit_log_stream_t noit_error; |
---|
37 |
|
---|
38 |
API_EXPORT(void) noit_log_init(); |
---|
39 |
API_EXPORT(noit_log_stream_t) noit_log_stream_new(const char *, logops_t *); |
---|
40 |
API_EXPORT(noit_log_stream_t) noit_log_stream_new_on_fd(const char *, int); |
---|
41 |
API_EXPORT(noit_log_stream_t) noit_log_stream_new_on_file(const char *); |
---|
42 |
API_EXPORT(noit_log_stream_t) noit_log_stream_find(const char *); |
---|
43 |
API_EXPORT(void) noit_log_stream_add_stream(noit_log_stream_t ls, |
---|
44 |
noit_log_stream_t outlet); |
---|
45 |
API_EXPORT(noit_log_stream_t) |
---|
46 |
noit_log_stream_remove_stream(noit_log_stream_t ls, |
---|
47 |
const char *name); |
---|
48 |
API_EXPORT(void) noit_log_stream_reopen(noit_log_stream_t ls); |
---|
49 |
API_EXPORT(void) noit_log_stream_close(noit_log_stream_t ls); |
---|
50 |
API_EXPORT(void) noit_log_stream_free(noit_log_stream_t ls); |
---|
51 |
API_EXPORT(void) noit_vlog(noit_log_stream_t ls, struct timeval *, |
---|
52 |
const char *file, int line, |
---|
53 |
const char *format, va_list arg); |
---|
54 |
API_EXPORT(void) noit_log(noit_log_stream_t ls, struct timeval *, |
---|
55 |
const char *file, int line, |
---|
56 |
const char *format, ...) |
---|
57 |
#ifdef __GNUC__ |
---|
58 |
__attribute__ ((format (printf, 5, 6))) |
---|
59 |
#endif |
---|
60 |
; |
---|
61 |
|
---|
62 |
#define noitLT(ls, t, args...) \ |
---|
63 |
if(ls && ls->enabled) noit_log(ls, t, __FILE__, __LINE__, args) |
---|
64 |
#define noitL(ls, args...) do { \ |
---|
65 |
if(ls && ls->enabled) { \ |
---|
66 |
struct timeval __noitL_now; \ |
---|
67 |
gettimeofday(&__noitL_now, NULL); \ |
---|
68 |
noit_log(ls, &__noitL_now, __FILE__, __LINE__, args); \ |
---|
69 |
} \ |
---|
70 |
} while(0) |
---|
71 |
|
---|
72 |
#endif |
---|