tdb2: clean up logging
[ccan] / ccan / tdb2 / transaction.c
index 0aad8de8ee98b5fe38015b2ae076866a9bf117f0..92658026ac9c006c5e6f9bf31b99f77bb116abc6 100644 (file)
@@ -169,10 +169,9 @@ static int transaction_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
        return 0;
 
 fail:
-       tdb->ecode = TDB_ERR_IO;
-       tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                "transaction_read: failed at off=%llu len=%llu\n",
-                (long long)off, (long long)len);
+       tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+                  "transaction_read: failed at off=%zu len=%zu",
+                  (size_t)off, (size_t)len);
        tdb->transaction->transaction_error = 1;
        return -1;
 }
@@ -188,12 +187,10 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
 
        /* Only a commit is allowed on a prepared transaction */
        if (tdb->transaction->prepared) {
-               tdb->ecode = TDB_ERR_EINVAL;
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_FATAL,
                         "transaction_write: transaction already prepared,"
-                        " write not allowed\n");
-               tdb->transaction->transaction_error = 1;
-               return -1;
+                        " write not allowed");
+               goto fail;
        }
 
        /* break it up into block sized chunks */
@@ -228,7 +225,8 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
                                (blk+1)*sizeof(uint8_t *));
                }
                if (new_blocks == NULL) {
-                       tdb->ecode = TDB_ERR_OOM;
+                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                                  "transaction_write: failed to allocate");
                        goto fail;
                }
                memset(&new_blocks[tdb->transaction->num_blocks], 0,
@@ -242,9 +240,9 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
        if (tdb->transaction->blocks[blk] == NULL) {
                tdb->transaction->blocks[blk] = (uint8_t *)calloc(getpagesize(), 1);
                if (tdb->transaction->blocks[blk] == NULL) {
-                       tdb->ecode = TDB_ERR_OOM;
-                       tdb->transaction->transaction_error = 1;
-                       return -1;
+                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                                  "transaction_write: failed to allocate");
+                       goto fail;
                }
                if (tdb->transaction->old_map_size > blk * getpagesize()) {
                        tdb_len_t len2 = getpagesize();
@@ -254,6 +252,10 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
                        if (tdb->transaction->io_methods->read(tdb, blk * getpagesize(),
                                                               tdb->transaction->blocks[blk],
                                                               len2) != 0) {
+                               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                                          "transaction_write: failed to"
+                                          " read old block: %s",
+                                          strerror(errno));
                                SAFE_FREE(tdb->transaction->blocks[blk]);
                                goto fail;
                        }
@@ -278,10 +280,6 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
        return 0;
 
 fail:
-       tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                "transaction_write: failed at off=%llu len=%llu\n",
-                (long long)((blk*getpagesize()) + off),
-                (long long)len);
        tdb->transaction->transaction_error = 1;
        return -1;
 }
@@ -341,6 +339,12 @@ static int transaction_oob(struct tdb_context *tdb, tdb_off_t len, bool probe)
                return 0;
        }
        tdb->ecode = TDB_ERR_IO;
+       if (!probe) {
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+                          "tdb_oob len %lld beyond transaction size %lld",
+                          (long long)len,
+                          (long long)tdb->map_size);
+       }
        return -1;
 }
 
@@ -383,9 +387,9 @@ static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t
        }
 
        if (fsync(tdb->fd) != 0) {
-               tdb->ecode = TDB_ERR_IO;
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                        "tdb_transaction: fsync failed\n");
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+                          "tdb_transaction: fsync failed: %s",
+                          strerror(errno));
                return -1;
        }
 #ifdef MS_SYNC
@@ -393,10 +397,9 @@ static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t
                tdb_off_t moffset = offset & ~(getpagesize()-1);
                if (msync(moffset + (char *)tdb->map_ptr,
                          length + (offset - moffset), MS_SYNC) != 0) {
-                       tdb->ecode = TDB_ERR_IO;
-                       tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                                "tdb_transaction: msync failed - %s\n",
-                                strerror(errno));
+                       tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+                                  "tdb_transaction: msync failed: %s",
+                                  strerror(errno));
                        return -1;
                }
        }
@@ -410,9 +413,8 @@ static void _tdb_transaction_cancel(struct tdb_context *tdb)
        int i;
 
        if (tdb->transaction == NULL) {
-               tdb->ecode = TDB_ERR_EINVAL;
-               tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
-                        "tdb_transaction_cancel: no transaction\n");
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+                          "tdb_transaction_cancel: no transaction");
                return;
        }
 
