rpm  4.12.0.1
rpmlog.h
Go to the documentation of this file.
1 #ifndef H_RPMLOG
2 #define H_RPMLOG 1
3 
10 #include <stdarg.h>
11 #include <stdio.h>
12 
13 #include <rpm/rpmutil.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
29 typedef enum rpmlogLvl_e {
33  RPMLOG_ERR = 3,
38 } rpmlogLvl;
39 
40 #define RPMLOG_PRIMASK 0x07 /* mask to extract priority part (internal) */
41  /* extract priority */
42 #define RPMLOG_PRI(p) ((p) & RPMLOG_PRIMASK)
43 #define RPMLOG_MAKEPRI(fac, pri) ((((unsigned)(fac)) << 3) | (pri))
44 
45 #ifdef RPMLOG_NAMES
46 #define _RPMLOG_NOPRI 0x10 /* the "no priority" priority */
47  /* mark "facility" */
48 #define _RPMLOG_MARK RPMLOG_MAKEPRI(RPMLOG_NFACILITIES, 0)
49 typedef struct _rpmcode {
50  const char *c_name;
51  int c_val;
52 } RPMCODE;
53 
54 RPMCODE rpmprioritynames[] =
55  {
56  { "alert", RPMLOG_ALERT },
57  { "crit", RPMLOG_CRIT },
58  { "debug", RPMLOG_DEBUG },
59  { "emerg", RPMLOG_EMERG },
60  { "err", RPMLOG_ERR },
61  { "error", RPMLOG_ERR }, /* DEPRECATED */
62  { "info", RPMLOG_INFO },
63  { "none", _RPMLOG_NOPRI }, /* INTERNAL */
64  { "notice", RPMLOG_NOTICE },
65  { "panic", RPMLOG_EMERG }, /* DEPRECATED */
66  { "warn", RPMLOG_WARNING }, /* DEPRECATED */
67  { "warning",RPMLOG_WARNING },
68  { NULL, -1 }
69  };
70 #endif
71 
75 typedef enum rpmlogFac_e {
76  RPMLOG_KERN = (0<<3),
77  RPMLOG_USER = (1<<3),
78  RPMLOG_MAIL = (2<<3),
79  RPMLOG_DAEMON = (3<<3),
80  RPMLOG_AUTH = (4<<3),
81  RPMLOG_SYSLOG = (5<<3),
82  RPMLOG_LPR = (6<<3),
83  RPMLOG_NEWS = (7<<3),
84  RPMLOG_UUCP = (8<<3),
85  RPMLOG_CRON = (9<<3),
86  RPMLOG_AUTHPRIV = (10<<3),
87  RPMLOG_FTP = (11<<3),
89  /* other codes through 15 reserved for system use */
90  RPMLOG_LOCAL0 = (16<<3),
91  RPMLOG_LOCAL1 = (17<<3),
92  RPMLOG_LOCAL2 = (18<<3),
93  RPMLOG_LOCAL3 = (19<<3),
94  RPMLOG_LOCAL4 = (20<<3),
95  RPMLOG_LOCAL5 = (21<<3),
96  RPMLOG_LOCAL6 = (22<<3),
97  RPMLOG_LOCAL7 = (23<<3),
99 #define RPMLOG_NFACILITIES 24
100  RPMLOG_ERRMSG = (((unsigned)(RPMLOG_NFACILITIES+0))<<3)
101 } rpmlogFac;
102 
103 #define RPMLOG_FACMASK 0x03f8
104 #define RPMLOG_FAC(p) (((p) & RPMLOG_FACMASK) >> 3)
105 
106 
107 #ifdef RPMLOG_NAMES
108 RPMCODE facilitynames[] =
109  {
110  { "auth", RPMLOG_AUTH },
111  { "authpriv",RPMLOG_AUTHPRIV },
112  { "cron", RPMLOG_CRON },
113  { "daemon", RPMLOG_DAEMON },
114  { "ftp", RPMLOG_FTP },
115  { "kern", RPMLOG_KERN },
116  { "lpr", RPMLOG_LPR },
117  { "mail", RPMLOG_MAIL },
118  { "mark", _RPMLOG_MARK }, /* INTERNAL */
119  { "news", RPMLOG_NEWS },
120  { "security",RPMLOG_AUTH }, /* DEPRECATED */
121  { "syslog", RPMLOG_SYSLOG },
122  { "user", RPMLOG_USER },
123  { "uucp", RPMLOG_UUCP },
124  { "local0", RPMLOG_LOCAL0 },
125  { "local1", RPMLOG_LOCAL1 },
126  { "local2", RPMLOG_LOCAL2 },
127  { "local3", RPMLOG_LOCAL3 },
128  { "local4", RPMLOG_LOCAL4 },
129  { "local5", RPMLOG_LOCAL5 },
130  { "local6", RPMLOG_LOCAL6 },
131  { "local7", RPMLOG_LOCAL7 },
132  { NULL, -1 }
133  };
134 #endif
135 
136 /*
137  * arguments to setlogmask.
138  */
139 #define RPMLOG_MASK(pri) (1 << ((unsigned)(pri)))
140 #define RPMLOG_UPTO(pri) ((1 << (((unsigned)(pri))+1)) - 1)
142 /*
143  * Option flags for openlog.
144  *
145  * RPMLOG_ODELAY no longer does anything.
146  * RPMLOG_NDELAY is the inverse of what it used to be.
147  */
148 #define RPMLOG_PID 0x01
149 #define RPMLOG_CONS 0x02
150 #define RPMLOG_ODELAY 0x04
151 #define RPMLOG_NDELAY 0x08
152 #define RPMLOG_NOWAIT 0x10
153 #define RPMLOG_PERROR 0x20
155 /* \ingroup rpmlog
156  * Option flags for callback return value.
157  */
158 #define RPMLOG_DEFAULT 0x01
159 #define RPMLOG_EXIT 0x02
163 typedef struct rpmlogRec_s * rpmlogRec;
164 
170 const char * rpmlogRecMessage(rpmlogRec rec);
171 
178 
179 typedef void * rpmlogCallbackData;
180 
189 typedef int (*rpmlogCallback) (rpmlogRec rec, rpmlogCallbackData data);
190 
195 int rpmlogGetNrecs(void) ;
196 
201 void rpmlogPrint(FILE *f);
202 
207 void rpmlogClose (void);
208 
213 void rpmlogOpen (const char * ident, int option, int facility);
214 
220 int rpmlogSetMask (int mask);
221 
225 void rpmlog (int code, const char *fmt, ...) RPM_GNUC_PRINTF(2, 3);
226 
231 const char * rpmlogMessage(void);
232 
240 int rpmlogCode(void);
241 
247 const char * rpmlogLevelPrefix(rpmlogLvl pri);
248 
255 rpmlogCallback rpmlogSetCallback(rpmlogCallback cb, rpmlogCallbackData data);
256 
262 FILE * rpmlogSetFile(FILE * fp);
263 
264 #define rpmSetVerbosity(_lvl) \
265  ((void)rpmlogSetMask( RPMLOG_UPTO( RPMLOG_PRI(_lvl))))
266 #define rpmIncreaseVerbosity() \
267  ((void)rpmlogSetMask(((((unsigned)(rpmlogSetMask(0) & 0xff)) << 1) | 1)))
268 #define rpmDecreaseVerbosity() \
269  ((void)rpmlogSetMask((((int)(rpmlogSetMask(0) & 0xff)) >> 1)))
270 #define rpmIsNormal() \
271  (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_NOTICE ))
272 #define rpmIsVerbose() \
273  (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_INFO ))
274 #define rpmIsDebug() \
275  (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_DEBUG ))
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #endif /* H_RPMLOG */
const char * rpmlogLevelPrefix(rpmlogLvl pri)
Return translated prefix string (if any) given log level.
FILE * rpmlogSetFile(FILE *fp)
Set rpmlog file handle.
void * rpmlogCallbackData
Definition: rpmlog.h:179
enum rpmlogFac_e rpmlogFac
facility codes
struct rpmlogRec_s * rpmlogRec
Definition: rpmlog.h:163
void rpmlogClose(void)
Close desriptor used to write to system logger.
void const char * rpmlogMessage(void)
Return text of last rpmError() message.
int rpmlogSetMask(int mask)
Set the log mask level.
int(* rpmlogCallback)(rpmlogRec rec, rpmlogCallbackData data)
Definition: rpmlog.h:189
rpmlogLvl rpmlogRecPriority(rpmlogRec rec)
Retrieve log priority from rpmlog record.
void rpmlogOpen(const char *ident, int option, int facility)
Open connection to system logger.
#define RPM_GNUC_PRINTF(format_idx, arg_idx)
Definition: rpmutil.h:67
void rpmlog(int code, const char *fmt,...) RPM_GNUC_PRINTF(2
Generate a log message using FMT string and option arguments.
rpmlogCallback rpmlogSetCallback(rpmlogCallback cb, rpmlogCallbackData data)
Set rpmlog callback function.
int rpmlogCode(void)
Return error code from last rpmError() message.
enum rpmlogLvl_e rpmlogLvl
RPM Log levels.
void rpmlogPrint(FILE *f)
Print all rpmError() messages.
rpmlogFac_e
facility codes
Definition: rpmlog.h:75
const char * rpmlogRecMessage(rpmlogRec rec)
Retrieve log message string from rpmlog record.
rpmlogLvl_e
RPM Log levels.
Definition: rpmlog.h:29
int rpmlogGetNrecs(void)
Return number of rpmError() ressages.