11 /*@access rpmlogRec @*/
14 static rpmlogRec recs = NULL;
16 int rpmlogGetNrecs(void)
21 const char * rpmlogMessage(void)
24 return recs[nrecs-1].message;
25 return _("(no error)");
28 void rpmlogPrint(FILE *f)
35 for (i = 0; i < nrecs; i++) {
36 rpmlogRec rec = recs + i;
37 if (rec->message && *rec->message)
38 fprintf(f, " %s\n", rec->message);
42 void rpmlogClose (void)
46 for (i = 0; i < nrecs; i++) {
47 rpmlogRec rec = recs + i;
49 free((void *)rec->message);
58 void rpmlogOpen (const char *ident, int option, int facility)
62 static int rpmlogMask = RPMLOG_UPTO( RPMLOG_NOTICE );
63 static int rpmlogFacility = RPMLOG_USER;
65 int rpmlogSetMask (int mask)
67 int omask = rpmlogMask;
73 static rpmlogCallback _rpmlogCallback = NULL;
75 rpmlogCallback rpmlogSetCallback(rpmlogCallback cb)
77 rpmlogCallback ocb = _rpmlogCallback;
82 static char *rpmlogMsgPrefix[] = {
83 N_("fatal error: "),/*!< RPMLOG_EMERG */
84 N_("fatal error: "),/*!< RPMLOG_ALERT */
85 N_("fatal error: "),/*!< RPMLOG_CRIT */
86 N_("error: "), /*!< RPMLOG_ERR */
87 N_("warning: "), /*!< RPMLOG_WARNING */
88 "", /*!< RPMLOG_NOTICE */
89 "", /*!< RPMLOG_INFO */
90 "D: ", /*!< RPMLOG_DEBUG */
93 static void vrpmlog (int code, const char *fmt, va_list ap)
95 int pri = RPMLOG_PRI(code);
96 int mask = RPMLOG_MASK(pri);
97 int fac = RPMLOG_FAC(code);
98 char msgbuf[BUFSIZ], *msg;
99 FILE * msgout = stderr;
102 if ((mask & rpmlogMask) == 0)
105 vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap);
106 msgbuf[sizeof(msgbuf) - 1] = '\0';
109 /* Save copy of all messages at warning (or below == "more important"). */
110 if (pri <= RPMLOG_WARNING) {
113 recs = xmalloc((nrecs+2) * sizeof(*recs));
115 recs = xrealloc(recs, (nrecs+2) * sizeof(*recs));
116 recs[nrecs+1].code = 0;
117 recs[nrecs+1].message = NULL;
122 rec->message = xstrdup(msg);
124 if (_rpmlogCallback) {
126 return; /* XXX Preserve legacy rpmError behavior. */
130 /* rpmMessage behavior */
141 case RPMLOG_ERR: /* XXX Legacy rpmError behavior used stdout w/o prefix. */
147 /* Silly FORTRAN-like carriage control. */
150 else if (rpmlogMsgPrefix[pri] && *rpmlogMsgPrefix[pri])
151 fputs(_(rpmlogMsgPrefix[pri]), msgout);
155 if (pri <= RPMLOG_CRIT)
159 void rpmlog (int code, const char *fmt, ...)
164 vrpmlog(code, fmt, ap);