Skip to content

Commit d664460

Browse files
committed
fw/system/logging: improve logging
- Use level-named macros, e.g. PBL_LOG_INFO(...) instead of PBL_LOG(LOG_LEVEL_INFO, ...) - Each level has a default color (e.g. info->green, error->red...) - Removed usage of colored logs (it's just confusing) Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
1 parent ddcf87c commit d664460

File tree

419 files changed

+2383
-2601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

419 files changed

+2383
-2601
lines changed

src/bluetooth-fw/nimble/advert.c

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ static void prv_handle_connection_event(struct ble_gap_event *event) {
6161

6262
struct ble_gap_conn_desc desc;
6363
if (ble_gap_conn_find(event->connect.conn_handle, &desc) != 0) {
64-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
65-
"prv_handle_connection_event: Failed to find connection descriptor");
64+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "prv_handle_connection_event: Failed to find connection descriptor");
6665
return;
6766
}
6867

@@ -128,8 +127,7 @@ static void prv_handle_disconnection_event(struct ble_gap_event *event) {
128127
static void prv_handle_enc_change_event(struct ble_gap_event *event) {
129128
struct ble_gap_conn_desc desc;
130129
if (ble_gap_conn_find(event->enc_change.conn_handle, &desc) != 0) {
131-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
132-
"prv_handle_enc_change_event: Failed to find connection descriptor");
130+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "prv_handle_enc_change_event: Failed to find connection descriptor");
133131
return;
134132
}
135133

@@ -144,21 +142,18 @@ static void prv_handle_enc_change_event(struct ble_gap_event *event) {
144142

145143
static void prv_handle_conn_params_updated_event(struct ble_gap_event *event) {
146144
if (event->conn_update.status != 0) {
147-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
148-
"Connection parameters update failed: 0x%04x",
145+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "Connection parameters update failed: 0x%04x",
149146
(uint16_t)event->conn_update.status);
150147
return;
151148
}
152149

153150
struct ble_gap_conn_desc desc;
154151
if (ble_gap_conn_find(event->conn_update.conn_handle, &desc) != 0) {
155-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
156-
"prv_handle_conn_params_updated_event: Failed to find connection descriptor");
152+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "prv_handle_conn_params_updated_event: Failed to find connection descriptor");
157153
return;
158154
}
159155

