# go-zap **Repository Path**: go_27/go-zap ## Basic Information - **Project Name**: go-zap - **Description**: // 创建开发环境日志记录器 logger, _ := zap.NewDevelopment() //defer logger.Sync() // 程序退出前刷新日志缓冲区 // 不同级别的日志输出 logger.Debug("调试信息") logger.Info("普通信息") logger.Warn("警告信息") logger.Error("错误信息") logger.P - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-28 - **Last Updated**: 2025-10-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # go-zap #### Introduction This project is a learning tutorial for Uber's zap logging library ([go.uber.org/zap](https://github.com/uber-go/zap)). Through progressive example code, it demonstrates various features and usage techniques of the zap logging library. zap is a high-performance, structured logging library especially suitable for Go language applications with high performance requirements. #### Software Architecture The project adopts a progressive learning structure, organizing example code from basic to advanced in order: ``` go-zap/ ├── 1.zap基本使用.go # Basic logging functionality demo ├── 2.日志配置.go # Detailed explanation of logger configuration options ├── 3.输出美化.go # Beautifying log output format ├── 4.日志前缀.go # Custom log prefixes ├── 5.全局日志.go # Using global loggers ├── 6.日志双写.go # Output to multiple targets simultaneously ├── 7.日志分割.go # Log file size-based rotation ├── 8.日志等级切片.go # Log level filtering and management ├── 9.日志整合.go # Comprehensive example integrating multiple advanced features ├── md/ # Detailed documentation directory │ ├── 1.zap基本使用.md # Detailed explanations for corresponding examples │ └── ... ├── go.mod # Go module definition └── go.sum # Dependency version locking ``` #### Installation 1. Ensure Go 1.13 or higher is installed 2. Clone this repository: `git clone https://gitee.com/your_username/go-zap.git` 3. Enter the project directory: `cd go-zap` 4. Install dependencies: `go mod download` #### Usage Instructions Each example file can be run independently to demonstrate specific zap logging library features: 1. **Basic Usage**: `go run 1.zap基本使用.go` - Learn zap's basic API and usage 2. **Log Configuration**: `go run 2.日志配置.go` - Understand how to configure various logger parameters 3. **Output Beautification**: `go run 3.输出美化.go` - Beautify console log output, add colors, etc. 4. **Log Prefixes**: `go run 4.日志前缀.go` - Add custom prefixes to logs 5. **Global Logging**: `go run 5.全局日志.go` - Use zap's global logger 6. **Dual Logging**: `go run 6.日志双写.go` - Output logs to multiple targets simultaneously (file and console) 7. **Log Rotation**: `go run 7.日志分割.go` - Implement automatic log file rotation 8. **Log Level Slicing**: `go run 8.日志等级切片.go` - Filter and manage logs by level 9. **Log Integration**: `go run 9.日志整合.go` - Comprehensive example demonstrating a complete logging system implementation Each example file contains detailed code comments, and there are more detailed documentation in the corresponding md directory. #### Contribution 1. Fork this repository 2. Create a new branch (e.g.: `git checkout -b feature/add-new-example`) 3. Commit your code (`git commit -m 'Add new zap feature example'`) 4. Push to the branch (`git push origin feature/add-new-example`) 5. Create a Pull Request #### Notes - Please refer to the go.mod file for the zap version used in this project - When running examples, some will generate log files - Ensure you have appropriate file system permissions to create and write log files