{"id":49880028,"url":"https://github.com/pardnio/go-logger","last_synced_at":"2026-05-15T13:40:38.528Z","repository":{"id":300347125,"uuid":"1005894232","full_name":"pardnio/go-logger","owner":"pardnio","description":"Structured logging via log/slog with 8 levels, auto-rotation, and backup management.","archived":false,"fork":false,"pushed_at":"2025-07-18T15:31:43.000Z","size":51,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-24T17:35:28.983Z","etag":null,"topics":["backend","go","golang","pardnchiu"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pardnio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-21T03:20:27.000Z","updated_at":"2026-04-11T15:46:19.000Z","dependencies_parsed_at":"2025-06-21T07:21:07.376Z","dependency_job_id":"a7ecac59-54f5-472b-ac9b-c43e93867f32","html_url":"https://github.com/pardnio/go-logger","commit_stats":null,"previous_names":["pardnchiu/go-logger","pardnio/go-logger"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/pardnio/go-logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pardnio%2Fgo-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pardnio%2Fgo-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pardnio%2Fgo-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pardnio%2Fgo-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pardnio","download_url":"https://codeload.github.com/pardnio/go-logger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pardnio%2Fgo-logger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33068889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T11:35:32.926Z","status":"ssl_error","status_checked_at":"2026-05-15T11:35:31.362Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","go","golang","pardnchiu"],"created_at":"2026-05-15T13:40:38.159Z","updated_at":"2026-05-15T13:40:38.508Z","avatar_url":"https://github.com/pardnio.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!Note]\n\u003e This content is translated by LLM. Original text can be found [here](README.zh.md)\n\n# Go Logger\n\n\u003e A Golang logging package with automatic rotation, multi-level log classification, file management capabilities, and comprehensive error handling mechanisms.\u003cbr\u003e\n\u003e Primarily designed for use in `pardnchiu/go-*` packages\n\n[![lang](https://img.shields.io/badge/lang-Go-blue)](README.zh.md) \n[![license](https://img.shields.io/github/license/pardnchiu/go-logger)](LICENSE)\n[![version](https://img.shields.io/github/v/tag/pardnchiu/go-logger)](https://github.com/pardnchiu/go-logger/releases)\n![card](https://goreportcard.com/badge/github.com/pardnchiu/go-logger)\u003cbr\u003e\n[![readme](https://img.shields.io/badge/readme-EN-white)](README.md)\n[![readme](https://img.shields.io/badge/readme-ZH-white)](README.zh.md) \n\n## Three Core Features\n\n### Support for slog Standardization and Tree Structure Output\nJSON uses Go's standard `log/slog` package for structured logging\nText adopts tree structure to enhance readability\n\n### Complete Multi-Level Log Classification\nSupports 8 levels (`DEBUG`, `TRACE`, `INFO`, `NOTICE`, `WARNING`, `ERROR`, `FATAL`, `CRITICAL`)\n\n### Automatic File Rotation and Cleanup\nAutomatically rotates and creates backups when files reach size limits, intelligently cleans expired files to maintain configured backup count\n\n## Usage\n\n### Installation\n```bash\ngo get github.com/pardnchiu/go-logger\n```\n\n### Initialization\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"errors\"\n  \n  \"github.com/pardnchiu/go-logger\"\n)\n\nfunc main() {\n  config := \u0026goLogger.Log{\n    Path:      \"./logs\",              // Log directory\n    Stdout:    true,                  // Also output to terminal\n    MaxSize:   16 * 1024 * 1024,      // 16MB file size limit\n    MaxBackup: 5,                     // Keep 5 backup files\n    Type:      \"json\",                // \"json\" for slog standard, \"text\" for tree format\n  }\n  \n  // Initialize\n  logger, err := goLogger.New(config)\n  if err != nil {\n    panic(err)\n  }\n  defer logger.Close()\n  \n  // Log messages at different levels\n  logger.Debug(\"This is debug message\", \"detailed debug info\")\n  logger.Trace(\"Trace program execution flow\")\n  logger.Info(\"General information message\")\n  logger.Notice(\"Message that needs attention\")\n  logger.Warn(\"Warning message\")\n  \n  // Error handling\n  err = errors.New(\"an error occurred\")\n  logger.WarnError(err, \"Warning message for handling error\")\n  logger.Error(err, \"Additional message for handling error\")\n  logger.Fatal(err, \"Critical error\")\n  logger.Critical(err, \"System critical error\")\n  \n  // Flush cache\n  logger.Flush()\n}\n```\n\n## Configuration\n\n```go\ntype Log struct {\n  Path      string // Log file directory path (default: ./logs)\n  Stdout    bool   // Whether to output to stdout (default: false)\n  MaxSize   int64  // Maximum log file size in bytes (default: 16MB)\n  MaxBackup int    // Maximum number of backup files (default: 5)\n  Type      string // Output format: \"json\" for slog standard, \"text\" for tree format (default: \"text\")\n}\n```\n\n## Output Formats\n\n### slog Standard\nWhen `Type: \"json\"`, logs are output in `log/slog` structured format:\n\n```json\n{\"timestamp\":\"2024/01/15 14:30:25.123456\",\"level\":\"INFO\",\"message\":\"Application started\",\"data\":null}\n{\"timestamp\":\"2024/01/15 14:30:25.123457\",\"level\":\"ERROR\",\"message\":\"Database connection failed\",\"data\":[\"Connection timeout\",\"Retry in 5 seconds\"]}\n```\n- Directly uses Go's standard `log/slog` package\n- Easy integration with log aggregation tools\n- Consistent JSON schema across all log levels\n\n### Tree Structure\nWhen `Type: \"text\"`, logs are displayed in tree format:\n\n```\n2024/01/15 14:30:25.123457 [ERROR] Database connection failed\n2024/01/15 14:30:25.123457 ├── Connection timeout\n2024/01/15 14:30:25.123457 └── Retry in 5 seconds\n```\n- Clear hierarchical message structure\n- Enhanced readability during debugging\n\n## Log Levels\n\n### Debug and Trace\nLogged to `debug.log`\n```go\nlogger.Debug(\"Variable values\", \"x = 10\", \"y = 20\")\nlogger.Trace(\"Function call\", \"Started processing user request\")\n```\n\n### Info, Notice, Warning\nLogged to `output.log`\n```go\nlogger.Info(\"Application started\")                    // No prefix\nlogger.Notice(\"Configuration file reloaded\")          // [NOTICE] prefix\nlogger.Warn(\"Memory usage is high\")                   // [WARNING] prefix\nlogger.WarnError(err, \"Non-system-affecting error\")   // [WARNING] prefix\n```\n\n### Error, Fatal, Critical\nLogged to `error.log`\n```go\nlogger.Error(err, \"Retry attempt 3\")         // [ERROR] prefix\nlogger.Fatal(err, \"Unable to start service\") // [FATAL] prefix\nlogger.Critical(err, \"System crash\")         // [CRITICAL] prefix\n```\n\n## Available Functions\n\n- **New** - Create a new logger instance\n  ```go\n  logger, err := goLogger.New(config)\n  ```\n  - Initialize log directory, ensure path exists\n  - Initialize three log files: `debug.log`, `output.log`, `error.log`\n  - Set up log handlers for each level\n\n- **Close** - Properly close the logger\n  ```go\n  err := logger.Close()\n  ```\n  - Mark logger as closed\n  - Ensure no resource leaks\n\n- **Flush** - Force write to files\n  ```go\n  err := logger.Flush()\n  ```\n  - Write all cached log content to disk\n  - Ensure logs are not lost\n\n### File Rotation Mechanism\n\n#### Automatic Rotation\n- Check file size before each log write\n- Automatically rotate when exceeding `MaxSize` limit\n- Backup file naming format: `filename.YYYYMMDD_HHMMSS`\n\n#### Backup Management\n- Keep the latest `MaxBackup` backup files\n- Automatically delete expired old backups\n- Sort by modification time, keep the newest files\n\n## License\n\nThis project is licensed under the [MIT](LICENSE) License.\n\n## Author\n\n\u003cimg src=\"https://avatars.githubusercontent.com/u/25631760\" align=\"left\" width=\"96\" height=\"96\" style=\"margin-right: 0.5rem;\"\u003e\n\n\u003ch4 style=\"padding-top: 0\"\u003e邱敬幃 Pardn Chiu\u003c/h4\u003e\n\n\u003ca href=\"mailto:dev@pardn.io\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://pardn.io/image/email.svg\" width=\"48\" height=\"48\"\u003e\n\u003c/a\u003e \u003ca href=\"https://linkedin.com/in/pardnchiu\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://pardn.io/image/linkedin.svg\" width=\"48\" height=\"48\"\u003e\n\u003c/a\u003e\n\n***\n\n©️ 2025 [邱敬幃 Pardn Chiu](https://pardn.io)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpardnio%2Fgo-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpardnio%2Fgo-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpardnio%2Fgo-logger/lists"}