160-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_INFO,
161-
"Connection parameters updated: "
156+
PBL_LOG_D_INFO(LOG_DOMAIN_BT, "Connection parameters updated: "
162157
"itvl=%u ms, latency=%u, spvn timeout=%u ms",
163158
desc.conn_itvl * BLE_HCI_CONN_ITVL / 1000, desc.conn_latency,
164159
desc.supervision_timeout * BLE_HCI_CONN_SPVN_TMO_UNITS);
@@ -175,8 +170,7 @@ static void prv_handle_conn_params_updated_event(struct ble_gap_event *event) {
175170
static void prv_handle_conn_update_req_event(struct ble_gap_event *event) {
176171
*event->conn_update_req.self_params = *event->conn_update_req.peer_params;
177172

178-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_INFO,
179-
"Connection update request: "
173+
PBL_LOG_D_INFO(LOG_DOMAIN_BT, "Connection update request: "
180174
"itvl=(%u, %u) ms, latency=%u, spvn timeout=%u ms",
181175
event->conn_update_req.self_params->itvl_min * BLE_HCI_CONN_ITVL / 1000,
182176
event->conn_update_req.self_params->itvl_max * BLE_HCI_CONN_ITVL / 1000,
@@ -218,8 +212,7 @@ static void prv_handle_pairing_complete_event(struct ble_gap_event *event) {
218212
static void prv_handle_identity_resolved_event(struct ble_gap_event *event) {
219213
struct ble_gap_conn_desc desc;
220214
if (ble_gap_conn_find(event->identity_resolved.conn_handle, &desc) != 0) {
221-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
222-
"prv_handle_identity_resolved_event: Failed to find connection descriptor");
215+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "prv_handle_identity_resolved_event: Failed to find connection descriptor");
223216
return;
224217
}
225218

@@ -232,8 +225,7 @@ static void prv_handle_identity_resolved_event(struct ble_gap_event *event) {
232225
static void prv_handle_mtu_change_event(struct ble_gap_event *event) {
233226
struct ble_gap_conn_desc desc;
234227
if (ble_gap_conn_find(event->mtu.conn_handle, &desc) != 0) {
235-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
236-
"prv_handle_mtu_change_event: Failed to find connection descriptor");
228+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "prv_handle_mtu_change_event: Failed to find connection descriptor");
237229
return;
238230
}
239231

@@ -245,8 +237,7 @@ static void prv_handle_mtu_change_event(struct ble_gap_event *event) {
245237
extern int pebble_pairing_service_get_connectivity_send_notification(uint16_t conn_handle,
246238
uint16_t attr_handle);
247239
static void prv_handle_subscription_event(struct ble_gap_event *event) {
248-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG,
249-
"prv_handle_subscription_event: connhandle: %d attr:%d notify:%d/%d indicate:%d/%d",
240+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "prv_handle_subscription_event: connhandle: %d attr:%d notify:%d/%d indicate:%d/%d",
250241
event->subscribe.conn_handle, event->subscribe.attr_handle,
251242
event->subscribe.prev_notify, event->subscribe.cur_notify,
252243
event->subscribe.prev_indicate, event->subscribe.cur_indicate);
@@ -255,8 +246,7 @@ static void prv_handle_subscription_event(struct ble_gap_event *event) {
255246
static void prv_handle_notification_rx_event(struct ble_gap_event *event) {
256247
struct ble_gap_conn_desc desc;
257248
if (ble_gap_conn_find(event->notify_rx.conn_handle, &desc) != 0) {
258-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
259-
"prv_handle_notification_rx_event: Failed to find connection descriptor");
249+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "prv_handle_notification_rx_event: Failed to find connection descriptor");
260250
return;
261251
}
262252

@@ -275,8 +265,7 @@ static void prv_handle_notification_rx_event(struct ble_gap_event *event) {
275265
}
276266

277267
static void prv_handle_notification_tx_event(struct ble_gap_event *event) {
278-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG,
279-
"notification tx event; status=%d attr_handle=%d indication=%d\n",
268+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "notification tx event; status=%d attr_handle=%d indication=%d\n",
280269
event->notify_tx.status,
281270
event->notify_tx.attr_handle,
282271
event->notify_tx.indication);
@@ -300,82 +289,81 @@ static int prv_handle_repeat_pairing_event(struct ble_gap_event *event) {
300289

301290
return BLE_GAP_REPEAT_PAIRING_RETRY;
302291
#else
303-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_WARNING, "BLE_GAP_EVENT_REPEAT_PAIRING ignored");
292+
PBL_LOG_D_WRN(LOG_DOMAIN_BT, "BLE_GAP_EVENT_REPEAT_PAIRING ignored");
304293
return BLE_GAP_REPEAT_PAIRING_IGNORE;
305294
#endif
306295
}
307296

308297
static void prv_handle_phy_update_event(struct ble_gap_event *event) {
309298
if (event->phy_updated.status != 0) {
310-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
311-
"PHY update failed: 0x%04x",
299+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "PHY update failed: 0x%04x",
312300
(uint16_t)event->phy_updated.status);
313301
return;
314302
}
315303

316-
PBL_LOG(LOG_LEVEL_DEBUG, "PHY update complete; conn_handle=%d, tx_phy=%d, rx_phy=%d",
304+
PBL_LOG_DBG("PHY update complete; conn_handle=%d, tx_phy=%d, rx_phy=%d",
317305
event->phy_updated.conn_handle, event->phy_updated.tx_phy, event->phy_updated.rx_phy);
318306
}
319307

320308
static int prv_handle_gap_event(struct ble_gap_event *event, void *arg) {
321309
switch (event->type) {
322310
case BLE_GAP_EVENT_CONNECT:
323-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_CONNECT");
311+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_CONNECT");
324312
prv_handle_connection_event(event);
325313
break;
326314
case BLE_GAP_EVENT_DISCONNECT:
327-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_DISCONNECT");
315+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_DISCONNECT");
328316
prv_handle_disconnection_event(event);
329317
break;
330318
case BLE_GAP_EVENT_ENC_CHANGE:
331-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_ENC_CHANGE");
319+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_ENC_CHANGE");
332320
prv_handle_enc_change_event(event);
333321
break;
334322
case BLE_GAP_EVENT_CONN_UPDATE:
335-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_CONN_UPDATE");
323+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_CONN_UPDATE");
336324
prv_handle_conn_params_updated_event(event);
337325
break;
338326
case BLE_GAP_EVENT_CONN_UPDATE_REQ:
339-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_CONN_UPDATE_REQ");
327+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_CONN_UPDATE_REQ");
340328
prv_handle_conn_update_req_event(event);
341329
break;
342330
case BLE_GAP_EVENT_PASSKEY_ACTION:
343-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_PASSKEY_ACTION");
331+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_PASSKEY_ACTION");
344332
prv_handle_passkey_event(event);
345333
break;
346334
case BLE_GAP_EVENT_IDENTITY_RESOLVED:
347-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_IDENTITY_RESOLVED");
335+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_IDENTITY_RESOLVED");
348336
prv_handle_identity_resolved_event(event);
349337
break;
350338
case BLE_GAP_EVENT_PAIRING_COMPLETE:
351-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_PAIRING_COMPLETE");
339+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_PAIRING_COMPLETE");
352340
prv_handle_pairing_complete_event(event);
353341
break;
354342
case BLE_GAP_EVENT_MTU:
355-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_MTU");
343+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_MTU");
356344
prv_handle_mtu_change_event(event);
357345
break;
358346
case BLE_GAP_EVENT_SUBSCRIBE:
359-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_SUBSCRIBE");
347+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_SUBSCRIBE");
360348
prv_handle_subscription_event(event);
361349
break;
362350
case BLE_GAP_EVENT_NOTIFY_RX:
363351
// no log here because it's incredibly noisy
364352
prv_handle_notification_rx_event(event);
365353
break;
366354
case BLE_GAP_EVENT_NOTIFY_TX:
367-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_NOTIFY_TX");
355+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_NOTIFY_TX");
368356
prv_handle_notification_tx_event(event);
369357
break;
370358
case BLE_GAP_EVENT_REPEAT_PAIRING:
371-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_REPEAT_PAIRING");
359+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_REPEAT_PAIRING");
372360
return prv_handle_repeat_pairing_event(event);
373361
case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE:
374-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_DEBUG, "BLE_GAP_EVENT_PHY_UPDATE_COMPLETE");
362+
PBL_LOG_D_DBG(LOG_DOMAIN_BT, "BLE_GAP_EVENT_PHY_UPDATE_COMPLETE");
375363
prv_handle_phy_update_event(event);
376364
break;
377365
default:
378-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_WARNING, "Unhandled GAP event: %d", event->type);
366+
PBL_LOG_D_WRN(LOG_DOMAIN_BT, "Unhandled GAP event: %d", event->type);
379367
break;
380368
}
381369
return 0;
@@ -393,13 +381,13 @@ bool bt_driver_advert_advertising_enable(uint32_t min_interval_ms, uint32_t max_
393381

394382
rc = ble_hs_id_infer_auto(0, &own_addr_type);
395383
if (rc != 0) {
396-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR, "Failed to infer own address type (%d)", rc);
384+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "Failed to infer own address type (%d)", rc);
397385
return false;
398386
}
399387

400388
rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER, &advp, prv_handle_gap_event, NULL);
401389
if (rc != 0) {
402-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR, "Failed to start advertising (0x%04x)", (uint16_t)rc);
390+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "Failed to start advertising (0x%04x)", (uint16_t)rc);
403391
return false;
404392
}
405393

