int refcount;
};
+struct event_reason {
+ struct event *event;
+};
+
extern const struct event_passthrough event_passthrough_vfuncs;
static struct event *events = NULL;
return current_global_event;
}
+#undef event_reason_begin
+struct event_reason *
+event_reason_begin(const char *reason_code, const char *source_filename,
+ unsigned int source_linenum)
+{
+ struct event_reason *reason;
+
+ reason = i_new(struct event_reason, 1);
+ reason->event = event_create(event_get_global(),
+ source_filename, source_linenum);
+ event_strlist_append(reason->event, EVENT_REASON_CODE, reason_code);
+ event_push_global(reason->event);
+ return reason;
+}
+
+void event_reason_end(struct event_reason **_reason)
+{
+ struct event_reason *reason = *_reason;
+
+ if (reason == NULL)
+ return;
+ event_pop_global(reason->event);
+ /* This event was created only for global use. It shouldn't be
+ permanently stored anywhere. This assert could help catch bugs. */
+ i_assert(reason->event->refcount == 1);
+ event_unref(&reason->event);
+ i_free(reason);
+}
+
static struct event *
event_set_log_prefix(struct event *event, const char *prefix, bool append)
{
#include <sys/time.h>
+/* Field name for the reason_code string list. */
+#define EVENT_REASON_CODE "reason_code"
+
struct event;
struct event_log_params;
/* Returns the current global event. */
struct event *event_get_global(void);
+/* Shortcut to create and push a global event and set its reason_code field. */
+struct event_reason *
+event_reason_begin(const char *reason_code, const char *source_filename,
+ unsigned int source_linenum);
+#define event_reason_begin(reason_code) \
+ event_reason_begin(reason_code, __FILE__, __LINE__)
+/* Finish the reason event. It pops the global event, which means it must be
+ at the top of the stack. */
+void event_reason_end(struct event_reason **reason);
+
/* Set the appended log prefix string for this event. All the parent events'
log prefixes will be concatenated together when logging. The log type
text (e.g. "Info: ") will be inserted before appended log prefixes (but