@@ -441,9 +443,9 @@ static void _tdb_transaction_cancel(struct tdb_context *tdb)
                                   &invalid, sizeof(invalid)) == -1 ||
                    transaction_sync(tdb, tdb->transaction->magic_offset,
                                     sizeof(invalid)) == -1) {
-                       tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                                "tdb_transaction_cancel: failed to remove"
-                                " recovery magic\n");
+                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                                  "tdb_transaction_cancel: failed to remove"
+                                  " recovery magic");
                }
        }
 
@@ -469,16 +471,17 @@ int tdb_transaction_start(struct tdb_context *tdb)
 {
        /* some sanity checks */
        if (tdb->read_only || (tdb->flags & TDB_INTERNAL)) {
-               tdb->ecode = TDB_ERR_EINVAL;
-               tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
-                        "tdb_transaction_start: cannot start a transaction"
-                        " on a read-only or internal db\n");
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+                          "tdb_transaction_start: cannot start a transaction"
+                          " on a read-only or internal db");
                return -1;
        }
 
        /* cope with nested tdb_transaction_start() calls */
        if (tdb->transaction != NULL) {
-               tdb->ecode = TDB_ERR_NESTING;
+               tdb_logerr(tdb, TDB_ERR_NESTING, TDB_DEBUG_ERROR,
+                          "tdb_transaction_start:"
+                          " already inside transaction");
                return -1;
        }
 
@@ -486,17 +489,17 @@ int tdb_transaction_start(struct tdb_context *tdb)
                /* the caller must not have any locks when starting a
                   transaction as otherwise we'll be screwed by lack
                   of nested locks in posix */
-               tdb->ecode = TDB_ERR_LOCK;
-               tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
-                        "tdb_transaction_start: cannot start a transaction"
-                        " with locks held\n");
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+                          "tdb_transaction_start: cannot start a transaction"
+                          " with locks held");
                return -1;
        }
 
        tdb->transaction = (struct tdb_transaction *)
                calloc(sizeof(struct tdb_transaction), 1);
        if (tdb->transaction == NULL) {
-               tdb->ecode = TDB_ERR_OOM;
+               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_ERROR,
+                          "tdb_transaction_start: cannot allocate");
                return -1;
        }
 
@@ -585,17 +588,17 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
 
        recovery_head = tdb_read_off(tdb, offsetof(struct tdb_header,recovery));
        if (recovery_head == TDB_OFF_ERR) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_recovery_allocate:"
-                        " failed to read recovery head\n");
+                        " failed to read recovery head");
                return -1;
        }
 
        if (recovery_head != 0) {
                if (methods->read(tdb, recovery_head, &rec, sizeof(rec))) {
-                       tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                                 "tdb_recovery_allocate:"
-                                " failed to read recovery record\n");
+                                " failed to read recovery record");
                        return -1;
                }
                tdb_convert(tdb, &rec, sizeof(rec));
@@ -624,9 +627,9 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
                add_stat(tdb, frees, 1);
                if (add_free_record(tdb, recovery_head,
                                    sizeof(rec) + rec.max_len) != 0) {
-                       tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                                "tdb_recovery_allocate:"
-                                " failed to free previous recovery area\n");
+                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                                  "tdb_recovery_allocate:"
+                                  " failed to free previous recovery area");
                        return -1;
                }
        }
@@ -650,9 +653,9 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
                sizeof(rec) + *recovery_max_size;
        tdb->map_size = tdb->transaction->old_map_size;
        if (methods->expand_file(tdb, addition) == -1) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_recovery_allocate:"
-                        " failed to create recovery area\n");
+                        " failed to create recovery area");
                return -1;
        }
 
@@ -666,9 +669,9 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
        tdb_convert(tdb, &recovery_head, sizeof(recovery_head));
        if (methods->write(tdb, offsetof(struct tdb_header, recovery),
                           &recovery_head, sizeof(tdb_off_t)) == -1) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_recovery_allocate:"
-                        " failed to write recovery head\n");
+                        " failed to write recovery head");
                return -1;
        }
        transaction_write_existing(tdb, offsetof(struct tdb_header, recovery),
@@ -714,7 +717,8 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
 
        data = (unsigned char *)malloc(recovery_size + sizeof(*rec));
        if (data == NULL) {
-               tdb->ecode = TDB_ERR_OOM;
+               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                          "transaction_setup_recovery: cannot allocate");
                return -1;
        }
 
@@ -744,10 +748,9 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
                        continue;
                }
                if (offset + length > tdb->map_size) {
-                       tdb->ecode = TDB_ERR_CORRUPT;
-                       tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                                "tdb_transaction_setup_recovery:"
-                                " transaction data over new region boundary\n");
+                       tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
+                                  "tdb_transaction_setup_recovery:"
+                                  " transaction data over new region boundary");
                        free(data);
                        return -1;
                }
