Skip to content

Commit 4e56774

Browse files
committed
[fdb] add db path info for logs
1 parent 8608140 commit 4e56774

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

inc/fdb_low_lvl.h

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ uint32_t _fdb_continue_ff_addr(fdb_db_t db, uint32_t start, uint32_t end);
5757
fdb_err_t _fdb_init_ex(fdb_db_t db, const char *name, const char *part_name, fdb_db_type type, void *user_data);
5858
void _fdb_init_finish(fdb_db_t db, fdb_err_t result);
5959
void _fdb_deinit(fdb_db_t db);
60+
const char *_fdb_db_path(fdb_db_t db);
6061
fdb_err_t _fdb_write_status(fdb_db_t db, uint32_t addr, uint8_t status_table[], size_t status_num, size_t status_index, bool sync);
6162
size_t _fdb_read_status(fdb_db_t db, uint32_t addr, uint8_t status_table[], size_t total_num);
6263
fdb_err_t _fdb_flash_read(fdb_db_t db, uint32_t addr, void *buf, size_t size);

src/fdb.c

+20-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ void _fdb_init_finish(fdb_db_t db, fdb_err_t result)
103103
log_is_show = true;
104104
}
105105
} else if (!db->not_formatable) {
106-
FDB_INFO("Error: %s (%s) is initialize fail (%d).\n", db->type == FDB_DB_TYPE_KV ? "KVDB" : "TSDB",
107-
db->name, (int)result);
106+
FDB_INFO("Error: %s (%s@%s) is initialize fail (%d).\n", db->type == FDB_DB_TYPE_KV ? "KVDB" : "TSDB",
107+
db->name, _fdb_db_path(db), (int)result);
108108
}
109109
}
110110

@@ -131,3 +131,21 @@ void _fdb_deinit(fdb_db_t db)
131131

132132
db->init_ok = false;
133133
}
134+
135+
const char *_fdb_db_path(fdb_db_t db)
136+
{
137+
if (db->file_mode) {
138+
#ifdef FDB_USING_FILE_MODE
139+
return db->storage.dir;
140+
#else
141+
return NULL;
142+
#endif
143+
}
144+
else {
145+
#ifdef FDB_USING_FAL_MODE
146+
return db->storage.part->name;
147+
#else
148+
return NULL;
149+
#endif
150+
}
151+
}

src/fdb_kvdb.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define FDB_LOG_TAG "[kv]"
2020
/* rewrite log prefix */
2121
#undef FDB_LOG_PREFIX2
22-
#define FDB_LOG_PREFIX2() FDB_PRINT("[%s] ", db_name(db))
22+
#define FDB_LOG_PREFIX2() FDB_PRINT("[%s][%s] ", db_name(db), _fdb_db_path((fdb_db_t)db))
2323

2424
#if defined(FDB_USING_KVDB)
2525

@@ -276,7 +276,8 @@ static uint32_t find_next_kv_addr(fdb_kvdb_t db, uint32_t start, uint32_t end)
276276
#endif /* FDB_KV_USING_CACHE */
277277

278278
for (; start < end && start + sizeof(buf) < end; start += (sizeof(buf) - sizeof(uint32_t))) {
279-
_fdb_flash_read((fdb_db_t)db, start, (uint32_t *) buf, sizeof(buf));
279+
if (_fdb_flash_read((fdb_db_t)db, start, (uint32_t *) buf, sizeof(buf)) != FDB_NO_ERR)
280+
return FAILED_ADDR;
280281
for (i = 0; i < sizeof(buf) - sizeof(uint32_t) && start + i < end; i++) {
281282
#ifndef FDB_BIG_ENDIAN /* Little Endian Order */
282283
magic = buf[i] + (buf[i + 1] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24);

src/fdb_tsdb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define FDB_LOG_TAG "[tsl]"
2222
/* rewrite log prefix */
2323
#undef FDB_LOG_PREFIX2
24-
#define FDB_LOG_PREFIX2() FDB_PRINT("[%s] ", db_name(db))
24+
#define FDB_LOG_PREFIX2() FDB_PRINT("[%s][%s] ", db_name(db), _fdb_db_path((fdb_db_t)db))
2525

2626
#if defined(FDB_USING_TSDB)
2727

0 commit comments

Comments
 (0)