1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
use wide_log::wide_log; // Customize built-in key strings using the dotted-path override syntax. // Event.Id => "correlation_id" means the generated event ID is serialized // under "correlation_id" instead of the default "id". wide_log!([ Event.Id => "correlation_id", Log.Level => "severity", Log.Message => "msg", Duration.TotalMs => "elapsed_ms" ], { "service": { "name": "example", "version": "1.0.0" }, "requests": counter!, }); fn main() { let _guard = WideLogGuard::builder().build(); wl_inc!("requests"); info!("request received"); warn!("upstream slow"); // _guard drops → emitted JSON uses custom key names, written to // non-blocking stdout: // {"service":{"name":"example","version":"1.0.0"}, // "duration":{"elapsed_ms":0},"requests":1, // "event":{"timestamp":"...","correlation_id":"01J6XK5R..."}, // "log":[{"severity":"info","msg":"request received"}, // {"severity":"warn","msg":"upstream slow"}]} }