embassy-rs / nrf-softdevice

Apache License 2.0
254 stars 74 forks source link

Improve defmt trace #240

Closed HaoboGu closed 4 months ago

HaoboGu commented 4 months ago

I'm using nrf-softdevice with defmt logger, and I found the traces printed by nrf-softdevice are all from nrf-softdevice/src/fmt.rs, which misses file info and makes debugging harder.

TRACE ble evt 80
└─ nrf_softdevice::ble::on_evt @ /Users/haobogu/.cargo/git/checkouts/nrf-softdevice-8a2bc4dcba836638/8db29ff/nrf-softdevice/src/fmt.rs:112 
TRACE gatts write handle=26 data=[1, 0]
└─ nrf_softdevice::ble::gatt_server::run::{async_fn#0}::{closure#1} @ /Users/haobogu/.cargo/git/checkouts/nrf-softdevice-8a2bc4dcba836638/8db29ff/nrf-softdevice/src/fmt.rs:112 
TRACE ble evt 18
└─ nrf_softdevice::ble::on_evt @ /Users/haobogu/.cargo/git/checkouts/nrf-softdevice-8a2bc4dcba836638/8db29ff/nrf-softdevice/src/fmt.rs:112 
DEBUG on_conn_param_update conn_handle=3 conn_sup_timeout=100 max_conn_interval=12 min_conn_interval=12 slave_latency=4
└─ nrf_softdevice::ble::gap::on_evt @ /Users/haobogu/.cargo/git/checkouts/nrf-softdevice-8a2bc4dcba836638/8db29ff/nrf-softdevice/src/fmt.rs:125 

Maybe it can be improved somehow? by logging the real file and line numbers.

alexmoon commented 4 months ago

fmt.rs is required to allow the crate to be agnostic between the log and defmt logging options. Unfortunately there's no way to make the file and line numbers come from the caller instead.