@@ -775,9 +778,9 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
        /* write the recovery data to the recovery area */
        if (methods->write(tdb, recovery_offset, data,
                           sizeof(*rec) + recovery_size) == -1) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_transaction_setup_recovery:"
-                        " failed to write recovery data\n");
+                        " failed to write recovery data");
                free(data);
                return -1;
        }
@@ -802,9 +805,9 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
                                                   magic);
 
        if (methods->write(tdb, *magic_offset, &magic, sizeof(magic)) == -1) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_transaction_setup_recovery:"
-                        " failed to write recovery magic\n");
+                        " failed to write recovery magic");
                return -1;
        }
        transaction_write_existing(tdb, *magic_offset, &magic, sizeof(magic));
@@ -822,27 +825,24 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
        const struct tdb_methods *methods;
 
        if (tdb->transaction == NULL) {
-               tdb->ecode = TDB_ERR_EINVAL;
-               tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
-                        "tdb_transaction_prepare_commit: no transaction\n");
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+                          "tdb_transaction_prepare_commit: no transaction");
                return -1;
        }
 
        if (tdb->transaction->prepared) {
-               tdb->ecode = TDB_ERR_EINVAL;
                _tdb_transaction_cancel(tdb);
-               tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
-                        "tdb_transaction_prepare_commit:"
-                        " transaction already prepared\n");
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+                          "tdb_transaction_prepare_commit:"
+                          " transaction already prepared");
                return -1;
        }
 
        if (tdb->transaction->transaction_error) {
-               tdb->ecode = TDB_ERR_IO;
                _tdb_transaction_cancel(tdb);
-               tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
-                        "tdb_transaction_prepare_commit:"
-                        " transaction error pending\n");
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+                          "tdb_transaction_prepare_commit:"
+                          " transaction error pending");
                return -1;
        }
 
@@ -861,9 +861,9 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
 
        /* upgrade the main transaction lock region to a write lock */
        if (tdb_allrecord_upgrade(tdb) == -1) {
-               tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_ERROR,
                         "tdb_transaction_prepare_commit:"
-                        " failed to upgrade hash locks\n");
+                        " failed to upgrade hash locks");
                _tdb_transaction_cancel(tdb);
                return -1;
        }
@@ -871,9 +871,9 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
        /* get the open lock - this prevents new users attaching to the database
           during the commit */
        if (tdb_lock_open(tdb, TDB_LOCK_WAIT|TDB_LOCK_NOCHECK) == -1) {
-               tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_ERROR,
                         "tdb_transaction_prepare_commit:"
-                        " failed to get open lock\n");
+                        " failed to get open lock");
                _tdb_transaction_cancel(tdb);
                return -1;
        }
@@ -882,9 +882,9 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
        if (!(tdb->flags & TDB_NOSYNC)) {
                /* write the recovery data to the end of the file */
                if (transaction_setup_recovery(tdb, &tdb->transaction->magic_offset) == -1) {
-                       tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
+                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                                 "tdb_transaction_prepare_commit:"
-                                " failed to setup recovery data\n");
+                                " failed to setup recovery data");
                        _tdb_transaction_cancel(tdb);
                        return -1;
                }
@@ -898,9 +898,9 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
                /* Restore original map size for tdb_expand_file */
                tdb->map_size = tdb->transaction->old_map_size;
                if (methods->expand_file(tdb, add) == -1) {
-                       tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
+                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_ERROR,
                                 "tdb_transaction_prepare_commit:"
-                                " expansion failed\n");
+                                " expansion failed");
                        _tdb_transaction_cancel(tdb);
                        return -1;
                }
@@ -928,19 +928,18 @@ int tdb_transaction_commit(struct tdb_context *tdb)
        int i;
 
        if (tdb->transaction == NULL) {
-               tdb->ecode = TDB_ERR_EINVAL;
-               tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
-                        "tdb_transaction_commit: no transaction\n");
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+                        "tdb_transaction_commit: no transaction");
                return -1;
        }
 
        tdb_trace(tdb, "tdb_transaction_commit");
 
        if (tdb->transaction->transaction_error) {
-               tdb->ecode = TDB_ERR_IO;
                tdb_transaction_cancel(tdb);
-               tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv,
-                        "tdb_transaction_commit: transaction error pending\n");
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_ERROR,
+                          "tdb_transaction_commit:"
+                          " transaction error pending");
                return -1;
        }
 
