{"id":27203219,"url":"https://github.com/go-universal/logger","last_synced_at":"2025-09-12T19:41:40.448Z","repository":{"id":286787797,"uuid":"962523662","full_name":"go-universal/logger","owner":"go-universal","description":"📜 High-performance, time-based file logger for Go.","archived":false,"fork":false,"pushed_at":"2025-04-23T11:10:22.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T12:20:31.532Z","etag":null,"topics":["golang","log","logger","logging"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-universal.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}},"created_at":"2025-04-08T09:29:44.000Z","updated_at":"2025-04-23T11:10:26.000Z","dependencies_parsed_at":"2025-04-08T11:41:26.491Z","dependency_job_id":null,"html_url":"https://github.com/go-universal/logger","commit_stats":null,"previous_names":["go-universal/logger"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/go-universal/logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Flogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Flogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Flogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Flogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-universal","download_url":"https://codeload.github.com/go-universal/logger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-universal%2Flogger/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270191455,"owners_count":24542270,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["golang","log","logger","logging"],"created_at":"2025-04-09T22:29:11.367Z","updated_at":"2025-08-13T06:07:47.945Z","avatar_url":"https://github.com/go-universal.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logger Package Documentation\n\n![GitHub Tag](https://img.shields.io/github/v/tag/go-universal/logger?sort=semver\u0026label=version)\n[![Go Reference](https://pkg.go.dev/badge/github.com/go-universal/logger.svg)](https://pkg.go.dev/github.com/go-universal/logger)\n[![License](https://img.shields.io/badge/license-ISC-blue.svg)](https://github.com/go-universal/logger/blob/main/LICENSE)\n[![Go Report Card](https://goreportcard.com/badge/github.com/go-universal/logger)](https://goreportcard.com/report/github.com/go-universal/logger)\n![Contributors](https://img.shields.io/github/contributors/go-universal/logger)\n![Issues](https://img.shields.io/github/issues/go-universal/logger)\n\nThe `logger` package provides a flexible and efficient logging system for Go applications. It supports multiple logging levels, structured and simple formats, and customizable time formatting.\n\n## Installation\n\n```bash\ngo get github.com/go-universal/logger\n```\n\nHere is an example of how to use the `logger` package:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/go-universal/logger\"\n)\n\nfunc main() {\n    // Create a logger instance\n    log, err := logger.NewLogger().\n        SetBufferSize(100).\n        Path(\"./logs\").\n        Prefix(\"app_\").\n        Extension(\"log\").\n        Daily().\n        Simple().\n        StdFormatter().\n        Logger()\n\n    if err != nil {\n        fmt.Println(\"Failed to initialize logger:\", err)\n        return\n    }\n\n    // Log messages at different levels\n    log.Debug(\n        logger.With(\"Name\", \"John Doe\"),\n        logger.With(\"Age\", 30),\n        logger.WithMessage(\"Debugging application\"),\n    )\n\n    log.Info(\n        logger.With(\"Name\", \"Jane Doe\"),\n        logger.With(\"Age\", 25),\n        logger.WithMessage(\"Application started\"),\n    )\n\n    log.Warn(\n        logger.With(\"Name\", \"Jim Doe\"),\n        logger.With(\"Age\", 40),\n        logger.WithMessage(\"Potential issue detected\"),\n    )\n\n    log.Error(\n        logger.With(\"Name\", \"Jake Doe\"),\n        logger.With(\"Age\", 50),\n        logger.WithMessage(\"An error occurred\"),\n    )\n\n    // Flush logs before exiting\n    log.Sync()\n}\n```\n\n## Types and Functions\n\n### Logger\n\nDefines methods for logging at various levels:\n\n- **`Debug(options ...LogOptions)`**: Logs a debug-level message (development only).\n- **`Info(options ...LogOptions)`**: Logs an info-level message.\n- **`Warn(options ...LogOptions)`**: Logs a warning-level message.\n- **`Error(options ...LogOptions)`**: Logs an error-level message.\n- **`Panic(options ...LogOptions)`**: Logs a panic-level message.\n- **`Sync()`**: Flushes any buffered log entries.\n\n### Logger Builder\n\nUsed to configure and create a `Logger` instance:\n\n- **`NewLogger()`**: Initializes a `LoggerBuilder` with default settings.\n- **`SetBufferSize(size uint)`**: Configures the buffer size for the logger's channel.\n- **`SetEnv(dev bool)`**: Set development or production mode for the logger.\n- **`SetSimple(simple bool)`**: Set simple formatting for the logger.\n- **`SetSilent(silent bool)`**: Set silent mode for logger (no print to console).\n- **`Path(root string)`**: Sets the root directory for log files.\n- **`Prefix(prefix string)`**: Sets the prefix for log file names.\n- **`Extension(ext string)`**: Sets the extension for log file names.\n- **`Daily()`**: Sets the log file layout to daily.\n- **`Monthly()`**: Sets the log file layout to monthly.\n- **`CustomLayout(layout string)`**: Sets a custom layout for log file names.\n- **`StdFormatter()`**: Sets the logger to use the standard time formatter.\n- **`JalaaliFormatter()`**: Sets the logger to use the Jalaali time formatter.\n- **`CustomFormatter(formatter TimeFormatter)`**: Sets a custom time formatter for the logger.\n- **`Logger()`**: Creates and returns a `Logger` instance.\n\n### Log Options\n\nFunctions to modify log entries:\n\n- **`With(key string, value any)`**: Adds extra metadata to a log entry.\n- **`WithMessage(msg string)`**: Adds a message to a log entry.\n\n### TimeFormatter\n\nA function signature for time formatting:\n\n```go\ntype TimeFormatter func(t time.Time, layout string) string\n```\n\nBuilt-in formatters:\n\n- **`StdFormatter`**: Formats time using the standard library.\n- **`JalaaliFormatter`**: Formats time using the Jalaali calendar.\n\n### Log Levels\n\nDefines the severity levels for log messages:\n\n- `DEBUG`, `INFO`, `WARN`, `ERROR`, `PANIC`.\n\n## License\n\nThis project is licensed under the ISC License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-universal%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-universal%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-universal%2Flogger/lists"}