rpm  4.18.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,
37  RPMLOG_DEBUG = 7
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 #define RPMLOG_NPRIS (RPMLOG_DEBUG + 1)
45 
49 typedef enum rpmlogFac_e {
50  RPMLOG_KERN = (0<<3),
51  RPMLOG_USER = (1<<3),
52  RPMLOG_MAIL = (2<<3),
53  RPMLOG_DAEMON = (3<<3),
54  RPMLOG_AUTH = (4<<3),
55  RPMLOG_SYSLOG = (5<<3),
56  RPMLOG_LPR = (6<<3),
57  RPMLOG_NEWS = (7<<3),
58  RPMLOG_UUCP = (8<<3),
59  RPMLOG_CRON = (9<<3),
60  RPMLOG_AUTHPRIV = (10<<3),
61  RPMLOG_FTP = (11<<3),
63  /* other codes through 15 reserved for system use */
64  RPMLOG_LOCAL0 = (16<<3),
65  RPMLOG_LOCAL1 = (17<<3),
66  RPMLOG_LOCAL2 = (18<<3),
67  RPMLOG_LOCAL3 = (19<<3),
68  RPMLOG_LOCAL4 = (20<<3),
69  RPMLOG_LOCAL5 = (21<<3),
70  RPMLOG_LOCAL6 = (22<<3),
71  RPMLOG_LOCAL7 = (23<<3),
73 #define RPMLOG_NFACILITIES 24
74  RPMLOG_ERRMSG = (((unsigned)(RPMLOG_NFACILITIES+0))<<3)
76 
77 #define RPMLOG_FACMASK 0x03f8
78 #define RPMLOG_FAC(p) (((p) & RPMLOG_FACMASK) >> 3)
79 
80 
81 /*
82  * arguments to setlogmask.
83  */
84 #define RPMLOG_MASK(pri) (1 << ((unsigned)(pri)))
85 #define RPMLOG_UPTO(pri) ((1 << (((unsigned)(pri))+1)) - 1)
87 /*
88  * Option flags for openlog.
89  *
90  * RPMLOG_ODELAY no longer does anything.
91  * RPMLOG_NDELAY is the inverse of what it used to be.
92  */
93 #define RPMLOG_PID 0x01
94 #define RPMLOG_CONS 0x02
95 #define RPMLOG_ODELAY 0x04
96 #define RPMLOG_NDELAY 0x08
97 #define RPMLOG_NOWAIT 0x10
98 #define RPMLOG_PERROR 0x20
103 #define RPMLOG_DEFAULT 0x01
104 #define RPMLOG_EXIT 0x02
108 typedef struct rpmlogRec_s * rpmlogRec;
109 
115 const char * rpmlogRecMessage(rpmlogRec rec);
116 
123 
124 typedef void * rpmlogCallbackData;
125 
134 typedef int (*rpmlogCallback) (rpmlogRec rec, rpmlogCallbackData data);
135 
141 int rpmlogGetNrecsByMask(unsigned mask);
142 
147 int rpmlogGetNrecs(void) ;
148 
154 void rpmlogPrintByMask(FILE *f, unsigned mask);
155 
160 void rpmlogPrint(FILE *f);
161 
166 void rpmlogClose (void);
167 
172 void rpmlogOpen (const char * ident, int option, int facility);
173 
179 int rpmlogSetMask (int mask);
180 
184 void rpmlog (int code, const char *fmt, ...) RPM_GNUC_PRINTF(2, 3);
185 
190 const char * rpmlogMessage(void);
191 
199 int rpmlogCode(void);
200 
206 const char * rpmlogLevelPrefix(rpmlogLvl pri);
207 
215 
221 FILE * rpmlogSetFile(FILE * fp);
222 
223 #define rpmSetVerbosity(_lvl) \
224  ((void)rpmlogSetMask( RPMLOG_UPTO( RPMLOG_PRI(_lvl))))
225 #define rpmIncreaseVerbosity() \
226  ((void)rpmlogSetMask(((((unsigned)(rpmlogSetMask(0) & 0xff)) << 1) | 1)))
227 #define rpmDecreaseVerbosity() \
228  ((void)rpmlogSetMask((((int)(rpmlogSetMask(0) & 0xff)) >> 1)))
229 #define rpmIsNormal() \
230  (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_NOTICE ))
231 #define rpmIsVerbose() \
232  (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_INFO ))
233 #define rpmIsDebug() \
234  (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_DEBUG ))
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 #endif /* H_RPMLOG */
int rpmlogGetNrecs(void)
Return number of rpmError() ressages.
rpmlogFac_e
facility codes
Definition: rpmlog.h:49
int rpmlogSetMask(int mask)
Set the log mask level.
int rpmlogGetNrecsByMask(unsigned mask)
Return number of rpmError() messages matching a log mask.
FILE * rpmlogSetFile(FILE *fp)
Set rpmlog file handle.
void rpmlogOpen(const char *ident, int option, int facility)
Open connection to system logger.
const char * rpmlogRecMessage(rpmlogRec rec)
Retrieve log message string from rpmlog record.
const char * rpmlogLevelPrefix(rpmlogLvl pri)
Return translated prefix string (if any) given log level.
void rpmlogPrint(FILE *f)
Print all rpmError() messages.
enum rpmlogLvl_e rpmlogLvl
RPM Log levels.
int(* rpmlogCallback)(rpmlogRec rec, rpmlogCallbackData data)
Definition: rpmlog.h:134
void rpmlog(int code, const char *fmt,...) RPM_GNUC_PRINTF(2
Generate a log message using FMT string and option arguments.
void const char * rpmlogMessage(void)
Return text of last rpmError() message.
rpmlogCallback rpmlogSetCallback(rpmlogCallback cb, rpmlogCallbackData data)
Set rpmlog callback function.
void rpmlogClose(void)
Close desriptor used to write to system logger.
struct rpmlogRec_s * rpmlogRec
Definition: rpmlog.h:108
rpmlogLvl rpmlogRecPriority(rpmlogRec rec)
Retrieve log priority from rpmlog record.
enum rpmlogFac_e rpmlogFac
facility codes
rpmlogLvl_e
RPM Log levels.
Definition: rpmlog.h:29
int rpmlogCode(void)
Return error code from last rpmError() message.
void rpmlogPrintByMask(FILE *f, unsigned mask)
Print all rpmError() messages matching a log mask.
@ RPMLOG_CRON
Definition: rpmlog.h:59
@ RPMLOG_KERN
Definition: rpmlog.h:50
@ RPMLOG_NEWS
Definition: rpmlog.h:57
@ RPMLOG_AUTH
Definition: rpmlog.h:54
@ RPMLOG_LOCAL3
Definition: rpmlog.h:67
@ RPMLOG_LOCAL0
Definition: rpmlog.h:64
@ RPMLOG_SYSLOG
Definition: rpmlog.h:55
@ RPMLOG_LOCAL2
Definition: rpmlog.h:66
@ RPMLOG_LOCAL6
Definition: rpmlog.h:70
@ RPMLOG_LPR
Definition: rpmlog.h:56
@ RPMLOG_ERRMSG
Definition: rpmlog.h:74
@ RPMLOG_DAEMON
Definition: rpmlog.h:53
@ RPMLOG_UUCP
Definition: rpmlog.h:58
@ RPMLOG_LOCAL7
Definition: rpmlog.h:71
@ RPMLOG_LOCAL5
Definition: rpmlog.h:69
@ RPMLOG_FTP
Definition: rpmlog.h:61
@ RPMLOG_USER
Definition: rpmlog.h:51
@ RPMLOG_AUTHPRIV
Definition: rpmlog.h:60
@ RPMLOG_LOCAL4
Definition: rpmlog.h:68
@ RPMLOG_LOCAL1
Definition: rpmlog.h:65
@ RPMLOG_MAIL
Definition: rpmlog.h:52
@ RPMLOG_DEBUG
Definition: rpmlog.h:37
@ RPMLOG_ERR
Definition: rpmlog.h:33
@ RPMLOG_WARNING
Definition: rpmlog.h:34
@ RPMLOG_NOTICE
Definition: rpmlog.h:35
@ RPMLOG_INFO
Definition: rpmlog.h:36
@ RPMLOG_CRIT
Definition: rpmlog.h:32
@ RPMLOG_EMERG
Definition: rpmlog.h:30
@ RPMLOG_ALERT
Definition: rpmlog.h:31
#define RPMLOG_NFACILITIES
Definition: rpmlog.h:73
void * rpmlogCallbackData
Definition: rpmlog.h:124
Miscellaneous utility macros:
#define RPM_GNUC_PRINTF(format_idx, arg_idx)
Definition: rpmutil.h:68