A high-performance, flexible Go logging library built on zap, providing rich features and a simple API.
- ๐บ๐ธ English
- ๐จ๐ณ ็ฎไฝไธญๆ
- ๐น๐ผ ็น้ซไธญๆ
- ๐ซ๐ท Franรงais
- ๐ท๐บ ะ ัััะบะธะน
- ๐ช๐ธ Espaรฑol
- ๐ธ๐ฆ ุงูุนุฑุจูุฉ
Visit our GitHub Pages documentation for a better reading experience.
- ๐ High Performance: Built on zap with object pooling and conditional field recording
- ๐ Rich Log Levels: Trace, Debug, Info, Warn, Error, Fatal, Panic levels
- โ๏ธ Flexible Configuration:
- Log level control
- Caller information recording
- Trace information (including goroutine ID)
- Custom log prefixes and suffixes
- Custom output targets (console, files, etc.)
- Log formatting options
- ๐ File Rotation: Hourly log file rotation support
- ๐ Zap Compatibility: Seamless integration with zap WriteSyncer
- ๐ฏ Simple API: Clean API similar to standard log library, easy to use
go get github.com/lazygophers/logpackage main
import (
"github.com/lazygophers/log"
)
func main() {
// Use default global logger
log.Debug("Debug message")
log.Info("Info message")
log.Warn("Warning message")
log.Error("Error message")
// Use formatted output
log.Infof("User %s logged in successfully", "admin")
// Custom configuration
customLogger := log.New().
SetLevel(log.InfoLevel).
EnableCaller(false).
SetPrefixMsg("[MyApp]")
customLogger.Info("This is a log from custom logger")
}package main
import (
"os"
"github.com/lazygophers/log"
)
func main() {
// Create logger with file output
logger := log.New().
SetLevel(log.DebugLevel).
EnableCaller(true).
EnableTrace(true).
SetOutput(os.Stdout, log.GetOutputWriterHourly("/var/log/myapp.log"))
logger.Debug("Debug message with caller info")
logger.Info("Info message with trace info")
}package main
import "github.com/lazygophers/log"
func main() {
logger := log.New().SetLevel(log.WarnLevel)
// Only warn and above will be logged
logger.Debug("This won't be logged") // Ignored
logger.Info("This won't be logged") // Ignored
logger.Warn("This will be logged") // Logged
logger.Error("This will be logged") // Logged
}| Method | Description | Default |
|---|---|---|
SetLevel(level) |
Set minimum log level | DebugLevel |
EnableCaller(enable) |
Enable/disable caller info | false |
EnableTrace(enable) |
Enable/disable trace info | false |
SetCallerDepth(depth) |
Set caller depth | 2 |
SetPrefixMsg(prefix) |
Set log prefix | "" |
SetSuffixMsg(suffix) |
Set log suffix | "" |
SetOutput(writers...) |
Set output targets | os.Stdout |
| Level | Description |
|---|---|
TraceLevel |
Most verbose, for detailed tracing |
DebugLevel |
Debug information |
InfoLevel |
General information |
WarnLevel |
Warning messages |
ErrorLevel |
Error messages |
FatalLevel |
Fatal errors (calls os.Exit(1)) |
PanicLevel |
Panic errors (calls panic()) |
- Logger: Main logging structure with configurable options
- Entry: Individual log record with comprehensive field support
- Level: Log level definitions and utility functions
- Format: Log formatting interface and implementations
- Object Pooling: Reuses Entry objects to reduce memory allocation
- Conditional Recording: Only records expensive fields when needed
- Fast Level Checking: Checks log level at the outermost layer
- Lock-Free Design: Most operations don't require locks
| Feature | lazygophers/log | zap | logrus | standard log |
|---|---|---|---|---|
| Performance | High | High | Medium | Low |
| API Simplicity | High | Medium | High | High |
| Feature Richness | Medium | High | High | Low |
| Flexibility | Medium | High | High | Low |
| Learning Curve | Low | Medium | Medium | Low |
- ๐ API Documentation - Complete API reference
- ๐ค Contributing Guide - How to contribute
- ๐ Changelog - Version history
- ๐ Security Policy - Security guidelines
- ๐ Code of Conduct - Community guidelines
- GitHub Issues: Report bugs or request features
- GoDoc: API Documentation
- Examples: Usage examples
This project is licensed under the MIT License - see the LICENSE file for details.
This document is available in multiple languages:
- ๐บ๐ธ English (Current)
- ๐จ๐ณ ็ฎไฝไธญๆ
- ๐น๐ผ ็น้ซไธญๆ
- ๐ซ๐ท Franรงais
- ๐ท๐บ ะ ัััะบะธะน
- ๐ช๐ธ Espaรฑol
- ๐ธ๐ฆ ุงูุนุฑุจูุฉ
We welcome contributions! Please see our Contributing Guide for details.
lazygophers/log is designed to be the go-to logging solution for Go developers who value both performance and simplicity. Whether you're building a small utility or a large-scale distributed system, this library provides the right balance of features and ease of use.