00001 #ifndef H_RPMLOG
00002 #define H_RPMLOG 1
00003
00009 #include <stdarg.h>
00010
00021
00022 typedef enum rpmlogLvl_e {
00023 RPMLOG_EMERG = 0,
00024 RPMLOG_ALERT = 1,
00025 RPMLOG_CRIT = 2,
00026 RPMLOG_ERR = 3,
00027 RPMLOG_WARNING = 4,
00028 RPMLOG_NOTICE = 5,
00029 RPMLOG_INFO = 6,
00030 RPMLOG_DEBUG = 7
00031 } rpmlogLvl;
00032
00033
00034 #define RPMLOG_PRIMASK 0x07
00035
00036 #define RPMLOG_PRI(p) ((p) & RPMLOG_PRIMASK)
00037 #define RPMLOG_MAKEPRI(fac, pri) ((((unsigned)(fac)) << 3) | (pri))
00038
00039 #ifdef RPMLOG_NAMES
00040 #define _RPMLOG_NOPRI 0x10
00041
00042 #define _RPMLOG_MARK RPMLOG_MAKEPRI(RPMLOG_NFACILITIES, 0)
00043 typedef struct _rpmcode {
00044 const char *c_name;
00045 int c_val;
00046 } RPMCODE;
00047
00048 RPMCODE rpmprioritynames[] =
00049 {
00050 { "alert", RPMLOG_ALERT },
00051 { "crit", RPMLOG_CRIT },
00052 { "debug", RPMLOG_DEBUG },
00053 { "emerg", RPMLOG_EMERG },
00054 { "err", RPMLOG_ERR },
00055 { "error", RPMLOG_ERR },
00056 { "info", RPMLOG_INFO },
00057 { "none", _RPMLOG_NOPRI },
00058 { "notice", RPMLOG_NOTICE },
00059 { "panic", RPMLOG_EMERG },
00060 { "warn", RPMLOG_WARNING },
00061 { "warning",RPMLOG_WARNING },
00062 { NULL, -1 }
00063 };
00064 #endif
00065
00069
00070 typedef enum rpmlogFac_e {
00071 RPMLOG_KERN = (0<<3),
00072 RPMLOG_USER = (1<<3),
00073 RPMLOG_MAIL = (2<<3),
00074 RPMLOG_DAEMON = (3<<3),
00075 RPMLOG_AUTH = (4<<3),
00076 RPMLOG_SYSLOG = (5<<3),
00077 RPMLOG_LPR = (6<<3),
00078 RPMLOG_NEWS = (7<<3),
00079 RPMLOG_UUCP = (8<<3),
00080 RPMLOG_CRON = (9<<3),
00081 RPMLOG_AUTHPRIV = (10<<3),
00082 RPMLOG_FTP = (11<<3),
00084
00085 RPMLOG_LOCAL0 = (16<<3),
00086 RPMLOG_LOCAL1 = (17<<3),
00087 RPMLOG_LOCAL2 = (18<<3),
00088 RPMLOG_LOCAL3 = (19<<3),
00089 RPMLOG_LOCAL4 = (20<<3),
00090 RPMLOG_LOCAL5 = (21<<3),
00091 RPMLOG_LOCAL6 = (22<<3),
00092 RPMLOG_LOCAL7 = (23<<3),
00094 #define RPMLOG_NFACILITIES 24
00095 RPMLOG_ERRMSG = (((unsigned)(RPMLOG_NFACILITIES+0))<<3)
00096 } rpmlogFac;
00097
00098
00099 #define RPMLOG_FACMASK 0x03f8
00100 #define RPMLOG_FAC(p) (((p) & RPMLOG_FACMASK) >> 3)
00101
00102
00103 #ifdef RPMLOG_NAMES
00104 RPMCODE facilitynames[] =
00105 {
00106 { "auth", RPMLOG_AUTH },
00107 { "authpriv",RPMLOG_AUTHPRIV },
00108 { "cron", RPMLOG_CRON },
00109 { "daemon", RPMLOG_DAEMON },
00110 { "ftp", RPMLOG_FTP },
00111 { "kern", RPMLOG_KERN },
00112 { "lpr", RPMLOG_LPR },
00113 { "mail", RPMLOG_MAIL },
00114 { "mark", _RPMLOG_MARK },
00115 { "news", RPMLOG_NEWS },
00116 { "security",RPMLOG_AUTH },
00117 { "syslog", RPMLOG_SYSLOG },
00118 { "user", RPMLOG_USER },
00119 { "uucp", RPMLOG_UUCP },
00120 { "local0", RPMLOG_LOCAL0 },
00121 { "local1", RPMLOG_LOCAL1 },
00122 { "local2", RPMLOG_LOCAL2 },
00123 { "local3", RPMLOG_LOCAL3 },
00124 { "local4", RPMLOG_LOCAL4 },
00125 { "local5", RPMLOG_LOCAL5 },
00126 { "local6", RPMLOG_LOCAL6 },
00127 { "local7", RPMLOG_LOCAL7 },
00128 { NULL, -1 }
00129 };
00130 #endif
00131
00132
00133
00134
00135 #define RPMLOG_MASK(pri) (1 << ((unsigned)(pri)))
00136 #define RPMLOG_UPTO(pri) ((1 << (((unsigned)(pri))+1)) - 1)
00138
00139
00140
00141
00142
00143
00144 #define RPMLOG_PID 0x01
00145 #define RPMLOG_CONS 0x02
00146 #define RPMLOG_ODELAY 0x04
00147 #define RPMLOG_NDELAY 0x08
00148 #define RPMLOG_NOWAIT 0x10
00149 #define RPMLOG_PERROR 0x20
00153 typedef struct rpmlogRec_s * rpmlogRec;
00154
00157 typedef void * rpmlogCallbackData;
00158
00167 typedef int (*rpmlogCallback) (rpmlogRec rec, rpmlogCallbackData data)
00168 ;
00169
00173 #define RPMLOG_DEFAULT 0x01
00174 #define RPMLOG_EXIT 0x02
00176 #if defined(_RPMLOG_INTERNAL)
00177
00179 struct rpmlogRec_s {
00180 int code;
00181 rpmlogLvl pri;
00182
00183 const char * message;
00184 };
00185 #endif
00186
00187 #ifdef __cplusplus
00188 extern "C" {
00189 #endif
00190
00196
00197 const char * rpmlogLevelPrefix(rpmlogLvl pri)
00198 ;
00199
00206 rpmlogCallback rpmlogSetCallback(rpmlogCallback cb, rpmlogCallbackData data)
00207
00208 ;
00209
00216 void rpmlogGetCallback(rpmlogCallback *cb, rpmlogCallbackData *data)
00217
00218 ;
00219
00224 int rpmlogGetNrecs(void)
00225 ;
00226
00232
00233 const char * rpmlogRecMessage(rpmlogRec rec)
00234 ;
00235
00241 rpmlogLvl rpmlogRecPriority(rpmlogRec rec)
00242 ;
00243
00248 void rpmlogPrint( FILE *f)
00249 ;
00250
00255
00256 void rpmlogClose (void)
00257
00258 ;
00259
00264
00265 void rpmlogOpen (const char * ident, int option, int facility)
00266
00267 ;
00268
00274 int rpmlogSetMask (int mask)
00275
00276 ;
00277
00282
00283 void _rpmlog (int code, const char *fmt, ...)
00284 #if defined(__GNUC__) && __GNUC__ >= 2
00285
00286 __attribute__((format (printf, 2, 3)))
00287 #endif
00288 ;
00289
00293 void vrpmlog (unsigned code, const char * fmt, va_list ap)
00294 ;
00295
00296
00297 static inline
00298 void rpmlog (int code, const char *fmt, ...)
00299
00300 {
00301 unsigned pri = RPMLOG_PRI(code);
00302 unsigned mask = RPMLOG_MASK(pri);
00303
00304 if (mask & rpmlogSetMask(0)) {
00305 va_list ap;
00306 va_start(ap, fmt);
00307 vrpmlog(code, fmt, ap);
00308 va_end(ap);
00309 }
00310 }
00311
00312
00317
00318 const char * rpmlogMessage(void)
00319 ;
00320
00321
00329 int rpmlogCode(void)
00330 ;
00331
00337
00338 FILE * rpmlogSetFile( FILE * fp)
00339
00340 ;
00341
00342
00343 #ifdef __cplusplus
00344 }
00345 #endif
00346
00347 #endif