| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #define L_ERROR 0x1 |
|---|
| 24 | #define L_WARN 0x2 |
|---|
| 25 | #define L_INFO 0x4 |
|---|
| 26 | #define L_FORBIDDEN 0x8 |
|---|
| 27 | #define L_UNCACHEABLE 0x10 |
|---|
| 28 | #define L_SUPERSEDED 0x20 |
|---|
| 29 | #define L_VARY 0x40 |
|---|
| 30 | |
|---|
| 31 | #define D_SERVER_CONN 0x100 |
|---|
| 32 | #define D_SERVER_REQ 0x200 |
|---|
| 33 | #define D_CLIENT_CONN 0x400 |
|---|
| 34 | #define D_CLIENT_REQ 0x800 |
|---|
| 35 | #define D_ATOM_REFCOUNT 0x1000 |
|---|
| 36 | #define D_REFCOUNT 0x2000 |
|---|
| 37 | #define D_LOCK 0x4000 |
|---|
| 38 | #define D_OBJECT 0x8000 |
|---|
| 39 | #define D_OBJECT_DATA 0x10000 |
|---|
| 40 | #define D_SERVER_OFFSET 0x20000 |
|---|
| 41 | #define D_CLIENT_DATA 0x40000 |
|---|
| 42 | #define D_DNS 0x80000 |
|---|
| 43 | #define D_CHILD 0x100000 |
|---|
| 44 | #define D_IO 0x200000 |
|---|
| 45 | |
|---|
| 46 | #define LOGGING_DEFAULT (L_ERROR | L_WARN | L_INFO) |
|---|
| 47 | #define LOGGING_MAX 0xFF |
|---|
| 48 | |
|---|
| 49 | extern AtomPtr logFile; |
|---|
| 50 | extern FILE *logF; |
|---|
| 51 | |
|---|
| 52 | void preinitLog(void); |
|---|
| 53 | void initLog(void); |
|---|
| 54 | void reopenLog(void); |
|---|
| 55 | |
|---|
| 56 | void really_do_log(int type, const char *f, ...) |
|---|
| 57 | ATTRIBUTE ((format (printf, 2, 3))); |
|---|
| 58 | void really_do_log_v(int type, const char *f, va_list args) |
|---|
| 59 | ATTRIBUTE ((format (printf, 2, 0))); |
|---|
| 60 | void really_do_log_n(int type, const char *s, int n); |
|---|
| 61 | void really_do_log_error(int type, int e, const char *f, ...) |
|---|
| 62 | ATTRIBUTE ((format (printf, 3, 4))); |
|---|
| 63 | void really_do_log_error_v(int type, int e, const char *f, va_list args) |
|---|
| 64 | ATTRIBUTE ((format (printf, 3, 0))); |
|---|
| 65 | |
|---|
| 66 | #ifdef __GNUC__ |
|---|
| 67 | #define DO_BACKTRACE() \ |
|---|
| 68 | do { \ |
|---|
| 69 | int n; \ |
|---|
| 70 | void *buffer[10]; \ |
|---|
| 71 | n = backtrace(buffer, 5); \ |
|---|
| 72 | fflush(stderr); \ |
|---|
| 73 | backtrace_symbols_fd(buffer, n, 2); \ |
|---|
| 74 | } while(0) |
|---|
| 75 | #else |
|---|
| 76 | #define DO_BACKTRACE() |
|---|
| 77 | #endif |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L |
|---|
| 83 | |
|---|
| 84 | #define do_log(_type, ...) \ |
|---|
| 85 | do { \ |
|---|
| 86 | if((_type) & (LOGGING_MAX)) really_do_log((_type), __VA_ARGS__); \ |
|---|
| 87 | } while(0) |
|---|
| 88 | #define do_log_error(_type, _e, ...) \ |
|---|
| 89 | do { \ |
|---|
| 90 | if((_type) & (LOGGING_MAX)) \ |
|---|
| 91 | really_do_log_error((_type), (_e), __VA_ARGS__); \ |
|---|
| 92 | } while(0) |
|---|
| 93 | |
|---|
| 94 | #elif defined(__GNUC__) |
|---|
| 95 | |
|---|
| 96 | #define do_log(_type, _args...) \ |
|---|
| 97 | do { \ |
|---|
| 98 | if((_type) & (LOGGING_MAX)) really_do_log((_type), _args); \ |
|---|
| 99 | } while(0) |
|---|
| 100 | #define do_log_error(_type, _e, _args...) \ |
|---|
| 101 | do { \ |
|---|
| 102 | if((_type) & (LOGGING_MAX)) \ |
|---|
| 103 | really_do_log_error((_type), (_e), _args); \ |
|---|
| 104 | } while(0) |
|---|
| 105 | |
|---|
| 106 | #else |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | static inline void |
|---|
| 111 | do_log(int type, const char *f, ...) |
|---|
| 112 | { |
|---|
| 113 | va_list args; |
|---|
| 114 | |
|---|
| 115 | va_start(args, f); |
|---|
| 116 | if((type & (LOGGING_MAX)) != 0) |
|---|
| 117 | really_do_log_v(type, f, args); |
|---|
| 118 | va_end(args); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | static inline void |
|---|
| 122 | do_log_error(int type, int e, const char *f, ...) |
|---|
| 123 | { |
|---|
| 124 | va_list args; |
|---|
| 125 | |
|---|
| 126 | va_start(args, f); |
|---|
| 127 | if((type & (LOGGING_MAX)) != 0) |
|---|
| 128 | really_do_log_error_v(type, e, f, args); |
|---|
| 129 | va_end(args); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | #endif |
|---|
| 133 | |
|---|
| 134 | #define do_log_n(_type, _s, _n) \ |
|---|
| 135 | do { \ |
|---|
| 136 | if((_type) & (LOGGING_MAX)) really_do_log_n((_type), (_s), (_n)); \ |
|---|
| 137 | } while(0) |
|---|