6 * Yet Another syslog(3) API clone.
7 * Used to unify rpmError() and rpmMessage() interfaces in rpm.
19 * priorities/facilities are encoded into a single 32-bit quantity, where the
20 * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
21 * (0-big number). Both the priorities and the facilities map roughly
22 * one-to-one to strings in the syslogd(8) source code. This mapping is
23 * included in this file.
25 * priorities (these are ordered)
27 typedef enum rpmlogLvl_e {
28 RPMLOG_EMERG = 0, /*!< system is unusable */
29 RPMLOG_ALERT = 1, /*!< action must be taken immediately */
30 RPMLOG_CRIT = 2, /*!< critical conditions */
31 RPMLOG_ERR = 3, /*!< error conditions */
32 RPMLOG_WARNING = 4, /*!< warning conditions */
33 RPMLOG_NOTICE = 5, /*!< normal but significant condition */
34 RPMLOG_INFO = 6, /*!< informational */
35 RPMLOG_DEBUG = 7 /*!< debug-level messages */
38 #define RPMLOG_PRIMASK 0x07 /* mask to extract priority part (internal) */
39 /* extract priority */
40 #define RPMLOG_PRI(p) ((p) & RPMLOG_PRIMASK)
41 #define RPMLOG_MAKEPRI(fac, pri) ((((unsigned)(fac)) << 3) | (pri))
44 #define _RPMLOG_NOPRI 0x10 /* the "no priority" priority */
46 #define _RPMLOG_MARK RPMLOG_MAKEPRI(RPMLOG_NFACILITIES, 0)
47 typedef struct _rpmcode {
52 RPMCODE rpmprioritynames[] =
54 { "alert", RPMLOG_ALERT },
55 { "crit", RPMLOG_CRIT },
56 { "debug", RPMLOG_DEBUG },
57 { "emerg", RPMLOG_EMERG },
58 { "err", RPMLOG_ERR },
59 { "error", RPMLOG_ERR }, /* DEPRECATED */
60 { "info", RPMLOG_INFO },
61 { "none", _RPMLOG_NOPRI }, /* INTERNAL */
62 { "notice", RPMLOG_NOTICE },
63 { "panic", RPMLOG_EMERG }, /* DEPRECATED */
64 { "warn", RPMLOG_WARNING }, /* DEPRECATED */
65 { "warning",RPMLOG_WARNING },
73 typedef enum rpmlogFac_e {
74 RPMLOG_KERN = (0<<3), /*!< kernel messages */
75 RPMLOG_USER = (1<<3), /*!< random user-level messages */
76 RPMLOG_MAIL = (2<<3), /*!< mail system */
77 RPMLOG_DAEMON = (3<<3), /*!< system daemons */
78 RPMLOG_AUTH = (4<<3), /*!< security/authorization messages */
79 RPMLOG_SYSLOG = (5<<3), /*!< messages generated internally by syslogd */
80 RPMLOG_LPR = (6<<3), /*!< line printer subsystem */
81 RPMLOG_NEWS = (7<<3), /*!< network news subsystem */
82 RPMLOG_UUCP = (8<<3), /*!< UUCP subsystem */
83 RPMLOG_CRON = (9<<3), /*!< clock daemon */
84 RPMLOG_AUTHPRIV = (10<<3), /*!< security/authorization messages (private) */
85 RPMLOG_FTP = (11<<3), /*!< ftp daemon */
87 /* other codes through 15 reserved for system use */
88 RPMLOG_LOCAL0 = (16<<3), /*!< reserved for local use */
89 RPMLOG_LOCAL1 = (17<<3), /*!< reserved for local use */
90 RPMLOG_LOCAL2 = (18<<3), /*!< reserved for local use */
91 RPMLOG_LOCAL3 = (19<<3), /*!< reserved for local use */
92 RPMLOG_LOCAL4 = (20<<3), /*!< reserved for local use */
93 RPMLOG_LOCAL5 = (21<<3), /*!< reserved for local use */
94 RPMLOG_LOCAL6 = (22<<3), /*!< reserved for local use */
95 RPMLOG_LOCAL7 = (23<<3), /*!< reserved for local use */
97 #define RPMLOG_NFACILITIES 24 /*!< current number of facilities */
98 RPMLOG_ERRMSG = (((unsigned)(RPMLOG_NFACILITIES+0))<<3)
101 #define RPMLOG_FACMASK 0x03f8 /*!< mask to extract facility part */
102 #define RPMLOG_FAC(p) (((p) & RPMLOG_FACMASK) >> 3)
106 RPMCODE facilitynames[] =
108 { "auth", RPMLOG_AUTH },
109 { "authpriv",RPMLOG_AUTHPRIV },
110 { "cron", RPMLOG_CRON },
111 { "daemon", RPMLOG_DAEMON },
112 { "ftp", RPMLOG_FTP },
113 { "kern", RPMLOG_KERN },
114 { "lpr", RPMLOG_LPR },
115 { "mail", RPMLOG_MAIL },
116 { "mark", _RPMLOG_MARK }, /* INTERNAL */
117 { "news", RPMLOG_NEWS },
118 { "security",RPMLOG_AUTH }, /* DEPRECATED */
119 { "syslog", RPMLOG_SYSLOG },
120 { "user", RPMLOG_USER },
121 { "uucp", RPMLOG_UUCP },
122 { "local0", RPMLOG_LOCAL0 },
123 { "local1", RPMLOG_LOCAL1 },
124 { "local2", RPMLOG_LOCAL2 },
125 { "local3", RPMLOG_LOCAL3 },
126 { "local4", RPMLOG_LOCAL4 },
127 { "local5", RPMLOG_LOCAL5 },
128 { "local6", RPMLOG_LOCAL6 },
129 { "local7", RPMLOG_LOCAL7 },
135 * arguments to setlogmask.
137 #define RPMLOG_MASK(pri) (1 << ((unsigned)(pri))) /*!< mask for one priority */
138 #define RPMLOG_UPTO(pri) ((1 << (((unsigned)(pri))+1)) - 1) /*!< all priorities through pri */
141 * Option flags for openlog.
143 * RPMLOG_ODELAY no longer does anything.
144 * RPMLOG_NDELAY is the inverse of what it used to be.
146 #define RPMLOG_PID 0x01 /*!< log the pid with each message */
147 #define RPMLOG_CONS 0x02 /*!< log on the console if errors in sending */
148 #define RPMLOG_ODELAY 0x04 /*!< delay open until first syslog() (default) */
149 #define RPMLOG_NDELAY 0x08 /*!< don't delay open */
150 #define RPMLOG_NOWAIT 0x10 /*!< don't wait for console forks: DEPRECATED */
151 #define RPMLOG_PERROR 0x20 /*!< log to stderr as well */
154 * Option flags for callback return value.
156 #define RPMLOG_DEFAULT 0x01 /*!< perform default logging */
157 #define RPMLOG_EXIT 0x02 /*!< exit after logging */
161 typedef struct rpmlogRec_s * rpmlogRec;
164 * Retrieve log message string from rpmlog record
165 * @param rec rpmlog record
166 * @return log message
168 const char * rpmlogRecMessage(rpmlogRec rec);
171 * Retrieve log priority from rpmlog record
172 * @param rec rpmlog record
173 * @return log priority
175 rpmlogLvl rpmlogRecPriority(rpmlogRec rec);
177 typedef void * rpmlogCallbackData;
180 * @param rec rpmlog record
181 * @param data private callback data
182 * @return flags to define further behavior:
183 * RPMLOG_DEFAULT to perform default logging,
184 * RPMLOG_EXIT to exit after processing,
185 * 0 to return after callback
187 typedef int (*rpmlogCallback) (rpmlogRec rec, rpmlogCallbackData data);
190 * Return number of rpmError() ressages.
191 * @return number of messages
193 int rpmlogGetNrecs(void) ;
196 * Print all rpmError() messages.
197 * @param f file handle (NULL uses stderr)
199 void rpmlogPrint(FILE *f);
202 * Close desriptor used to write to system logger.
205 void rpmlogClose (void);
208 * Open connection to system logger.
211 void rpmlogOpen (const char * ident, int option, int facility);
214 * Set the log mask level.
215 * @param mask log mask (0 is no operation)
216 * @return previous log mask
218 int rpmlogSetMask (int mask);
221 * Generate a log message using FMT string and option arguments.
223 void rpmlog (int code, const char *fmt, ...);
226 * Return text of last rpmError() message.
227 * @return text of last message
229 const char * rpmlogMessage(void);
232 * Return error code from last rpmError() message.
233 * @deprecated Perl-RPM needs, what's really needed is predictable, non-i18n
234 * encumbered, error text that can be retrieved through rpmlogMessage()
236 * @return code from last message
238 int rpmlogCode(void);
241 * Return translated prefix string (if any) given log level.
242 * @param pri log priority
243 * @return message prefix (or "" for none)
245 const char * rpmlogLevelPrefix(rpmlogLvl pri);
248 * Set rpmlog callback function.
249 * @param cb rpmlog callback function
250 * @param data callback private (user) data
251 * @return previous rpmlog callback function
253 rpmlogCallback rpmlogSetCallback(rpmlogCallback cb, rpmlogCallbackData data);
256 * Set rpmlog file handle.
257 * @param fp rpmlog file handle (NULL uses stdout/stderr)
258 * @return previous rpmlog file handle
260 FILE * rpmlogSetFile(FILE * fp);
262 #define rpmSetVerbosity(_lvl) \
263 ((void)rpmlogSetMask( RPMLOG_UPTO( RPMLOG_PRI(_lvl))))
264 #define rpmIncreaseVerbosity() \
265 ((void)rpmlogSetMask(((((unsigned)(rpmlogSetMask(0) & 0xff)) << 1) | 1)))
266 #define rpmDecreaseVerbosity() \
267 ((void)rpmlogSetMask((((int)(rpmlogSetMask(0) & 0xff)) >> 1)))
268 #define rpmIsNormal() \
269 (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_NOTICE ))
270 #define rpmIsVerbose() \
271 (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_INFO ))
272 #define rpmIsDebug() \
273 (rpmlogSetMask(0) >= RPMLOG_MASK( RPMLOG_DEBUG ))
279 #endif /* H_RPMLOG */