src/bluetooth-fw/nimble/gap_le_connect.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ int bt_driver_gap_le_disconnect(const BTDeviceInternal *peer_address) {
1010
uint16_t conn_handle;
1111

1212
if (!pebble_device_to_nimble_conn_handle(peer_address, &conn_handle)) {
13-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
14-
"bt_driver_gap_le_disconnect: Failed to find connection handle");
13+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "bt_driver_gap_le_disconnect: Failed to find connection handle");
1514
return -1;
1615
}
1716

1817
int rc = ble_gap_terminate(conn_handle, BLE_ERR_REM_USER_CONN_TERM);
1918
if (rc != 0) {
20-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR, "ble_gap_terminate rc=0x%04x", (uint16_t)rc);
19+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "ble_gap_terminate rc=0x%04x", (uint16_t)rc);
2120
}
2221

2322
return rc;

src/bluetooth-fw/nimble/gap_le_device_name.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static int prv_device_name_read_event_cb(uint16_t conn_handle, const struct ble_
1717
struct ble_gatt_attr *attr, void *arg) {
1818
if (error->status != 0) {
1919
if (error->status != BLE_HS_EDONE) {
20-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR, "prv_device_name_read_event_cb error=%d",
20+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "prv_device_name_read_event_cb error=%d",
2121
error->status);
2222
}
2323
return 0;
@@ -46,16 +46,14 @@ static int prv_device_name_read_event_cb(uint16_t conn_handle, const struct ble_
4646
static void prv_gap_le_device_name_request(GAPLEConnection *connection) {
4747
uint16_t conn_handle;
4848
if (!pebble_device_to_nimble_conn_handle(&connection->device, &conn_handle)) {
49-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
50-
"prv_gap_le_device_name_request: Failed to find connection handle");
49+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "prv_gap_le_device_name_request: Failed to find connection handle");
5150
return;
5251
}
5352

5453
int rc = ble_gattc_read_by_uuid(conn_handle, 1, UINT16_MAX, (ble_uuid_t *)&device_name_chr_uuid,
5554
prv_device_name_read_event_cb, (void *)connection);
5655
if (rc != 0) {
57-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
58-
"prv_gap_le_device_name_request ble_gattc_read_by_uuid rc=0x%04x", (uint16_t)rc);
56+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "prv_gap_le_device_name_request ble_gattc_read_by_uuid rc=0x%04x", (uint16_t)rc);
5957
}
6058
}
6159

@@ -66,8 +64,7 @@ static void prv_request_device_name_cb(GAPLEConnection *connection, void *data)
6664
void bt_driver_gap_le_device_name_request(const BTDeviceInternal *device) {
6765
GAPLEConnection *connection = gap_le_connection_by_device(device);
6866
if (connection == NULL) {
69-
PBL_LOG_D(LOG_DOMAIN_BT, LOG_LEVEL_ERROR,
70-
"bt_driver_gap_le_device_name_request gap_le_connection_by_device returned NULL");
67+
PBL_LOG_D_ERR(LOG_DOMAIN_BT, "bt_driver_gap_le_device_name_request gap_le_connection_by_device returned NULL");
7168
return;
7269
}
7370
prv_gap_le_device_name_request(connection);

0 commit comments

Comments
 (0)