{"id":23554748,"url":"https://github.com/alejoacosta74/go-logger","last_synced_at":"2025-10-25T07:46:43.867Z","repository":{"id":64299295,"uuid":"568170925","full_name":"alejoacosta74/go-logger","owner":"alejoacosta74","description":"A golang logger based on logrus library, implementing out-of-the-box ","archived":false,"fork":false,"pushed_at":"2025-01-24T21:18:19.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-24T22:22:17.910Z","etag":null,"topics":["golang","logging","singleton-pattern"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alejoacosta74.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-11-19T17:10:45.000Z","updated_at":"2025-01-24T21:17:16.000Z","dependencies_parsed_at":"2024-11-25T14:46:49.462Z","dependency_job_id":"60fadafd-2077-4951-b758-ebcc5cde8065","html_url":"https://github.com/alejoacosta74/go-logger","commit_stats":null,"previous_names":["alejoacosta74/go-logger"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejoacosta74%2Fgo-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejoacosta74%2Fgo-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejoacosta74%2Fgo-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alejoacosta74%2Fgo-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alejoacosta74","download_url":"https://codeload.github.com/alejoacosta74/go-logger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239295996,"owners_count":19615434,"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","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","logging","singleton-pattern"],"created_at":"2024-12-26T12:25:10.421Z","updated_at":"2025-10-25T07:46:38.846Z","avatar_url":"https://github.com/alejoacosta74.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Logger Library\n\nA flexible and feature-rich logging library for Go applications, built on top of [logrus](https://github.com/sirupsen/logrus). This library provides enhanced logging capabilities with runtime context, customizable outputs, log levels, and field support.\n\n## Features\n\n- A global logger instance ready to use\n- Multiple logging levels (Trace, Debug, Info, Warn, Error, Fatal, Panic)\n- Runtime context capturing (function names, file locations)\n- Singleton logger support\n- Customizable outputs (console, file, null)\n- Field-based logging\n- Thread-safe operation\n- ANSI color support\n- Flexible configuration through options pattern\n\n## Installation\n\n```bash\ngo get github.com/alejoacosta74/go-logger\n```\n\n## Basic Usage\n\n- Create a new logger with default settings\n```go\npackage main\n\nimport log \"github.com/alejoacosta74/go-logger\"\n\nfunc main() {\n\t// Create a new logger with default settings\n\tlog, err := log.NewLogger()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// Basic logging\n\tlog.Info(\"Hello, World!\")\n\tlog.Debug(\"This is a debug message\")\n\tlog.Error(\"Something went wrong\")\n}\n```\n\n- Or use the global logger instance\n```go\nlog.Info(\"Hello, World!\")\nlog.Debug(\"This is a debug message\")\nlog.Error(\"Something went wrong\")\n```\n## Advanced Features\n\n### Setting Log Level\n\n- Set the log level to info on the global logger instance\n```go\nlog.SetLevel(\"info\")\n```\n\n- Set the log level to info on a new logger instance\n```go\nlog, err := log.NewLogger(log.WithLevel(\"info\"))\nif err != nil {\n\tpanic(err)\n}\n```\n\n### Adding Runtime Context\n\nRuntime context adds function name and file location to log entries:\n\n```go\nlogger, := log.NewLogger(\n\tlog.WithRuntimeContext(),\n)\nlogger.Debug(\"This message will include runtime context\")\n// Output: level=debug func=main.myFunction src=main.go:25 msg=\"This message will include runtime context\"\n```\n\n### Custom Output Destinations\n\n```go\n// Write to a file\nlogger, := log.NewLogger(\n\tlog.WithFileOutput(\"app.log\"),\n)\n// Write to custom writer\nvar buf bytes.Buffer\nlogger, := log.NewLogger(\n\tlog.WithOutput(\u0026buf),\n)\n// Disable output (for testing)\nlogger, := log.NewLogger(\n\tlog.WithNullOutput(),\n)\n```\n\n### Add logging to a file\n\nThe file will be rotated when the max size is reached.\n\n```go\nlog.AddFileOutputHook(\"app.log\", \u0026log.RotatingFileConfig{\n\tMaxSize:    10,\n\tMaxBackups: 3,\n\tMaxAge:     7,\n\tCompress:   true,\n})\n```\n\n### Using Fields\n\n```go\n// Single field\nlogger.WithField(\"user_id\", \"123\").Info(\"User logged in\")\n// Multiple fields\nlogger, := logger.NewLogger(\n\tlog.WithMultipleFields(\n\t\t\"service\", \"auth\",\n\t\t\"environment\", \"production\",\n\t),\n)\n// Or add fields to existing logger\nlogger.WithFields(\n\"request_id\", \"abc-123\",\n\"user_id\", \"456\",\n).Info(\"Request processed\")\n```\n### Singleton Logger\n\n```go\n// Create or get singleton instance\nlogger, err := log.NewSingletonLogger(\n\tlog.WithLevel(\"info\"),\n\tlog.WithRuntimeContext(),\n)\n// Use package-level functions\nlogger.Info(\"Using singleton logger\")\n// or\nlog.Debug(\"Debug message\")\n```\n\n### Formatting Options\n\n```go\nlog.Infof(\"Hello %s\", \"World\")\nlog.Debugf(\"Count: %d\", 42)\nlog.Errorf(\"Failed to process: %v\", err)\n```\n\n## Available Log Levels\n\n- `Trace`: Most verbose level\n- `Debug`: Debugging information\n- `Info`: General operational information\n- `Warn`: Warning messages\n- `Error`: Error messages\n- `Fatal`: Fatal errors (calls os.Exit(1))\n- `Panic`: Panic messages (calls panic())\n\n## Thread Safety\n\nThe logger is safe for concurrent use. All logging operations are thread-safe, and the singleton pattern implementation ensures safe initialization in concurrent environments.\n\n## Testing\n\nThe library includes comprehensive test coverage. Run tests with:\n```bash\ngo test ./...\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejoacosta74%2Fgo-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falejoacosta74%2Fgo-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falejoacosta74%2Fgo-logger/lists"}