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