00001 #ifndef H_RPMLOG
00002 #define H_RPMLOG 1
00003
00010 #include <stdarg.h>
00011 #include <stdio.h>
00012
00013 #include <rpm/rpmutil.h>
00014
00015 #ifdef __cplusplus
00016 extern "C" {
00017 #endif
00018
00029 typedef enum rpmlogLvl_e {
00030 RPMLOG_EMERG = 0,
00031 RPMLOG_ALERT = 1,
00032 RPMLOG_CRIT = 2,
00033 RPMLOG_ERR = 3,
00034 RPMLOG_WARNING = 4,
00035 RPMLOG_NOTICE = 5,
00036 RPMLOG_INFO = 6,
00037 RPMLOG_DEBUG = 7
00038 } rpmlogLvl;
00039
00040 #define RPMLOG_PRIMASK 0x07
00041
00042 #define RPMLOG_PRI(p) ((p) & RPMLOG_PRIMASK)
00043 #define RPMLOG_MAKEPRI(fac, pri) ((((unsigned)(fac)) << 3) | (pri))
00044
00045 #ifdef RPMLOG_NAMES
00046 #define _RPMLOG_NOPRI 0x10
00047
00048 #define _RPMLOG_MARK RPMLOG_MAKEPRI(RPMLOG_NFACILITIES, 0)
00049 typedef struct _rpmcode {
00050 const char *c_name;
00051 int c_val;
00052 } RPMCODE;
00053
00054 RPMCODE rpmprioritynames[] =
00055 {
00056 { "alert", RPMLOG_ALERT },
00057 { "crit", RPMLOG_CRIT },
00058 { "debug", RPMLOG_DEBUG },
00059 { "emerg", RPMLOG_EMERG },
00060 { "err", RPMLOG_ERR },
00061 { "error", RPMLOG_ERR },
00062 { "info", RPMLOG_INFO },
00063 { "none", _RPMLOG_NOPRI },
00064 { "notice", RPMLOG_NOTICE },
00065 { "panic", RPMLOG_EMERG },
00066 { "warn", RPMLOG_WARNING },
00067 { "warning",RPMLOG_WARNING },
00068 { NULL, -1 }
00069 };
00070 #endif
00071
00075 typedef enum rpmlogFac_e {
00076 RPMLOG_KERN = (0<<3),
00077 RPMLOG_USER = (1<<3),
00078 RPMLOG_MAIL = (2<<3),
00079 RPMLOG_DAEMON = (3<<3),
00080 RPMLOG_AUTH = (4<<3),
00081 RPMLOG_SYSLOG = (5<<3),
00082 RPMLOG_LPR = (6<<3),
00083 RPMLOG_NEWS = (7<<3),
00084 RPMLOG_UUCP = (8<<3),
00085 RPMLOG_CRON = (9<<3),
00086 RPMLOG_AUTHPRIV = (10<<3),
00087 RPMLOG_FTP = (11<<3),
00089
00090 RPMLOG_LOCAL0 = (16<<3),
00091 RPMLOG_LOCAL1 = (17<<3),
00092 RPMLOG_LOCAL2 = (18<<3),
00093 RPMLOG_LOCAL3 = (19<<3),
00094 RPMLOG_LOCAL4 = (20<<3),
00095 RPMLOG_LOCAL5 = (21<<3),
00096 RPMLOG_LOCAL6 = (22<<3),
00097 RPMLOG_LOCAL7 = (23<<3),
00099 #define RPMLOG_NFACILITIES 24
00100 RPMLOG_ERRMSG = (((unsigned)(RPMLOG_NFACILITIES+0))<<3)
00101 } rpmlogFac;
00102
00103 #define RPMLOG_FACMASK 0x03f8
00104 #define RPMLOG_FAC(p) (((p) & RPMLOG_FACMASK) >> 3)
00105
00106
00107 #ifdef RPMLOG_NAMES
00108 RPMCODE facilitynames[] =
00109 {
00110 { "auth", RPMLOG_AUTH },
00111 { "authpriv",RPMLOG_AUTHPRIV },
00112 { "cron", RPMLOG_CRON },
00113 { "daemon", RPMLOG_DAEMON },
00114 { "ftp", RPMLOG_FTP },
00115 { "kern", RPMLOG_KERN },
00116 { "lpr", RPMLOG_LPR },
00117 { "mail", RPMLOG_MAIL },
00118 { "mark", _RPMLOG_MARK },
00119 { "news", RPMLOG_NEWS },
00120 { "security",RPMLOG_AUTH },
00121 { "syslog", RPMLOG_SYSLOG },
00122 { "user", RPMLOG_USER },
00123 { "uucp", RPMLOG_UUCP },
00124 { "local0", RPMLOG_LOCAL0 },
00125 { "local1", RPMLOG_LOCAL1 },
00126 { "local2", RPMLOG_LOCAL2 },
00127 { "local3", RPMLOG_LOCAL3 },
00128 { "local4", RPMLOG_LOCAL4 },
00129 { "local5", RPMLOG_LOCAL5 },
00130 { "local6", RPMLOG_LOCAL6 },
00131 { "local7", RPMLOG_LOCAL7 },
00132 { NULL, -1 }
00133 };
00134 #endif
00135
00136
00137
00138
00139 #define RPMLOG_MASK(pri) (1 << ((unsigned)(pri)))
00140 #define RPMLOG_UPTO(pri) ((1 << (((unsigned)(pri))+1)) - 1)
00142
00143
00144
00145
00146
00147
00148 #define RPMLOG_PID 0x01
00149 #define RPMLOG_CONS 0x02
00150 #define RPMLOG_ODELAY 0x04
00151 #define RPMLOG_NDELAY 0x08
00152 #define RPMLOG_NOWAIT 0x10
00153 #define RPMLOG_PERROR 0x20
00155
00156
00157
00158 #define RPMLOG_DEFAULT 0x01
00159 #define RPMLOG_EXIT 0x02
00163 typedef struct rpmlogRec_s * rpmlogRec;
00164
00170 const char * rpmlogRecMessage(rpmlogRec rec);
00171
00177 rpmlogLvl rpmlogRecPriority(rpmlogRec rec);
00178
00179 typedef void * rpmlogCallbackData;
00180
00189 typedef int (*rpmlogCallback) (rpmlogRec rec, rpmlogCallbackData data);
00190
00195 int rpmlogGetNrecs(void) ;
00196
00201 void rpmlogPrint(FILE *f);
00202
00207 void rpmlogClose (void);
00208
00213 void rpmlogOpen (const char * ident, int option, int facility);
00214
00220 int rpmlogSetMask (int mask);
00221
00225 void rpmlog (int code, const char *fmt, ...) RPM_GNUC_PRINTF(2, 3);
00226
00231 const char * rpmlogMessage(void);
00232
00240 int rpmlogCode(void);
00241
00247 const char * rpmlogLevelPrefix(rpmlogLvl pri);
00248
00255 rpmlogCallback rpmlogSetCallback(rpmlogCallback cb, rpmlogCallbackData data);
00256
00262 FILE * rpmlogSetFile(FILE * fp);
00263
00264 #define rpmSetVerbosity(_lvl) \
00265 ((void)rpmlogSetMask( RPMLOG_UPTO( RPMLOG_PRI(_lvl))))
00266 #define rpmIncreaseVerbosity() \
00267 ((void)rpmlogSetMask(((((unsigned)(rpmlogSetMask(0) & 0xff)) << 1) | 1)))
00268 #define rpmDecreaseVerbosity() \
00269 ((void)rpmlogSetMask((((int)(rpmlogSetMask(0) & 0xff)) >> 1)))
00270 #define rpmIsNormal() \
00271 (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_NOTICE ))
00272 #define rpmIsVerbose() \
00273 (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_INFO ))
00274 #define rpmIsDebug() \
00275 (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_DEBUG ))
00276
00277 #ifdef __cplusplus
00278 }
00279 #endif
00280
00281 #endif