Go Gorm Logger
In this tutorial, you'll learn about GORM Logger: No SQL Logging. We cover key concepts, practical examples, and best practices.
GORM SQL logging -- Enable GORM's built-in logger to see executed SQL queries during development.
The Problem
By default, GORM logs nothing for successful queries. GORM's logger shows SQL, execution time, and errors.
Wrong
db, _ := gorm.Open(postgres.Open(dsn), &gorm.Config{})
db.Find(&users)
Output:
// No output at all
Right
db, _ := gorm.Open(postgres.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
})
db.Find(&users)
Output:
[2026-06-24] [0.12ms] SELECT * FROM users
Prevention
- Use logger.Info for development
- Use logger.Warn for staging
- Use logger.Silent for production
- Customize with logger.New()
- Set SlowThreshold for slow query logging
Common Mistakes with gorm logger
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
These mistakes appear frequently in real-world GO code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. DodaTech tutorials help Go developers build production-ready software used by millions.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro