Skip to content

Commit e4e434a

Browse files
committed
Make logs messages more idiomatic
1 parent 423c1fc commit e4e434a

40 files changed

Lines changed: 113 additions & 79 deletions

‎content/en/docs/_overview.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ aliases:
99

1010
> [!assignment] Dumindu Madunuwan
1111
[![buymeacoffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-dumindu-FFDD00?style=for-the-badge&logo=buymeacoffee&logoColor=333333&labelColor=f9f9f9)](https://www.buymeacoffee.com/dumindu)
12-
[![hireme](https://img.shields.io/badge/Seeking%20On%20site%20Roles-%5BVisa%20Sponsorship%20Required%5D-FFDD00?style=for-the-badge&logo=readdotcv&logoColor=333333&labelColor=f9f9f9)](https://github.com/dumindu/dumindu/blob/master/Dumindu%20Madunuwan.pdf)
12+
[![hireme](https://img.shields.io/badge/Open%20to%20work-%5BVisa%20Sponsorship%20Required%5D-FFDD00?style=for-the-badge&logo=readdotcv&logoColor=333333&labelColor=f9f9f9)](https://github.com/dumindu/dumindu/blob/master/Dumindu%20Madunuwan.pdf)
1313
>
1414
> Global Technical Expertise : Over 12 years of backend experience spanning Singapore, Vietnam, and Remote(Short-term).
1515
>

‎content/en/labs/a1.building-a-containerized-restful-api.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,5 @@ rest_api_workspace
140140

141141
| Environment | Rust Image Type | Rust Image Size | Postgres Image Type | Postgres Image Size |
142142
|----------------|------------------------------------|-----------------|---------------------|---------------------|
143-
| Development | rust:1.97-slim | ~ 900 MB | postgres:18-alpine | ~ 300MB |
144-
| Production | distroless/static-debian13:nonroot | ~ 15 MB | | |
143+
| Development | rust:1.100-slim | ~ 1200 MB | postgres:18-alpine | ~ 420MB |
144+
| Production | distroless/static-debian13:nonroot | ~ 24 MB | | |

‎content/en/labs/a2.initialize-the-server.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,13 @@ async fn main() -> anyhow::Result<()> {
215215

216216
tracing_subscriber::registry()
217217
.with(filter)
218-
.with(tracing_subscriber::fmt::layer().json().with_target(false).with_current_span(false))
218+
.with(
219+
tracing_subscriber::fmt::layer()
220+
.json()
221+
.flatten_event(true)
222+
.with_target(false)
223+
.with_current_span(false),
224+
)
219225
.init();
220226

221227
let addr = String::from("0.0.0.0:3000");

‎content/en/labs/a3.configuration-and-middleware.md‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,19 @@ pub fn init(state: AppState) -> Router {
164164
.unwrap_or("unknown");
165165

166166
info_span!(
167-
"http_request",
168-
method = ?request.method(),
169-
uri_path = request.uri().path(),
170-
request_id,
167+
"http request",
168+
method = %request.method(),
169+
path = request.uri().path(),
170+
request_id = request_id,
171171
status_code = tracing::field::Empty,
172172
latency = tracing::field::Empty
173173
)
174174
})
175175
.on_response(|response: &Response<_>, latency: Duration, span: &Span| {
176-
span.record("status_code", tracing::field::display(response.status()));
176+
span.record("status_code", response.status().as_u16());
177177
span.record("latency", latency.as_millis());
178-
179178
span.in_scope(|| {
180-
info!("request completed");
179+
info!("http request completed");
181180
});
182181
}),
183182
)
@@ -238,7 +237,13 @@ async fn main() -> anyhow::Result<()> {
238237

239238
tracing_subscriber::registry()
240239
.with(filter)
241-
.with(tracing_subscriber::fmt::layer().json().with_target(false).with_current_span(false))
240+
.with(
241+
tracing_subscriber::fmt::layer()
242+
.json()
243+
.flatten_event(true)
244+
.with_target(false)
245+
.with_current_span(false),
246+
)
242247
.init();
243248

244249
let conf = AppConf::init();

‎content/en/labs/a5.routes-and-error-responses.md‎

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ async fn main() -> anyhow::Result<()> {
142142

143143
tracing_subscriber::registry()
144144
.with(filter)
145-
.with(tracing_subscriber::fmt::layer().json().with_target(false).with_current_span(false))
145+
.with(
146+
tracing_subscriber::fmt::layer()
147+
.json()
148+
.flatten_event(true)
149+
.with_target(false)
150+
.with_current_span(false),
151+
)
146152
.init();
147153

148154
let conf = AppConf::init();
@@ -208,8 +214,8 @@ use crate::{errors::Error, models::Book, state::AppState};
208214
pub async fn list(State(mut state): State<AppState>) -> Result<impl IntoResponse, Error> {
209215
let (limit, offset) = (10, 0);
210216
let books =
211-
Book::all().limit(limit).offset(offset).exec(&mut state.db).await.map_err(|err| {
212-
error!(target: "database", "failed to fetch: {err:?}");
217+
Book::all().limit(limit).offset(offset).exec(&mut state.db).await.map_err(|error| {
218+
error!(target: "db", %error, "db fetch failed");
213219
Error::DbFetch
214220
})?;
215221
Ok((StatusCode::OK, Json(books)))
@@ -228,8 +234,8 @@ pub async fn create(
228234
})
229235
.exec(&mut state.db)
230236
.await
231-
.map_err(|err| {
232-
error!(target: "database", "failed to insert: {err:?}");
237+
.map_err(|error| {
238+
error!(target: "db", %error, "db insert failed");
233239
Error::DbInsert
234240
})?;
235241

@@ -242,11 +248,11 @@ pub async fn read(
242248
State(mut state): State<AppState>,
243249
Path(id): Path<Uuid>,
244250
) -> Result<impl IntoResponse, Error> {
245-
let book = Book::get_by_id(&mut state.db, &id).await.map_err(|err| {
246-
if err.is_record_not_found() {
251+
let book = Book::get_by_id(&mut state.db, &id).await.map_err(|error| {
252+
if error.is_record_not_found() {
247253
Error::NotFound
248254
} else {
249-
error!(target: "database", "failed to fetch: {err:?}");
255+
error!(target: "db", %error, "db fetch failed");
250256
Error::DbFetch
251257
}
252258
})?;
@@ -259,11 +265,11 @@ pub async fn update(
259265
Path(id): Path<Uuid>,
260266
Json(payload): Json<BookRequest>,
261267
) -> Result<impl IntoResponse, Error> {
262-
let mut book = Book::get_by_id(&mut state.db, &id).await.map_err(|err| {
263-
if err.is_record_not_found() {
268+
let mut book = Book::get_by_id(&mut state.db, &id).await.map_err(|error| {
269+
if error.is_record_not_found() {
264270
Error::NotFound
265271
} else {
266-
error!(target: "database", "failed to fetch: {err:?}");
272+
error!(target: "db", %error, "db fetch failed");
267273
Error::DbFetch
268274
}
269275
})?;
@@ -277,8 +283,8 @@ pub async fn update(
277283
})
278284
.exec(&mut state.db)
279285
.await
280-
.map_err(|err| {
281-
error!(target: "database", "failed to update: {err:?}");
286+
.map_err(|error| {
287+
error!(target: "db", %error, "db update failed");
282288
Error::DbUpdate
283289
})?;
284290

@@ -291,8 +297,8 @@ pub async fn delete(
291297
State(mut state): State<AppState>,
292298
Path(id): Path<Uuid>,
293299
) -> Result<impl IntoResponse, Error> {
294-
Book::delete_by_id(&mut state.db, id).await.map_err(|err| {
295-
error!(target: "database", "failed to delete: {err:?}");
300+
Book::delete_by_id(&mut state.db, id).await.map_err(|error| {
301+
error!(target: "db", %error, "db delete failed");
296302
Error::DbDelete
297303
})?;
298304

@@ -412,8 +418,8 @@ pub async fn list(
412418
) -> Result<impl IntoResponse, Error> {
413419
let (limit, offset) = pagination.limit_offset();
414420
let books =
415-
Book::all().limit(limit).offset(offset).exec(&mut state.db).await.map_err(|err| {
416-
error!(target: "database", "failed to fetch: {err:?}");
421+
Book::all().limit(limit).offset(offset).exec(&mut state.db).await.map_err(|error| {
422+
error!(target: "db", %error, "db fetch failed");
417423
Error::DbFetch
418424
})?;
419425
Ok((StatusCode::OK, Json(books)))

‎content/en/labs/a8.whats-next.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ slug: whats-next
1313
Add a new file `book_service/Dockerfile`.
1414

1515
```dockerfile
16-
FROM rust:1.97-slim
16+
FROM rust:1.100-slim
1717
WORKDIR /build/crates/book_service
1818

1919
ENV CARGO_TARGET_DIR=/build/target
@@ -88,7 +88,7 @@ panic = "abort"
8888
Add a new file `book_service/prod.Dockerfile`.
8989

9090
```dockerfile
91-
FROM rust:1.97-slim AS builder
91+
FROM rust:1.100-slim AS builder
9292

9393
ARG CARGO_BUILD_TARGET=aarch64-unknown-linux-musl
9494

‎docs/docs/index.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ However, it&amp;rsquo;s good practice to specify the type on variables when usin
659659
&lt;/div&gt;
660660
&lt;div class="alert-body"&gt;
661661
&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/dumindu" target="_blank" &gt;&lt;img src="https://img.shields.io/badge/Buy%20me%20a%20coffee-dumindu-FFDD00?style=for-the-badge&amp;amp;logo=buymeacoffee&amp;amp;logoColor=333333&amp;amp;labelColor=f9f9f9" alt="buymeacoffee"&gt;&lt;/a&gt;
662-
&lt;a href="https://github.com/dumindu/dumindu/blob/master/Dumindu%20Madunuwan.pdf" target="_blank" &gt;&lt;img src="https://img.shields.io/badge/Seeking%20On%20site%20Roles-%5BVisa%20Sponsorship%20Required%5D-FFDD00?style=for-the-badge&amp;amp;logo=readdotcv&amp;amp;logoColor=333333&amp;amp;labelColor=f9f9f9" alt="hireme"&gt;&lt;/a&gt;&lt;/p&gt;
662+
&lt;a href="https://github.com/dumindu/dumindu/blob/master/Dumindu%20Madunuwan.pdf" target="_blank" &gt;&lt;img src="https://img.shields.io/badge/Open%20to%20work-%5BVisa%20Sponsorship%20Required%5D-FFDD00?style=for-the-badge&amp;amp;logo=readdotcv&amp;amp;logoColor=333333&amp;amp;labelColor=f9f9f9" alt="hireme"&gt;&lt;/a&gt;&lt;/p&gt;
663663
&lt;p&gt;Global Technical Expertise : Over 12 years of backend experience spanning Singapore, Vietnam, and Remote(Short-term).&lt;/p&gt;</description></item><item><title>Ownership</title><link>https://learning-rust.github.io/docs/ownership/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://learning-rust.github.io/docs/ownership/</guid><description>&lt;p&gt;We discussed in the &lt;a href="https://learning-rust.github.io/docs/traits/#derive-traits" &gt;Derive Traits&lt;/a&gt;, the usage of &lt;a href="https://doc.rust-lang.org/std/marker/trait.Copy.html" target="_blank" &gt;&lt;code&gt;Copy&lt;/code&gt; marker trait&lt;/a&gt; and &lt;a href="https://doc.rust-lang.org/std/clone/index.html" target="_blank" &gt;&lt;code&gt;.clone()&lt;/code&gt;&lt;/a&gt; with the below code.&lt;/p&gt;
664664

665665

‎docs/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!doctype html><html lang=en-US><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="Rust Programming Language Tutorials for Everyone!"><meta name=author content="Dumindu Madunuwan"><meta name=theme-color content="#ffffff" media="(prefers-color-scheme: light)"><meta name=theme-color content="#101010" media="(prefers-color-scheme: dark)"><title>Learning Rust · Rust Programming Language Tutorials for Everyone!</title><link rel=canonical href=https://learning-rust.github.io/><link rel=stylesheet href=/assets/css/home.min.09796058e7b09445ee42bb44f2c65960746570b604443e89dd4479f2976419a6.css integrity><link href=https://learning-rust.github.io/pagefind/pagefind-component-ui.css rel=stylesheet><link rel=manifest href=/manifest.json><link rel=icon href=/favicon/favicon.ico><link rel=icon href=/favicon/favicon-16x16.png sizes=16x16 type=image/png><link rel=icon href=/favicon/favicon-32x32.png sizes=32x32 type=image/png><link rel=apple-touch-icon href=/favicon/apple-touch-icon.png sizes=180x180><script defer src=https://cloud.umami.is/script.js data-website-id=bdae094e-f156-4bf5-92d5-41e1809afd94></script><meta property="og:title" content="Learning Rust"><meta property="og:description" content="Learning Rust - Rust Programming Language Tutorials for Everyone!"><meta property="og:type" content="article"><meta property="og:url" content="https://learning-rust.github.io/"><meta property="og:image" content="https://learning-rust.github.io/og.jpg"><meta property="og:site_name" content="Learning Rust"><meta name=twitter:card content="summary_large_image"><meta name=twitter:title content="Learning Rust"><meta name=twitter:description content="Learning Rust - Rust Programming Language Tutorials for Everyone!"><meta name=twitter:image content="https://learning-rust.github.io/og.jpg"><script type=application/ld+json>{"@context":"https://schema.org","@type":"Article","headline":"Learning Rust","description":"Learning Rust - Rust Programming Language Tutorials for Everyone!","image":"https:\/\/learning-rust.github.io\/og.jpg","author":{"@type":"Person","name":"Dumindu Madunuwan","url":"https:\/\/github.com\/dumindu"},"publisher":{"@type":"Organization","name":"Learning Rust","logo":{"@type":"ImageObject","url":"https:\/\/learning-rust.github.io\/"}},"dateModified":"2026-11-01T23:40:30Z","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/learning-rust.github.io\/"}}</script></head><body><div id=content-wrapper><header id=site-header><div id=site-header-logo><a href=https://learning-rust.github.io/><img height=52px src=https://learning-rust.github.io/logo.svg alt="Site Logo"></a></div><div id=site-header-actions><div id=search-box><pagefind-modal-trigger compact=true></pagefind-modal-trigger><pagefind-modal></pagefind-modal></div><div id=theme-dropdown class=dropdown><button class=dropdown-btn aria-haspopup=menu aria-label="Select the theme">
1+
<!doctype html><html lang=en-US><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="Rust Programming Language Tutorials for Everyone!"><meta name=author content="Dumindu Madunuwan"><meta name=theme-color content="#ffffff" media="(prefers-color-scheme: light)"><meta name=theme-color content="#101010" media="(prefers-color-scheme: dark)"><title>Learning Rust · Rust Programming Language Tutorials for Everyone!</title><link rel=canonical href=https://learning-rust.github.io/><link rel=stylesheet href=/assets/css/home.min.09796058e7b09445ee42bb44f2c65960746570b604443e89dd4479f2976419a6.css integrity><link href=https://learning-rust.github.io/pagefind/pagefind-component-ui.css rel=stylesheet><link rel=manifest href=/manifest.json><link rel=icon href=/favicon/favicon.ico><link rel=icon href=/favicon/favicon-16x16.png sizes=16x16 type=image/png><link rel=icon href=/favicon/favicon-32x32.png sizes=32x32 type=image/png><link rel=apple-touch-icon href=/favicon/apple-touch-icon.png sizes=180x180><script defer src=https://cloud.umami.is/script.js data-website-id=bdae094e-f156-4bf5-92d5-41e1809afd94></script><meta property="og:title" content="Learning Rust"><meta property="og:description" content="Learning Rust - Rust Programming Language Tutorials for Everyone!"><meta property="og:type" content="article"><meta property="og:url" content="https://learning-rust.github.io/"><meta property="og:image" content="https://learning-rust.github.io/og.jpg"><meta property="og:site_name" content="Learning Rust"><meta name=twitter:card content="summary_large_image"><meta name=twitter:title content="Learning Rust"><meta name=twitter:description content="Learning Rust - Rust Programming Language Tutorials for Everyone!"><meta name=twitter:image content="https://learning-rust.github.io/og.jpg"><script type=application/ld+json>{"@context":"https://schema.org","@type":"Article","headline":"Learning Rust","description":"Learning Rust - Rust Programming Language Tutorials for Everyone!","image":"https:\/\/learning-rust.github.io\/og.jpg","author":{"@type":"Person","name":"Dumindu Madunuwan","url":"https:\/\/github.com\/dumindu"},"publisher":{"@type":"Organization","name":"Learning Rust","logo":{"@type":"ImageObject","url":"https:\/\/learning-rust.github.io\/"}},"dateModified":"2026-11-15T17:10:57Z","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/learning-rust.github.io\/"}}</script></head><body><div id=content-wrapper><header id=site-header><div id=site-header-logo><a href=https://learning-rust.github.io/><img height=52px src=https://learning-rust.github.io/logo.svg alt="Site Logo"></a></div><div id=site-header-actions><div id=search-box><pagefind-modal-trigger compact=true></pagefind-modal-trigger><pagefind-modal></pagefind-modal></div><div id=theme-dropdown class=dropdown><button class=dropdown-btn aria-haspopup=menu aria-label="Select the theme">
22
<span><svg class="icon" height="20" viewBox="0 -960 960 960" width="20"><path d="M480-96q-79 0-149-30t-122.5-82.5T126-331 96-480q0-80 30.5-149.5t84-122 125-82.5T488-864q78 0 146.5 27T754-763t80.5 110T864-518q0 96-67 163t-163 67h-68q-8 0-14 5t-6 13q0 15 15 25t15 53q0 37-27 66.5T480-96zm0-384zm-173.5 18.5Q324-479 324-504t-17.5-42.5T264-564t-42.5 17.5T204-504t17.5 42.5T264-444t42.5-17.5zm120-144Q444-623 444-648t-17.5-42.5T384-708t-42.5 17.5T324-648t17.5 42.5T384-588t42.5-17.5zm192 0Q636-623 636-648t-17.5-42.5T576-708t-42.5 17.5T516-648t17.5 42.5T576-588t42.5-17.5zm120 144Q756-479 756-504t-17.5-42.5T696-564t-42.5 17.5T636-504t17.5 42.5T696-444t42.5-17.5zM480-168q11 0 17.5-8.5T504-192q0-16-15-28t-15-50 26.5-64 64.5-26h69q66 0 112-46t46-112q0-115-88.5-194.5T488-792q-134 0-227 91t-93 221 91 221 221 91z"/></svg>
33
</span><span><svg class="icon" height="20" viewBox="0 -960 960 960" width="20"><path d="m480-246 85.91-85.91Q577-343 591.5-343t25.5 11 11 25.5-10.93 25.43L505-169q-5.4 5-11.7 7.5t-13.5 2.5-13.5-2.5T455-169L342.93-281.07Q332-292 332.5-306.5T344-332t25.5-11 25.47 11.09L480-246zm0-468-85.91 85.91Q383-617 368.5-617T343-628t-11-25.5 10.93-25.43L455-791q5.4-5 11.7-7.5t13.5-2.5 13.5 2.5T505-791l112.07 112.07Q628-668 628-654t-11 25-25.5 11-25.59-10.97L480-714z"/></svg></span></button><ul role=menu class=dropdown-menu><li role=menuitem><button title=Light class=color-scheme data-value=light style=background:#fff;color:#000>
44
<span style=color:#000>Aa</span></button></li><li role=menuitem><button title=dark class=color-scheme data-value=dark style=background:#101010;color:#fff>

‎docs/index.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ However, it&amp;rsquo;s good practice to specify the type on variables when usin
881881
&lt;/div&gt;
882882
&lt;div class="alert-body"&gt;
883883
&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/dumindu" target="_blank" &gt;&lt;img src="https://img.shields.io/badge/Buy%20me%20a%20coffee-dumindu-FFDD00?style=for-the-badge&amp;amp;logo=buymeacoffee&amp;amp;logoColor=333333&amp;amp;labelColor=f9f9f9" alt="buymeacoffee"&gt;&lt;/a&gt;
884-
&lt;a href="https://github.com/dumindu/dumindu/blob/master/Dumindu%20Madunuwan.pdf" target="_blank" &gt;&lt;img src="https://img.shields.io/badge/Seeking%20On%20site%20Roles-%5BVisa%20Sponsorship%20Required%5D-FFDD00?style=for-the-badge&amp;amp;logo=readdotcv&amp;amp;logoColor=333333&amp;amp;labelColor=f9f9f9" alt="hireme"&gt;&lt;/a&gt;&lt;/p&gt;
884+
&lt;a href="https://github.com/dumindu/dumindu/blob/master/Dumindu%20Madunuwan.pdf" target="_blank" &gt;&lt;img src="https://img.shields.io/badge/Open%20to%20work-%5BVisa%20Sponsorship%20Required%5D-FFDD00?style=for-the-badge&amp;amp;logo=readdotcv&amp;amp;logoColor=333333&amp;amp;labelColor=f9f9f9" alt="hireme"&gt;&lt;/a&gt;&lt;/p&gt;
885885
&lt;p&gt;Global Technical Expertise : Over 12 years of backend experience spanning Singapore, Vietnam, and Remote(Short-term).&lt;/p&gt;</description></item><item><title>Overview</title><link>https://learning-rust.github.io/labs/overview/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://learning-rust.github.io/labs/overview/</guid><description>&lt;div class="alert alert-assignment"&gt;
886886
&lt;div class="alert-header"&gt;
887887

0 commit comments

Comments
 (0)