Menu

Every Request Looked the Same in My Logs. Then I Added One Line.
πŸ“°

Every Request Looked the Same in My Logs. Then I Added One Line.

DEV CommunityΒ·Abhishek SharmaΒ·7 months ago
#md6EUsbt
#go#logging#request#time#slog
Reading 0:00
15s threshold

In Part 9 , I Dockerized my backend and added database migrations. One command ( docker compose up ) now spins up Go + Postgres + Redis.

Then I hit a bug. I sent a POST to /entries and got a 500 back. No idea why.

I opened the logs:

2026/02/01 10:15:23 POST /entries - Request received 2026/02/01 10:15:23 Creating entry for user ID: 3 2026/02/01 10:15:23 POST /entries - Request received 2026/02/01 10:15:23 Creating entry for user ID: 7 2026/02/01 10:15:23 Failed to extract user_id from context 2026/02/01 10:15:23 Entry created successfully with ID: 42

Enter fullscreen mode

Exit fullscreen mode

Five lines. Three users. Which line belongs to which request? I had no idea. The logs were flat strings β€” timestamps and messages, nothing else. When two requests hit at the same millisecond, the lines interleaved and became useless.

I couldn't debug my own backend.

Step 1: Replace Every log.Printf in the Codebase

Go ships a structured logging package in the standard library: log/slog .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.