00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __AW_LOG__
00022 #define __AW_LOG__
00023
00024 #include "sys.h"
00025 #include "thread.h"
00026 #include "errors.h"
00027 #include "util.h"
00028
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00078 typedef enum {
00079 AW_LOGGER_ENABLED = 0x1,
00080 AW_LOGGER_CACHEMSG = 0x2,
00081 AW_LOGGER_ERR2SYSLOG = 0x4,
00082 AW_LOGGER_ERR2STDERR = 0x8,
00083 AW_LOGGER_PREPEND_DATE = 0x10,
00084 AW_LOGGER_DUP2SYSLOG = 0x20,
00085 AW_LOGGER_DUP2STDERR = 0x40,
00086 AW_LOGGER_APPEND_NEWLINE = 0x80,
00087 AW_LOGGER_ROTATE_HR = 0x100,
00088 AW_LOGGER_ROTATE_DY = 0x200,
00089 AW_LOGGER_ROTATE_MH = 0x400,
00090 AW_LOGGER_DEDUP = 0x800,
00091 AW_LOGGER_NBITS
00092 } aw_logger_flag_t;
00093
00094
00095
00099 #define AW_LOGGER_IS_ROTATING(flags) \
00100 ( (flags)&(AW_LOGGER_ROTATE_HR | AW_LOGGER_ROTATE_DY | AW_LOGGER_ROTATE_MH) )
00101
00102
00106 #define AW_LOGGER_DEFAULT_FLAGS (\
00107 AW_LOGGER_ENABLED | \
00108 AW_LOGGER_CACHEMSG | \
00109 AW_LOGGER_ERR2SYSLOG | \
00110 AW_LOGGER_ERR2STDERR | \
00111 AW_LOGGER_PREPEND_DATE | \
00112 AW_LOGGER_APPEND_NEWLINE \
00113 )
00114
00118 typedef struct aw_logger_struct {
00119
00120 sem_t lock;
00121
00122 int32_t min_level, max_level;
00123
00124 const byte_t *filename;
00125
00126 int32_t fd;
00127
00128 u_int64_t byteswritten;
00129
00130 const byte_t *(*strlevel)(int32_t level);
00131
00132 struct aw_logger_struct *error_logger;
00133
00134
00135
00136
00137 u_int32_t lastrotation;
00138
00139 aw_logger_flag_t flags;
00140
00141 struct aw_logger_struct
00142 *head, *prev, *next;
00143
00144 char *msg;
00145 u_int32_t msg_size;
00146
00147 u_int32_t dup_count;
00148
00149 } aw_logger_t;
00150
00151
00155 typedef struct {
00156
00157
00158 const byte_t *filename;
00159
00160
00161 int fd;
00162
00163
00164 int32_t min_level;
00165
00166
00167 int32_t max_level;
00168
00169
00170 const byte_t *(*strlevel)(int32_t level);
00171
00172
00173 aw_logger_flag_t flags;
00174
00175
00176 aw_logger_t *error_logger;
00177
00178 } aw_logger_params_t;
00179
00180
00188 int32_t aw_logger_init(aw_logger_t *logger, aw_logger_params_t *params);
00189
00196 int32_t aw_logger_clear(aw_logger_t *logger);
00197
00198
00208 int32_t aw_log(aw_logger_t *logger, int32_t level, const char *fmt, ... ) __attribute__ ((format (printf, 3, 4)));
00209
00216 int32_t aw_logger_link(aw_logger_t *logger, aw_logger_t *chain);
00217
00222 void aw_logger_unlink(aw_logger_t *logger);
00223
00229 void aw_logger_setflags(aw_logger_t *logger, aw_logger_flag_t new_flags);
00230
00235 void aw_logger_enable(aw_logger_t *logger);
00236
00241 void aw_logger_disable(aw_logger_t *logger);
00242
00243 #endif