-
Notifications
You must be signed in to change notification settings - Fork 0
logger_en.md
maoxiaoyue edited this page May 14, 2026
·
1 revision
The logger package provides a lightweight and high-performance logging tool tailored for HypGo. Built on Go's standard library log, it extends functionality with colored output, multi-level filtering, and automatic log rotation.
-
Multiple Log Levels: Supports
DEBUG,INFO,NOTICE,WARN,ERROR,EMERGENCYlevels for easy output granularity control. -
Automatic Log Rotation: Built-in
LogRotatorthat can automatically split log files based on file size or retention days and clean up old logs, preventing disk exhaustion. -
Readable Colored Terminal Output: When logging to
stdout/stderr, color highlighting of levels and alignment is automatically enabled, greatly improving the development experience. - Key-Value Logging Support: Provides convenient syntax for printing parameter variables, which are automatically formatted and appended to log messages.
-
Global Instance (Singleton) and Flexible Configuration: Provides
InitLoggerandGetLoggerfor a convenient global logger integration.
Use GetLogger() to get the global Logger for logging anywhere:
package main
import (
"github.com/maoxiaoyue/hypgo/pkg/logger"
)
func main() {
log := logger.GetLogger()
// Set output level (all levels at or above DEBUG will be output)
log.SetLevel(logger.DEBUG)
// Basic log output
log.Info("Server started")
// Output with variables
log.Debug("New connection request received", "client_ip", "192.168.1.100", "port", 8080)
// Error occurred
log.Error("Unable to write to database: %v", err)
// Fatal error, exits with os.Exit(1) after output
log.Fatal("Core system component missing!")
}If you want to save logs to a file instead of the terminal, configure the output path and expiry mechanism:
log := logger.GetLogger()
// Set log output to logs/app.log file
log.SetFile("logs/app.log")
// Set automatic rotation strategy
log.SetRotator(&logger.LogRotator{
filename: "logs/app.log", // Same path as SetFile output
maxSize: 10485760, // Maximum file size (10 MB)
maxAge: 7, // Keep logs for this many days
maxBackups: 5, // Maximum number of historical log files to keep
})由 台灣卯小月 用 ❤️ 製作 · MIT License And Wiki is written by Claude
設計文件
套件
- config — 設定
- context — 請求上下文
- router — 路由器
- server — 伺服器
- middleware — 中介層
- websocket — WebSocket
- hidb — 資料庫 ORM
- hidb/cassandra — Cassandra
- logger — 日誌
- json — JSON 處理
- grpc — gRPC
AI 協作工具鏈
- schema — Schema-first 路由
- manifest — 專案 Manifest
- contract — Contract Testing
- errors — Typed Error Catalog
- migrate — Migration Diff
- scaffold — 智慧 Scaffold
- airules — AI Rules
CLI 命令
- hyp 總覽
- hyp new
- hyp api
- hyp run
- hyp restart
- hyp generate
- hyp migrate
- hyp context
- hyp ai-rules
- hyp chkcomment
- hyp impact
- hyp docker
- hyp health
- hyp version
- hyp difflog
Design Docs
Packages
- config — Configuration
- context — Request Context
- router — Router
- server — Server
- middleware — Middleware
- websocket — WebSocket
- hidb — Database ORM
- hidb/cassandra - Cassandra 5.0
- logger — Logger
- json — JSON
- grpc — gRPC
AI Collaboration Toolchain
- schema — Schema-first Routing
- manifest — Project Manifest
- contract — Contract Testing
- errors — Typed Error Catalog
- migrate — Migration Diff
- scaffold — Smart Scaffold
- airules — AI Rules
CLI Commands