log
Loggingimport "log"Implements a simple logging package with output to standard error by default.
Example
package main
import "log"
func main() {
log.Println("Application started")
log.Printf("Port: %d", 8080)
// log.Fatal("critical error") // exits after logging
}Key Types & Functions
PrintlnPrintfFatalFatalfSetFlagsSetOutputLoggerAbout log
The log package (imported as log) belongs to the Logging category of Go packages. Implements a simple logging package with output to standard error by default.
Go's standard library is one of the language's greatest strengths, providing production-ready implementations for networking, cryptography, encoding, I/O, and more. The log package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.
When using log in production, follow Go best practices: handle errors explicitly, use context for cancellation and timeouts, prefer composition over inheritance, and write table-driven tests. The Go documentation at pkg.go.dev provides comprehensive API references and examples for every exported type and function.