{"id":17304616,"url":"https://github.com/jordan-rash/slog-handler","last_synced_at":"2025-07-04T18:06:24.459Z","repository":{"id":230245097,"uuid":"778852392","full_name":"jordan-rash/slog-handler","owner":"jordan-rash","description":"A configurable log/slog handler that does JSON and text","archived":false,"fork":false,"pushed_at":"2025-04-11T13:48:08.000Z","size":94,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-11T14:52:02.269Z","etag":null,"topics":["golang","handler","logging","slog"],"latest_commit_sha":null,"homepage":"https://disorder.dev/shandler","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/jordan-rash.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-03-28T14:35:42.000Z","updated_at":"2025-04-11T13:47:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"f008b3ce-d4b9-457a-b2ac-9dc89c46622f","html_url":"https://github.com/jordan-rash/slog-handler","commit_stats":null,"previous_names":["jordan-rash/slog-handler"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordan-rash%2Fslog-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordan-rash%2Fslog-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordan-rash%2Fslog-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordan-rash%2Fslog-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jordan-rash","download_url":"https://codeload.github.com/jordan-rash/slog-handler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248886331,"owners_count":21177645,"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","handler","logging","slog"],"created_at":"2024-10-15T11:53:29.886Z","updated_at":"2025-04-14T13:14:12.219Z","avatar_url":"https://github.com/jordan-rash.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Lint | Test](https://github.com/jordan-rash/slog-handler/actions/workflows/ltb.yml/badge.svg)](https://github.com/jordan-rash/slog-handler/actions/workflows/ltb.yml)\n[![Dependabot Updates](https://github.com/jordan-rash/slog-handler/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/jordan-rash/slog-handler/actions/workflows/dependabot/dependabot-updates)\n[![CodeQL](https://github.com/jordan-rash/slog-handler/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/jordan-rash/slog-handler/actions/workflows/github-code-scanning/codeql)\n[![Go Report Card](https://goreportcard.com/badge/disorder.dev/shandler)](https://goreportcard.com/report/disorder.dev/shandler)\n[![Go Reference](https://pkg.go.dev/badge/disorder.dev/shandler.svg)](https://pkg.go.dev/disorder.dev/shandler)\n\n# SLOG Handler with more knobs\n\nAs great as `log/slog` is, the provided handlers don't have enough customization knobs. This tries to\nprovide more flexibility to the user.\n\n## Installation\n\n```shell\ngo get disorder.dev/shandler\n```\n\n## Features\n\n#### WithJSON\n\nEnables JSON output for the log message. This is useful for structured logging.\n\n#### WithLogLevel\n\nControls the log level for the message. This is useful for filtering messages.\n\n#### WithLineInfo(short)\n\nAdds the file and line number to a `slog_info` attribute within the log message  \nif `short == true`; the file basename and line number are included.  \nif `short == false`; the function name, full file path, and line number are included.\n\n`short` is `true` by default. This is helpful in smaller programs where the full path is not needed.\n\n#### WithTimeFormat\n\nControls the time format for the messages.\n\n#### WithTextOutputFormat\n\nThis is a format string that gets used in text based logs. It takes 3 strings: time, level, and message (in that order). Include a newline at the end of your string.\n\n#### WithStdOut\n\nControls which `io.Writer` is used for non-error log messages.\n\n#### WithStdErr\n\nControls which `io.Writer` is used for error messages.\n\n#### WithColor\n\nAdds color to the log levels in text mode\n\n#### With{Debug|Info|Warn|Error}Color\n\nOverrides the default color for the log level.\n\n#### WithShortLevels\n\nPrints 3 character log levels instead of the full name. In text mode, this helps keep the log lines visually straight.\n\n#### WithPid\n\nAdds the process ID to the log message.\n\n#### WithGroupRightJustify\n\nRight justifies the log group name. This is useful for visually grouping log messages.\nWill attempt to calculate terminal width; if an error occurs, it will default to 80 characters.\nOverrides WithGroupTextOutputFormat\n\n## Examples\n\n```go\nlogger = slog.New(shandler.NewHandler(\n shandler.WithLogLevel(slog.LevelDebug),\n shandler.WithTimeFormat(time.RFC822),\n shandler.WithTextOutputFormat(\"%s | %s | %s\\n\"),\n shandler.WithStdErr(os.Stdout),\n))\nlogger.With(slog.String(\"app\", \"myapp\")).Debug(\"test\")\n```\n\n#### Trace Log Level\n\nLibrary includes an easier way to log trace messages. This is useful for debugging chatty logs.\n\n```go\nlogger = slog.New(shandler.NewHandler(\n shandler.WithLogLevel(shandler.LevelTrace),\n))\nlogger.Log(context.Background(), shandler.LevelTrace, \"trace test\")\n```\n\n## Benchmarks if you're into that sort of thing\n\n```shell\ngoos: linux\ngoarch: amd64\npkg: disorder.dev/shandler\ncpu: 13th Gen Intel(R) Core(TM) i9-13900H\n\nBenchmarkHandlers/handler_text_log-20            3211198               351.4 ns/op\nBenchmarkHandlers/stdlib_text_log-20             3325005               356.1 ns/op\nBenchmarkHandlers/handler_json_log-20            2108128               592.3 ns/op\nBenchmarkHandlers/stdlib_json_log-20             3445792               379.6 ns/op\n\nPASS\nok      disorder.dev/shandler   6.604s\n```\n\n\u003e The JSON Handler here is much slower as it uses the JSON library under the covers. The stdlib implementation builds the string manually, so its faster. 🤷🏼‍♀️\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordan-rash%2Fslog-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjordan-rash%2Fslog-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordan-rash%2Fslog-handler/lists"}