rpm  4.14.0
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 
48 typedef enum rpmlogFac_e {
49  RPMLOG_KERN = (0<<3),
50  RPMLOG_USER = (1<<3),
51  RPMLOG_MAIL = (2<<3),
52  RPMLOG_DAEMON = (3<<3),
53  RPMLOG_AUTH = (4<<3),
54  RPMLOG_SYSLOG = (5<<3),
55  RPMLOG_LPR = (6<<3),
56  RPMLOG_NEWS = (7<<3),
57  RPMLOG_UUCP = (8<<3),
58  RPMLOG_CRON = (9<<3),
59  RPMLOG_AUTHPRIV = (10<<3),
60  RPMLOG_FTP = (11<<3),
62  /* other codes through 15 reserved for system use */
63  RPMLOG_LOCAL0 = (16<<3),
64  RPMLOG_LOCAL1 = (17<<3),
65  RPMLOG_LOCAL2 = (18<<3),
66  RPMLOG_LOCAL3 = (19<<3),
67  RPMLOG_LOCAL4 = (20<<3),
68  RPMLOG_LOCAL5 = (21<<3),
69  RPMLOG_LOCAL6 = (22<<3),
70  RPMLOG_LOCAL7 = (23<<3),
72 #define RPMLOG_NFACILITIES 24
73  RPMLOG_ERRMSG = (((unsigned)(RPMLOG_NFACILITIES+0))<<3)
74 } rpmlogFac;
75 
76 #define RPMLOG_FACMASK 0x03f8
77 #define RPMLOG_FAC(p) (((p) & RPMLOG_FACMASK) >> 3)
78 
79 
80 /*
81  * arguments to setlogmask.
82  */
83 #define RPMLOG_MASK(pri) (1 << ((unsigned)(pri)))
84 #define RPMLOG_UPTO(pri) ((1 << (((unsigned)(pri))+1)) - 1)
86 /*
87  * Option flags for openlog.
88  *
89  * RPMLOG_ODELAY no longer does anything.
90  * RPMLOG_NDELAY is the inverse of what it used to be.
91  */
92 #define RPMLOG_PID 0x01
93 #define RPMLOG_CONS 0x02
94 #define RPMLOG_ODELAY 0x04
95 #define RPMLOG_NDELAY 0x08
96 #define RPMLOG_NOWAIT 0x10
97 #define RPMLOG_PERROR 0x20
99 /* \ingroup rpmlog
100  * Option flags for callback return value.
101  */
102 #define RPMLOG_DEFAULT 0x01
103 #define RPMLOG_EXIT 0x02
107 typedef struct rpmlogRec_s * rpmlogRec;
108 
114 const char * rpmlogRecMessage(rpmlogRec rec);
115 
122 
123 typedef void * rpmlogCallbackData;
124 
133 typedef int (*rpmlogCallback) (rpmlogRec rec, rpmlogCallbackData data);
134 
139 int rpmlogGetNrecs(void) ;
140 
145 void rpmlogPrint(FILE *f);
146 
151 void rpmlogClose (void);
152 
157 void rpmlogOpen (const char * ident, int option, int facility);
158 
164 int rpmlogSetMask (int mask);
165 
169 void rpmlog (int code, const char *fmt, ...) RPM_GNUC_PRINTF(2, 3);
170 
175 const char * rpmlogMessage(void);
176 
184 int rpmlogCode(void);
185 
191 const char * rpmlogLevelPrefix(rpmlogLvl pri);
192 
199 rpmlogCallback rpmlogSetCallback(rpmlogCallback cb, rpmlogCallbackData data);
200 
206 FILE * rpmlogSetFile(FILE * fp);
207 
208 #define rpmSetVerbosity(_lvl) \
209  ((void)rpmlogSetMask( RPMLOG_UPTO( RPMLOG_PRI(_lvl))))
210 #define rpmIncreaseVerbosity() \
211  ((void)rpmlogSetMask(((((unsigned)(rpmlogSetMask(0) & 0xff)) << 1) | 1)))
212 #define rpmDecreaseVerbosity() \
213  ((void)rpmlogSetMask((((int)(rpmlogSetMask(0) & 0xff)) >> 1)))
214 #define rpmIsNormal() \
215  (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_NOTICE ))
216 #define rpmIsVerbose() \
217  (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_INFO ))
218 #define rpmIsDebug() \
219  (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_DEBUG ))
220 
221 #ifdef __cplusplus
222 }
223 #endif
224 
225 #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:123
enum rpmlogFac_e rpmlogFac
facility codes
struct rpmlogRec_s * rpmlogRec
Definition: rpmlog.h:107
void rpmlogClose(void)
Close desriptor used to write to system logger.
void const char * rpmlogMessage(void)
Return text of last rpmError() message.
int(* rpmlogCallback)(rpmlogRec rec, rpmlogCallbackData data)
Definition: rpmlog.h:133
int rpmlogSetMask(int mask)
Set the log mask level.
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:68
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:48
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.