{"id":17760854,"url":"https://github.com/cyrus2281/go-logger","last_synced_at":"2026-06-24T01:32:43.998Z","repository":{"id":258722627,"uuid":"875305247","full_name":"cyrus2281/go-logger","owner":"cyrus2281","description":"Complete customizable GoLang logger utility package","archived":false,"fork":false,"pushed_at":"2024-10-19T18:26:07.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T13:18:03.429Z","etag":null,"topics":["go","go-logger","go-logging","golang","logger","logging"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/cyrus2281/go-logger","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cyrus2281.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGE_LOGS.md","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":"2024-10-19T16:19:29.000Z","updated_at":"2024-10-19T18:25:40.000Z","dependencies_parsed_at":"2024-10-20T10:23:55.116Z","dependency_job_id":"2c442186-c52e-44cd-95d5-bd7fb38686c3","html_url":"https://github.com/cyrus2281/go-logger","commit_stats":null,"previous_names":["cyrus2281/go-logger"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/cyrus2281/go-logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrus2281%2Fgo-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrus2281%2Fgo-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrus2281%2Fgo-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrus2281%2Fgo-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cyrus2281","download_url":"https://codeload.github.com/cyrus2281/go-logger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyrus2281%2Fgo-logger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34713789,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","response_time":65,"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":["go","go-logger","go-logging","golang","logger","logging"],"created_at":"2024-10-26T19:13:42.950Z","updated_at":"2026-06-24T01:32:43.979Z","avatar_url":"https://github.com/cyrus2281.png","language":"Go","funding_links":["https://www.buymeacoffee.com/cyrus2281"],"categories":[],"sub_categories":[],"readme":"# Go Logger Package\n\n[![GitHub Tag](https://img.shields.io/github/v/tag/cyrus2281/go-logger?label=Version)](https://pkg.go.dev/github.com/cyrus2281/go-logger)\n[![License](https://img.shields.io/github/license/cyrus2281/go-logger)](https://github.com/cyrus2281/go-logger/blob/main/LICENSE)\n[![buyMeACoffee](https://img.shields.io/badge/BuyMeACoffee-cyrus2281-yellow?logo=buymeacoffee)](https://www.buymeacoffee.com/cyrus2281)\n[![GitHub issues](https://img.shields.io/github/issues/cyrus2281/go-logger?color=red)](https://github.com/cyrus2281/go-logger/issues)\n[![GitHub stars](https://img.shields.io/github/stars/cyrus2281/go-logger?style=social)](https://github.com/cyrus2281/go-logger/stargazers)\n\n- [Go Logger Package](#go-logger-package)\n  - [Features](#features)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Using the Default Logger](#using-the-default-logger)\n    - [Basic Logger Setup](#basic-logger-setup)\n    - [Customizing Log Prefixes](#customizing-log-prefixes)\n    - [Log Levels](#log-levels)\n    - [Formatted Logs](#formatted-logs)\n    - [Error Checking](#error-checking)\n  - [Log Level Behavior](#log-level-behavior)\n  - [Advanced Usage](#advanced-usage)\n    - [Custom Output Writers](#custom-output-writers)\n  - [Contributing](#contributing)\n    - [Running Tests](#running-tests)\n    - [License](#license)\n\nA lightweight and customizable logging package for Go. This package provides support for different log levels, output streams, formatted logs, and error handling, making it easy to integrate logging into your application.\n\n## Features\n\n- Support for log levels: `DEBUG`, `INFO`, `WARNING`, `ERROR`, `FATAL`, `OFF`\n- Customizable log message and error prefixes\n- Separate output writers for standard logs and errors\n- Easy-to-use functions for logging formatted messages\n- Error checking with built-in logging for `ERROR` and `FATAL` levels\n- Fatal logs that exit the program\n\n## Installation\n\n```bash\ngo get github.com/cyrus2281/go-logger\n```\n\n## Usage\n\n### Using the Default Logger\n\nThe default logger writes to `os.Stdout` and `os.Stderr` and has the log level set to `INFO`.\nAll of which can be customized using the `SetOutputWriters`, `SetLogLevel`, and `SetPrefixFormatters` methods.\n\n\n```go\npackage main\n\nimport (\n\t\"os\"\n\t\"github.com/cyrus2281/go-logger/logger\"\n)\n\nfunc main() {\n\t// Logging examples\n\tlogger.Infoln(\"This is an info message\")\n\tlogger.Warningln(\"This is a warning message\")\n\tlogger.Errorln(\"This is an error message\")\n}\n```\n### Basic Logger Setup\n\nYou can create a new logger using the `NewLogger` function by specifying the log level and output writers:\n\n```go\npackage main\n\nimport (\n\t\"os\"\n\t\"github.com/cyrus2281/go-logger/logger\"\n)\n\nfunc main() {\n\t// Create a logger with INFO level\n\tlog := logger.NewLogger(logger.INFO, os.Stdout, os.Stderr)\n\n\t// Logging examples\n\tlog.Infoln(\"This is an info message\")\n\tlog.Warningln(\"This is a warning message\")\n\tlog.Errorln(\"This is an error message\")\n}\n```\n\n### Customizing Log Prefixes\n\nYou can set prefixes for standard log messages and error messages:\n\n```go\nfunc formatter(level int) string {\n    currentDate := time.Now().Format(\"2006-01-02\")\n\treturn fmt.Sprintf(\"[%s] [%d] \", currentDate, level)\n}\n\nlog.SetPrefixFormatter(formatter)\nlog.SetErrorPrefixFormatter(formatter)\n\nlog.Infoln(\"Application started\")\nlog.Errorln(\"Failed to connect to database\")\n```\n\n### Log Levels\n\nThe package supports the following log levels, allowing you to filter messages based on importance:\n\n- `DEBUG`\n- `INFO`\n- `WARNING`\n- `ERROR`\n- `FATAL`\n- `OFF`\n\n```go\nlog.SetLogLevel(logger.WARNING)\n\nlog.Debugln(\"This will not be logged\")\nlog.Infoln(\"This will not be logged\")\nlog.Warningln(\"This will be logged\")\nlog.Errorln(\"This will be logged\")\n```\n\n### Formatted Logs\n\nYou can log formatted messages using the `DebugF`, `InfoF`, `WarningF`, `ErrorF`, and `FatalF` methods.\n\n```go\nlog.InfoF(\"User %s logged in at %s\", \"john_doe\", \"10:00 AM\")\nlog.ErrorF(\"Failed to load file: %s\", \"config.yaml\")\n```\n\n### Error Checking\n\nThe logger provides utility methods for checking errors and logging them automatically:\n\n```go\nerr := errors.New(\"connection failed\")\nlog.CheckError(err)  // Logs if `err` is not nil\n\nfatalErr := errors.New(\"fatal error\")\nlog.CheckFatal(fatalErr)  // Logs and exits the program if `fatalErr` is not nil\n```\n\n## Log Level Behavior\n\nThe log level controls which messages will be printed based on their importance:\n\n| Log Level | Logs Debug | Logs Info | Logs Warning | Logs Error | Logs Fatal |\n| --------- | ---------- | --------- | ------------ | ---------- | ---------- |\n| `DEBUG`   | ✔          | ✔         | ✔            | ✔          | ✔          |\n| `INFO`    | ✖          | ✔         | ✔            | ✔          | ✔          |\n| `WARNING` | ✖          | ✖         | ✔            | ✔          | ✔          |\n| `ERROR`   | ✖          | ✖         | ✖            | ✔          | ✔          |\n| `FATAL`   | ✖          | ✖         | ✖            | ✖          | ✔          |\n| `OFF`     | ✖          | ✖         | ✖            | ✖          | ✖          |\n\n## Advanced Usage\n\n### Custom Output Writers\n\nYou can direct standard and error logs to different output writers (e.g., files, network streams, etc.).\n\n```go\nvar outBuf, errBuf bytes.Buffer\n\nlog.SetOutputWriters(\u0026outBuf, \u0026errBuf)\n\nlog.Infoln(\"This will be written to outBuf\")\nlog.Errorln(\"This will be written to errBuf\")\n```\n\n## Contributing\n\nContributions are welcome! Feel free to submit issues or pull requests to help improve this package.\n\n### Running Tests\n\nTo run the tests for this package, use:\n\n```bash\ngo test ./...\n```\n\n### License\n\nThis project is licensed under the Apache v2.0 License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyrus2281%2Fgo-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcyrus2281%2Fgo-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyrus2281%2Fgo-logger/lists"}