Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 26 of 60 · Go

Logging with `log` and Structured Logging (`zap`)

Duration: 15 minutes

Simple Logging

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

The standard library log provides basic logging.

log.Println("Server started")
log.Fatalf("fatal error: %v", err)

Structured logging – zap

$ go get go.uber.org/zap
import "go.uber.org/zap"

func main() {
    logger, _ := zap.NewProduction()
    defer logger.Sync()
    sugar := logger.Sugar()
    sugar.Infow("request received", "method", "GET", "path", "/api")
}

zap offers high‑performance, leveled, and context‑aware logging.

Info

For long‑running services, prefer structured logs – they are easier to query with tools like Loki or Elastic.

Previous: Testing HTTP HandlersNext: Graceful Shutdown of Servers