]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add prefix to storage event
authorMarco Bettini <marco.bettini@open-xchange.com>
Tue, 19 Jul 2022 10:31:53 +0000 (10:31 +0000)
committerMarco Bettini <marco.bettini@open-xchange.com>
Thu, 4 Aug 2022 12:05:27 +0000 (12:05 +0000)
src/lib-storage/fail-mailbox.c
src/lib-storage/index/index-storage.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c

index 2ba1b7a604564df86fba105dd2458d537a724dc2..0c97f159076e0291db8ad5e28c2220359b52b211 100644 (file)
@@ -331,12 +331,8 @@ fail_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
        box->pool = pool;
        box->flags = flags;
 
-       box->event = event_create(box->storage->event);
-       event_add_category(box->event, &event_category_mailbox);
-       event_add_str(box->event, "mailbox", box->vname);
-       event_set_append_log_prefix(box->event,
-               t_strdup_printf("Mailbox %s: ", str_sanitize(box->vname, 128)));
-
+       box->event = mail_storage_mailbox_create_event(box->storage->event,
+                                                      box->vname);
        p_array_init(&box->search_results, pool, 16);
        p_array_init(&box->module_contexts, pool, 5);
        return box;
index 31ce6bb730e30f33aa4047dc96e253925ee97e3b..c3bcc1ba724faa3ee8e719ba6a004cc04369f67e 100644 (file)
@@ -402,11 +402,8 @@ void index_storage_mailbox_alloc(struct mailbox *box, const char *vname,
                             mailbox_list_get_storage_name(box->list, vname));
        box->flags = flags;
        box->index_prefix = p_strdup(box->pool, index_prefix);
-       box->event = event_create(box->storage->event);
-       event_add_category(box->event, &event_category_mailbox);
-       event_add_str(box->event, "mailbox", box->vname);
-       event_set_append_log_prefix(box->event,
-               t_strdup_printf("Mailbox %s: ", str_sanitize(box->vname, 128)));
+       box->event = mail_storage_mailbox_create_event(box->storage->event,
+                                                      box->vname);
 
        p_array_init(&box->search_results, box->pool, 16);
        array_create(&box->module_contexts,
index c4b567aedcebf53bf0e64a347c3f9314dfb9a487..79ba6465c3e20a3fad3276a9d84d16d2903bd6b7 100644 (file)
@@ -912,6 +912,9 @@ static inline const char *mailbox_name_sanitize(const char *name)
        return str_sanitize(name, 128);
 }
 
+struct event *
+mail_storage_mailbox_create_event(struct event *parent, const char *vname);
+
 /* for unit testing */
 int mailbox_verify_name(struct mailbox *box);
 
index d3d46afbe7405c0ba35f975c44ce17df7138e7c1..b1514f640a6643f46ae120852dfe26d086ca9eab 100644 (file)
@@ -430,6 +430,8 @@ int mail_storage_create_full(struct mail_namespace *ns, const char *driver,
        storage->event = event_create(ns->user->event);
        if (storage_class->event_category != NULL)
                event_add_category(storage->event, storage_class->event_category);
+       event_set_append_log_prefix(
+               storage->event, t_strdup_printf("%s: ", storage_class->name));
        p_array_init(&storage->module_contexts, storage->pool, 5);
 
        if (storage->v.create != NULL &&
@@ -573,12 +575,11 @@ void mail_storage_set_internal_error(struct mail_storage *storage)
        i_free(storage->last_internal_error);
 }
 
-void mail_storage_set_critical(struct mail_storage *storage,
-                              const char *fmt, ...)
+static void
+mail_storage_set_critical_error(struct mail_storage *storage, const char *str)
 {
        char *old_error = storage->error_string;
        char *old_internal_error = storage->last_internal_error;
-       va_list va;
 
        storage->error_string = NULL;
        storage->last_internal_error = NULL;
@@ -587,11 +588,8 @@ void mail_storage_set_critical(struct mail_storage *storage,
           easier to look from log files the actual error message. */
        mail_storage_set_internal_error(storage);
 
-       va_start(va, fmt);
-       storage->last_internal_error = i_strdup_vprintf(fmt, va);
-       va_end(va);
+       storage->last_internal_error = i_strdup(str);
        storage->last_error_is_internal = TRUE;
-       e_error(storage->event, "%s", storage->last_internal_error);
 
        /* free the old_error and old_internal_error only after the new error
           is generated, because they may be one of the parameters. */
@@ -599,15 +597,31 @@ void mail_storage_set_critical(struct mail_storage *storage,
        i_free(old_internal_error);
 }
 
+void mail_storage_set_critical(struct mail_storage *storage,
+                              const char *fmt, ...)
+{
+       va_list va;
+
+       va_start(va, fmt);
+       T_BEGIN {
+               const char *str = t_strdup_vprintf(fmt, va);
+               mail_storage_set_critical_error(storage, str);
+               e_error(storage->event, "%s", str);
+       } T_END;
+       va_end(va);
+}
+
 void mailbox_set_critical(struct mailbox *box, const char *fmt, ...)
 {
        va_list va;
 
        va_start(va, fmt);
        T_BEGIN {
-               mail_storage_set_critical(box->storage, "Mailbox %s: %s",
-                       mailbox_name_sanitize(box->vname),
-                       t_strdup_vprintf(fmt, va));
+               const char *str = t_strdup_vprintf(fmt, va);
+               mail_storage_set_critical_error(box->storage,
+                       t_strdup_printf("Mailbox %s: %s",
+                                       mailbox_name_sanitize(box->vname), str));
+               e_error(box->event, "%s", str);
        } T_END;
        va_end(va);
 }
@@ -3141,6 +3155,19 @@ mail_storage_settings_to_index_flags(const struct mail_storage_settings *set)
        return index_flags;
 }
 
+
+struct event *
+mail_storage_mailbox_create_event(struct event *parent, const char* vname)
+{
+       struct event *event = event_create(parent);
+       event_add_category(event, &event_category_mailbox);
+       event_add_str(event, "mailbox", vname);
+       event_drop_parent_log_prefixes(event, 1);
+       event_set_append_log_prefix(event, t_strdup_printf(
+               "Mailbox %s: ", mailbox_name_sanitize(vname)));
+       return event;
+}
+
 int mail_parse_human_timestamp(const char *str, time_t *timestamp_r,
                               bool *utc_r)
 {