{"id":24487298,"url":"https://github.com/rizanw/go-log","last_synced_at":"2026-05-19T08:02:42.093Z","repository":{"id":257813146,"uuid":"868146165","full_name":"rizanw/go-log","owner":"rizanw","description":"ready to use configurable, structured, hierarchical logging wrapper for Go ","archived":false,"fork":false,"pushed_at":"2024-10-23T04:48:12.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T15:45:24.752Z","etag":null,"topics":["go","golang-library","golang-package","golang-tools","library","log","log-wrapper","logging","package","wrapper","zap","zerolog"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/rizanw/go-log","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/rizanw.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":"2024-10-05T15:41:40.000Z","updated_at":"2025-01-04T06:53:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"03d3dcfd-631e-490a-845d-fc3acd00bf6f","html_url":"https://github.com/rizanw/go-log","commit_stats":null,"previous_names":["rizanw/go-log"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizanw%2Fgo-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizanw%2Fgo-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizanw%2Fgo-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rizanw%2Fgo-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rizanw","download_url":"https://codeload.github.com/rizanw/go-log/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243658270,"owners_count":20326467,"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":["go","golang-library","golang-package","golang-tools","library","log","log-wrapper","logging","package","wrapper","zap","zerolog"],"created_at":"2025-01-21T15:35:53.110Z","updated_at":"2025-12-30T11:39:27.803Z","avatar_url":"https://github.com/rizanw.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-log\n\ngo-log is a structured logging package to provides a simple way to log messages in different levels.\nIt is designed to be simple and easy to use.\n\n## Quick Start\n\n```bash\ngo get -u github.com/rizanw/go-log\n```\n\nAnd you can drop this package in to replace your log very simply:\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\n\t// import this log package\n\tlog \"github.com/rizanw/go-log\"\n)\n\nfunc main() {\n\tvar (\n\t\tappName = \"go-app\"\n\t)\n\n\t// use the log like this\n\tlog.Infof(context.TODO(), nil, log.KV{\"key\": \"value\"}, \"starting app %s\", appName)\n}\n```\n\n## Configurable Log\n\nYou can also customize configuration for your log very simple:\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t// import this log package\n\tlog \"github.com/rizanw/go-log\"\n)\n\nfunc main() {\n\tvar (\n\t\tctx = context.Background()\n\t\terr error\n\t)\n\n\t// customize configuration like this\n\terr = log.SetConfig(\u0026log.Config{\n\t\tAppName:     \"go-app\",\n\t\tEnvironment: \"development\",\n\t\tWithCaller:  true,\n\t})\n\tif err != nil {\n\t\t// use the log like this\n\t\tlog.Errorf(ctx, err, nil, \"we got error with message: %s\", err.Error())\n\t}\n}\n\n```\n\nNote: `SetConfig` func is not thread safe, so call it once when initializing the app only.\n\n### Configuration\n\nbelow is list of available configuration:\n\n| Key                 | type                        | Description                                                                        |\n|---------------------|-----------------------------|------------------------------------------------------------------------------------|\n| AppName             | string                      | your application name                                                              |\n| Environment         | string                      | your application environment                                                       |\n| Level               | log.Level                   | minimum log level to be printed (default: DEBUG)                                   |\n| TimeFormat          | string                      | desired time format (default: RFC3339)                                             |\n| WithCaller          | bool                        | caller toggle to print which line is calling the log (default: false)              |\n| CallerSkip          | int                         | which caller line wants to be print                                                |\n| WithStack           | bool                        | toggle to print which stack trace error located (default: false)                   |\n| StackLevel          | log.Level                   | minimum log level for zap stack trace (default: ERROR)                             |\n| StackMarshaller     | func(err error) interface{} | function to get and log the stack trace for zerolog (default: `zerolog/pkgerrors`) |\n| UseMultiWriters     | bool                        | a toggle to print log into log file and log console (FilePath required)            |\n| FilePath            | string                      | specify your output log files directories (default: no file)                       |\n| MaskSensitiveData   | []string                    | keys of field to be masked                                                         |\n| SensitiveDataMasker | func(value string) string   | function to modify sensitive value into something (default: `*****`)               |\n| UseJSON             | bool                        | a toggle to format log as json (default: false)                                    |\n| UseColor            | bool                        | a toggle to colorize your log console with zerolog                                 |\n| Engine              | log.Engine                  | desired engine logger (default: zerolog)                                           |                      \n\nnote:\n\n- Keep in mind that taking a caller or stacktrace is eager and expensive (relatively speaking) and makes an additional\n  allocation.\n\n#### Engine Options\n\nThis pkg currently provides two engine (aka logger) to use:\n\n- [Zerolog](https://github.com/rs/zerolog)\n- [Zap](https://github.com/uber-go/zap)\n\nif you confused to decide, you can\nread [this article](https://betterstack.com/community/guides/logging/best-golang-logging-libraries/) as reference.\n\n## Structured Log\n\nby implementing structured logging, we can easily filter and search logs based on the key-value fields:\n\n```json\n{\n  \"level\": \"info\",\n  \"timestamp\": \"2024-07-23T14:52:00Z\",\n  \"app\": \"golang-app\",\n  \"env\": \"development\",\n  \"request_id\": \"5825511e-196f-406b-baed-67a9da40a26a\",\n  \"source\": {\n    \"app\": \"ios\",\n    \"version\": \"1.10.5\"\n  },\n  \"metadata\": {\n    \"username\": \"hello\",\n    \"password\": \"*****\"\n  },\n  \"message\": \"[HTTP][Request]: POST /api/v1/login\"\n}\n```\n\n## Hierarchical Log\n\nthis package provide 5 hierarchical levels based on the severity:\n\n- **DEBUG** - this log level is used to obtain diagnostic information that can be helpful for troubleshooting and\n  debugging. These messages often contain verbose or fine-grained information about the inner workings of the system or\n  application. When teams look for log data to filter out for cost savings, they often start with DEBUG logs.\n- **INFO** - this log level provide general information about the status of the system. This log level is useful for\n  tracking an\n  application's progress or operational milestones. For example, your application may create INFO logs upon application\n  startup, when a user makes configuration changes, or when they successfully complete tasks.\n- **WARN** - this log level serves as a signal for potential issues that are not necessarily a critical error. For\n  example, your system may generate a WARN log when it is short on resources. If WARN logs go unaddressed, they may lead\n  to bigger issues in the future.\n- **ERROR** - this log level indicates significant problems that happened in the system. It usually denotes that an\n  unexpected event or exception has occurred. This log level is crucial for identifying issues affecting user experience\n  or overall functionality, so immediate attention is needed.\n- **FATAL** - this log level shows severe conditions that cause the system to terminate or operate in a significantly\n  degraded state. These logs are used for serious problems, like crashes or conditions that threaten data integrity or\n  application stability. FATAL logs often lead to service disruptions.\n\n## Usage\n\n### logging\n\nyou can log based on the severity hierarchy and each severity has 2 main functions:\n\n- unformatted, similar to `Println` in `fmt` package\n\n```go\n// Debug\nlog.Debug(ctx, err, log.KV{}, \"this is a debug log\")\n// Info\nlog.Info(ctx, err, log.KV{}, \"this is an info log\")\n// Warn\nlog.Warn(ctx, err, log.KV{}, \"this is a warning log\")\n// Error\nlog.Error(ctx, err, log.KV{}, \"this is an error log\")\n// Fatal\nlog.Fatal(ctx, err, log.KV{}, \"this is a fatal log\")\n```\n\n- formatted, similar to `Printf` in `fmt` package\n\n```go\n// Debug\nlog.Debugf(ctx, err, log.KV{}, \"this is a debug log: %s\", err.Error())\n// Info\nlog.Infof(ctx, err, log.KV{}, \"this is an info log: %s\", err.Error())\n// Warn\nlog.Warnf(ctx, err, log.KV{}, \"this is a warning log: %s\", err.Error())\n// Error\nlog.Errorf(ctx, err, log.KV{}, \"this is an error log: %s\", err.Error())\n// Fatal\nlog.Fatalf(ctx, err, log.KV{}, \"this is a fatal log: %s\", err.Error())\n```\n\n### context\n\n```go\n// set request_id (generated) logging into context\nctx = log.SetRequestID(ctx)\n\n// set request_id (by yours) logging into context\nctx = log.SetRequestID(ctx, requestID)\n```\n\n```go\n// set user_info logging into context\nctx = log.SetUserInfo(ctx, log.KV{\"username\": \"hello\"})\n```\n\n```go\n// set source logging into context\nctx = log.SetSource(ctx, log.KV{\"app\": source.App, \"version\": source.Version})\n```\n\n### Additional Fields\n\nNeed more fields? coming soon!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frizanw%2Fgo-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frizanw%2Fgo-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frizanw%2Fgo-log/lists"}