const char *str;
};
-/* For logs which have error codes associated with them */
-#define flog_err(ferr_id, format, ...) \
- zlog_err("[EC %u] " format, ferr_id, ##__VA_ARGS__)
-#define flog_err_sys(ferr_id, format, ...) \
- flog_err(ferr_id, format, ##__VA_ARGS__)
-#define flog_warn(ferr_id, format, ...) \
- zlog_warn("[EC %u] " format, ferr_id, ##__VA_ARGS__)
-#define flog(priority, ferr_id, format, ...) \
- zlog(priority, "[EC %u] " format, ferr_id, ##__VA_ARGS__)
-
extern void zlog_thread_info(int log_level);
#define ZLOG_FILTERS_MAX 100 /* Max # of filters at once */
const char *fmt;
va_list args;
+ const struct xref_logmsg *xref;
char *stackbuf;
size_t stackbufsz;
}
-static void vzlog_notls(int prio, const char *fmt, va_list ap)
+static void vzlog_notls(const struct xref_logmsg *xref, int prio,
+ const char *fmt, va_list ap)
{
struct zlog_target *zt;
struct zlog_msg stackmsg = {
.prio = prio & LOG_PRIMASK,
.fmt = fmt,
+ .xref = xref,
}, *msg = &stackmsg;
char stackbuf[512];
XFREE(MTYPE_LOG_MESSAGE, msg->text);
}
-static void vzlog_tls(struct zlog_tls *zlog_tls, int prio,
- const char *fmt, va_list ap)
+static void vzlog_tls(struct zlog_tls *zlog_tls, const struct xref_logmsg *xref,
+ int prio, const char *fmt, va_list ap)
{
struct zlog_target *zt;
struct zlog_msg *msg;
msg->stackbufsz = TLS_LOG_BUF_SIZE - zlog_tls->bufpos - 1;
msg->fmt = fmt;
msg->prio = prio & LOG_PRIMASK;
+ msg->xref = xref;
if (msg->prio < LOG_INFO)
immediate = true;
XFREE(MTYPE_LOG_MESSAGE, msg->text);
}
-void vzlog(int prio, const char *fmt, va_list ap)
+void vzlogx(const struct xref_logmsg *xref, int prio,
+ const char *fmt, va_list ap)
{
struct zlog_tls *zlog_tls = zlog_tls_get();
#endif
if (zlog_tls)
- vzlog_tls(zlog_tls, prio, fmt, ap);
+ vzlog_tls(zlog_tls, xref, prio, fmt, ap);
else
- vzlog_notls(prio, fmt, ap);
+ vzlog_notls(xref, prio, fmt, ap);
}
void zlog_sigsafe(const char *text, size_t len)
return msg->prio;
}
+const struct xref_logmsg *zlog_msg_xref(struct zlog_msg *msg)
+{
+ return msg->xref;
+}
+
const char *zlog_msg_text(struct zlog_msg *msg, size_t *textlen)
{
if (!msg->text) {
extern size_t zlog_prefixsz;
extern int zlog_tmpdirfd;
+struct xref_logmsg {
+ struct xref xref;
+
+ const char *fmtstring;
+ uint32_t priority;
+ uint32_t ec;
+};
+
+struct xrefdata_logmsg {
+ struct xrefdata xrefdata;
+
+ /* nothing more here right now */
+};
+
/* These functions are set up to write to stdout/stderr without explicit
* initialization and/or before config load. There is no need to call e.g.
* fprintf(stderr, ...) just because it's "too early" at startup. Depending
* determine wether something is a log message or something else.
*/
-extern void vzlog(int prio, const char *fmt, va_list ap);
+extern void vzlogx(const struct xref_logmsg *xref, int prio,
+ const char *fmt, va_list ap);
+#define vzlog(prio, ...) vzlogx(NULL, prio, __VA_ARGS__)
PRINTFRR(2, 3)
static inline void zlog(int prio, const char *fmt, ...)
va_end(ap);
}
-#define zlog_err(...) zlog(LOG_ERR, __VA_ARGS__)
-#define zlog_warn(...) zlog(LOG_WARNING, __VA_ARGS__)
-#define zlog_info(...) zlog(LOG_INFO, __VA_ARGS__)
-#define zlog_notice(...) zlog(LOG_NOTICE, __VA_ARGS__)
-#define zlog_debug(...) zlog(LOG_DEBUG, __VA_ARGS__)
+PRINTFRR(2, 3)
+static inline void zlog_ref(const struct xref_logmsg *xref,
+ const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vzlogx(xref, xref->priority, fmt, ap);
+ va_end(ap);
+}
+
+#define _zlog_ref(prio, msg, ...) do { \
+ static struct xrefdata _xrefdata = { \
+ .hashstr = (msg), \
+ .hashu32 = { (prio), 0 }, \
+ }; \
+ static const struct xref_logmsg _xref __attribute__((used)) = {\
+ .xref = XREF_INIT(XREFT_LOGMSG, &_xrefdata, __func__), \
+ .fmtstring = (msg), \
+ .priority = (prio), \
+ }; \
+ XREF_LINK(_xref.xref); \
+ zlog_ref(&_xref, (msg), ## __VA_ARGS__); \
+ } while (0)
+
+#define zlog_err(...) _zlog_ref(LOG_ERR, __VA_ARGS__)
+#define zlog_warn(...) _zlog_ref(LOG_WARNING, __VA_ARGS__)
+#define zlog_info(...) _zlog_ref(LOG_INFO, __VA_ARGS__)
+#define zlog_notice(...) _zlog_ref(LOG_NOTICE, __VA_ARGS__)
+#define zlog_debug(...) _zlog_ref(LOG_DEBUG, __VA_ARGS__)
+
+#define _zlog_ecref(ec_, prio, msg, ...) do { \
+ static struct xrefdata _xrefdata = { \
+ .hashstr = (msg), \
+ .hashu32 = { (prio), (ec_) }, \
+ }; \
+ static const struct xref_logmsg _xref __attribute__((used)) = {\
+ .xref = XREF_INIT(XREFT_LOGMSG, &_xrefdata, __func__), \
+ .fmtstring = (msg), \
+ .priority = (prio), \
+ .ec = (ec_), \
+ }; \
+ XREF_LINK(_xref.xref); \
+ zlog_ref(&_xref, "[EC %u] " msg, ec_, ## __VA_ARGS__); \
+ } while (0)
+
+#define flog_err(ferr_id, format, ...) \
+ _zlog_ecref(ferr_id, LOG_ERR, format, ## __VA_ARGS__)
+#define flog_warn(ferr_id, format, ...) \
+ _zlog_ecref(ferr_id, LOG_WARNING, format, ## __VA_ARGS__)
+
+#define flog_err_sys(ferr_id, format, ...) \
+ flog_err(ferr_id, format, ##__VA_ARGS__)
+#define flog(priority, ferr_id, format, ...) \
+ zlog(priority, "[EC %u] " format, ferr_id, ##__VA_ARGS__)
extern void zlog_sigsafe(const char *text, size_t len);
struct zlog_msg;
extern int zlog_msg_prio(struct zlog_msg *msg);
+extern const struct xref_logmsg *zlog_msg_xref(struct zlog_msg *msg);
/* pass NULL as textlen if you don't need it. */
extern const char *zlog_msg_text(struct zlog_msg *msg, size_t *textlen);