@@ -981,9 +980,9 @@ int tdb_transaction_commit(struct tdb_context *tdb)
 
                if (methods->write(tdb, offset, tdb->transaction->blocks[i],
                                   length) == -1) {
-                       tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                                "tdb_transaction_commit:"
-                                " write failed during commit\n");
+                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                                  "tdb_transaction_commit:"
+                                  " write failed during commit");
 
                        /* we've overwritten part of the data and
                           possibly expanded the file, so we need to
@@ -1043,9 +1042,9 @@ int tdb_transaction_recover(struct tdb_context *tdb)
        /* find the recovery area */
        recovery_head = tdb_read_off(tdb, offsetof(struct tdb_header,recovery));
        if (recovery_head == TDB_OFF_ERR) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_transaction_recover:"
-                        " failed to read recovery head\n");
+                        " failed to read recovery head");
                return -1;
        }
 
@@ -1056,9 +1055,9 @@ int tdb_transaction_recover(struct tdb_context *tdb)
 
        /* read the recovery record */
        if (tdb_read_convert(tdb, recovery_head, &rec, sizeof(rec)) == -1) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                        "tdb_transaction_recover:"
-                        " failed to read recovery record\n");
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                          "tdb_transaction_recover:"
+                          " failed to read recovery record");
                return -1;
        }
 
@@ -1068,10 +1067,9 @@ int tdb_transaction_recover(struct tdb_context *tdb)
        }
 
        if (tdb->read_only) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                        "tdb_transaction_recover:"
-                        " attempt to recover read only database\n");
-               tdb->ecode = TDB_ERR_CORRUPT;
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
+                          "tdb_transaction_recover:"
+                          " attempt to recover read only database");
                return -1;
        }
 
@@ -1079,19 +1077,18 @@ int tdb_transaction_recover(struct tdb_context *tdb)
 
        data = (unsigned char *)malloc(rec.len);
        if (data == NULL) {
-               tdb->ecode = TDB_ERR_OOM;
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                        "tdb_transaction_recover:"
-                        " failed to allocate recovery data\n");
+               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                          "tdb_transaction_recover:"
+                          " failed to allocate recovery data");
                return -1;
        }
 
        /* read the full recovery data */
        if (tdb->methods->read(tdb, recovery_head + sizeof(rec), data,
                               rec.len) == -1) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                        "tdb_transaction_recover:"
-                        " failed to read recovery data\n");
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                          "tdb_transaction_recover:"
+                          " failed to read recovery data");
                return -1;
        }
 
@@ -1107,9 +1104,9 @@ int tdb_transaction_recover(struct tdb_context *tdb)
 
                if (tdb->methods->write(tdb, ofs, p, len) == -1) {
                        free(data);
-                       tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                                 "tdb_transaction_recover:"
-                                " failed to recover %zu bytes at offset %zu\n",
+                                " failed to recover %zu bytes at offset %zu",
                                 (size_t)len, (size_t)ofs);
                        return -1;
                }
@@ -1119,8 +1116,8 @@ int tdb_transaction_recover(struct tdb_context *tdb)
        free(data);
 
        if (transaction_sync(tdb, 0, tdb->map_size) == -1) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                        "tdb_transaction_recover: failed to sync recovery\n");
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                          "tdb_transaction_recover: failed to sync recovery");
                return -1;
        }
 
@@ -1128,9 +1125,9 @@ int tdb_transaction_recover(struct tdb_context *tdb)
        if (recovery_eof <= recovery_head) {
                if (tdb_write_off(tdb, offsetof(struct tdb_header,recovery), 0)
                    == -1) {
-                       tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                                 "tdb_transaction_recover:"
-                                " failed to remove recovery head\n");
+                                " failed to remove recovery head");
                        return -1;
                }
        }
@@ -1140,21 +1137,21 @@ int tdb_transaction_recover(struct tdb_context *tdb)
                          recovery_head
                          + offsetof(struct tdb_recovery_record, magic),
                          TDB_RECOVERY_INVALID_MAGIC) == -1) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
                         "tdb_transaction_recover:"
-                        " failed to remove recovery magic\n");
+                        " failed to remove recovery magic");
                return -1;
        }
 
        if (transaction_sync(tdb, 0, recovery_eof) == -1) {
-               tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
-                        "tdb_transaction_recover: failed to sync2 recovery\n");
+               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                        "tdb_transaction_recover: failed to sync2 recovery");
                return -1;
        }
 
-       tdb->log(tdb, TDB_DEBUG_TRACE, tdb->log_priv,
-                "tdb_transaction_recover: recovered %zu byte database\n",
-                (size_t)recovery_eof);
+       tdb_logerr(tdb, TDB_SUCCESS, TDB_DEBUG_TRACE,
+                  "tdb_transaction_recover: recovered %zu byte database",
+                  (size_t)recovery_eof);
 
        /* all done */
        return 0;