{"id":13830376,"url":"https://github.com/samber/slog-syslog","last_synced_at":"2025-06-13T19:36:34.204Z","repository":{"id":152480097,"uuid":"626102825","full_name":"samber/slog-syslog","owner":"samber","description":"🚨 slog: Syslog handler","archived":false,"fork":false,"pushed_at":"2025-05-06T10:31:28.000Z","size":83,"stargazers_count":15,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-06T11:45:41.398Z","etag":null,"topics":["aggregation","attribute","errors","go","golang","handler","linux","log","log-level","logger","logstash","middleware","slog","structured-logging","syslog"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/samber/slog-syslog/v2","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/samber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"github":["samber"]}},"created_at":"2023-04-10T19:59:50.000Z","updated_at":"2025-05-06T10:31:25.000Z","dependencies_parsed_at":"2024-02-11T21:27:58.222Z","dependency_job_id":"0c3a7c3c-cb67-4c48-886a-232568544774","html_url":"https://github.com/samber/slog-syslog","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/samber/slog-syslog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fslog-syslog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fslog-syslog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fslog-syslog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fslog-syslog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samber","download_url":"https://codeload.github.com/samber/slog-syslog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fslog-syslog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259707986,"owners_count":22899516,"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":["aggregation","attribute","errors","go","golang","handler","linux","log","log-level","logger","logstash","middleware","slog","structured-logging","syslog"],"created_at":"2024-08-04T10:00:59.232Z","updated_at":"2025-06-13T19:36:34.165Z","avatar_url":"https://github.com/samber.png","language":"Go","readme":"\n# slog: Syslog handler\n\n[![tag](https://img.shields.io/github/tag/samber/slog-syslog.svg)](https://github.com/samber/slog-syslog/releases)\n![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.21-%23007d9c)\n[![GoDoc](https://godoc.org/github.com/samber/slog-syslog?status.svg)](https://pkg.go.dev/github.com/samber/slog-syslog)\n![Build Status](https://github.com/samber/slog-syslog/actions/workflows/test.yml/badge.svg)\n[![Go report](https://goreportcard.com/badge/github.com/samber/slog-syslog)](https://goreportcard.com/report/github.com/samber/slog-syslog)\n[![Coverage](https://img.shields.io/codecov/c/github/samber/slog-syslog)](https://codecov.io/gh/samber/slog-syslog)\n[![Contributors](https://img.shields.io/github/contributors/samber/slog-syslog)](https://github.com/samber/slog-syslog/graphs/contributors)\n[![License](https://img.shields.io/github/license/samber/slog-syslog)](./LICENSE)\n\nA Syslog Handler for [slog](https://pkg.go.dev/log/slog) Go library.\n\n\u003cdiv align=\"center\"\u003e\n  \u003chr\u003e\n  \u003csup\u003e\u003cb\u003eSponsored by:\u003c/b\u003e\u003c/sup\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://quickwit.io?utm_campaign=github_sponsorship\u0026utm_medium=referral\u0026utm_content=samber-slog-syslog\u0026utm_source=github\"\u003e\n    \u003cdiv\u003e\n      \u003cimg src=\"https://github.com/samber/oops/assets/2951285/49aaaa2b-b8c6-4f21-909f-c12577bb6a2e\" width=\"240\" alt=\"Quickwit\"\u003e\n    \u003c/div\u003e\n    \u003cdiv\u003e\n      Cloud-native search engine for observability - An OSS alternative to Splunk, Elasticsearch, Loki, and Tempo.\n    \u003c/div\u003e\n  \u003c/a\u003e\n  \u003chr\u003e\n\u003c/div\u003e\n\n**See also:**\n\n- [slog-multi](https://github.com/samber/slog-multi): `slog.Handler` chaining, fanout, routing, failover, load balancing...\n- [slog-formatter](https://github.com/samber/slog-formatter): `slog` attribute formatting\n- [slog-sampling](https://github.com/samber/slog-sampling): `slog` sampling policy\n- [slog-mock](https://github.com/samber/slog-mock): `slog.Handler` for test purposes\n\n**HTTP middlewares:**\n\n- [slog-gin](https://github.com/samber/slog-gin): Gin middleware for `slog` logger\n- [slog-echo](https://github.com/samber/slog-echo): Echo middleware for `slog` logger\n- [slog-fiber](https://github.com/samber/slog-fiber): Fiber middleware for `slog` logger\n- [slog-chi](https://github.com/samber/slog-chi): Chi middleware for `slog` logger\n- [slog-http](https://github.com/samber/slog-http): `net/http` middleware for `slog` logger\n\n**Loggers:**\n\n- [slog-zap](https://github.com/samber/slog-zap): A `slog` handler for `Zap`\n- [slog-zerolog](https://github.com/samber/slog-zerolog): A `slog` handler for `Zerolog`\n- [slog-logrus](https://github.com/samber/slog-logrus): A `slog` handler for `Logrus`\n\n**Log sinks:**\n\n- [slog-datadog](https://github.com/samber/slog-datadog): A `slog` handler for `Datadog`\n- [slog-betterstack](https://github.com/samber/slog-betterstack): A `slog` handler for `Betterstack`\n- [slog-rollbar](https://github.com/samber/slog-rollbar): A `slog` handler for `Rollbar`\n- [slog-loki](https://github.com/samber/slog-loki): A `slog` handler for `Loki`\n- [slog-sentry](https://github.com/samber/slog-sentry): A `slog` handler for `Sentry`\n- [slog-syslog](https://github.com/samber/slog-syslog): A `slog` handler for `Syslog`\n- [slog-logstash](https://github.com/samber/slog-logstash): A `slog` handler for `Logstash`\n- [slog-fluentd](https://github.com/samber/slog-fluentd): A `slog` handler for `Fluentd`\n- [slog-graylog](https://github.com/samber/slog-graylog): A `slog` handler for `Graylog`\n- [slog-quickwit](https://github.com/samber/slog-quickwit): A `slog` handler for `Quickwit`\n- [slog-slack](https://github.com/samber/slog-slack): A `slog` handler for `Slack`\n- [slog-telegram](https://github.com/samber/slog-telegram): A `slog` handler for `Telegram`\n- [slog-mattermost](https://github.com/samber/slog-mattermost): A `slog` handler for `Mattermost`\n- [slog-microsoft-teams](https://github.com/samber/slog-microsoft-teams): A `slog` handler for `Microsoft Teams`\n- [slog-webhook](https://github.com/samber/slog-webhook): A `slog` handler for `Webhook`\n- [slog-kafka](https://github.com/samber/slog-kafka): A `slog` handler for `Kafka`\n- [slog-nats](https://github.com/samber/slog-nats): A `slog` handler for `NATS`\n- [slog-parquet](https://github.com/samber/slog-parquet): A `slog` handler for `Parquet` + `Object Storage`\n- [slog-channel](https://github.com/samber/slog-channel): A `slog` handler for Go channels\n\n## 🚀 Install\n\n```sh\ngo get github.com/samber/slog-syslog/v2\n```\n\n**Compatibility**: go \u003e= 1.21\n\nNo breaking changes will be made to exported APIs before v3.0.0.\n\n## 💡 Usage\n\nGoDoc: [https://pkg.go.dev/github.com/samber/slog-syslog/v2](https://pkg.go.dev/github.com/samber/slog-syslog/v2)\n\n### Handler options\n\n```go\ntype Option struct {\n\t// log level (default: debug)\n\tLevel slog.Leveler\n\n\t// connection to syslog server\n\tWriter *syslog.Writer\n\n\t// optional: customize json payload builder\n\tConverter Converter\n\t// optional: custom marshaler\n\tMarshaler func(v any) ([]byte, error)\n\t// optional: fetch attributes from context\n\tAttrFromContext []func(ctx context.Context) []slog.Attr\n\n\t// optional: see slog.HandlerOptions\n\tAddSource   bool\n\tReplaceAttr func(groups []string, a slog.Attr) slog.Attr\n}\n```\n\nAttributes will be injected in log payload.\n\nOther global parameters:\n\n```go\nslogsyslog.SourceKey = \"source\"\nslogsyslog.ContextKey = \"extra\"\nslogsyslog.ErrorKeys = []string{\"error\", \"err\"}\n```\n\n### Example\n\n```go\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"log/slog\"\n\t\"net\"\n\t\"time\"\n\n\tslogsyslog \"github.com/samber/slog-syslog/v2\"\n)\n\nfunc main() {\n\t// ncat -u -l 9999 -k\n\twriter, err := net.Dial(\"udp\", \"localhost:9999\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlogger := slog.New(slogsyslog.Option{Level: slog.LevelDebug, Writer: writer}.NewSyslogHandler())\n\tlogger = logger.\n\t\tWith(\"environment\", \"dev\").\n\t\tWith(\"release\", \"v1.0.0\")\n\n\t// log error\n\tlogger.\n\t\tWith(\"category\", \"sql\").\n\t\tWith(\"query.statement\", \"SELECT COUNT(*) FROM users;\").\n\t\tWith(\"query.duration\", 1*time.Second).\n\t\tWith(\"error\", fmt.Errorf(\"could not count users\")).\n\t\tError(\"caramba!\")\n\n\t// log user signup\n\tlogger.\n\t\tWith(\n\t\t\tslog.Group(\"user\",\n\t\t\t\tslog.String(\"id\", \"user-123\"),\n\t\t\t\tslog.Time(\"created_at\", time.Now()),\n\t\t\t),\n\t\t).\n\t\tInfo(\"user registration\")\n}\n```\n\nOutput:\n\n```json\n@cee: {\"timestamp\":\"2023-04-10T14:00:0.000000\", \"level\":\"ERROR\", \"message\":\"caramba!\", \"error\":{ \"error\":\"could not count users\", \"kind\":\"*errors.errorString\", \"stack\":null }, \"extra\":{ \"environment\":\"dev\", \"release\":\"v1.0.0\", \"category\":\"sql\", \"query.statement\":\"SELECT COUNT(*) FROM users;\", \"query.duration\": \"1s\" }}\n\n@cee: {\"timestamp\":\"2023-04-10T14:00:0.000000\", \"level\":\"INFO\", \"message\":\"user registration\", \"error\":null, \"extra\":{ \"environment\":\"dev\", \"release\":\"v1.0.0\", \"user\":{ \"id\":\"user-123\", \"created_at\":\"2023-04-10T14:00:0.000000+00:00\"}}}\n```\n\n### Tracing\n\nImport the samber/slog-otel library.\n\n```go\nimport (\n\tslogsyslog \"github.com/samber/slog-syslog\"\n\tslogotel \"github.com/samber/slog-otel\"\n\t\"go.opentelemetry.io/otel/sdk/trace\"\n)\n\nfunc main() {\n\ttp := trace.NewTracerProvider(\n\t\ttrace.WithSampler(trace.AlwaysSample()),\n\t)\n\ttracer := tp.Tracer(\"hello/world\")\n\n\tctx, span := tracer.Start(context.Background(), \"foo\")\n\tdefer span.End()\n\n\tspan.AddEvent(\"bar\")\n\n\tlogger := slog.New(\n\t\tslogsyslog.Option{\n\t\t\t// ...\n\t\t\tAttrFromContext: []func(ctx context.Context) []slog.Attr{\n\t\t\t\tslogotel.ExtractOtelAttrFromContext([]string{\"tracing\"}, \"trace_id\", \"span_id\"),\n\t\t\t},\n\t\t}.NewSyslogHandler(),\n\t)\n\n\tlogger.ErrorContext(ctx, \"a message\")\n}\n```\n\n## 🤝 Contributing\n\n- Ping me on twitter [@samuelberthe](https://twitter.com/samuelberthe) (DMs, mentions, whatever :))\n- Fork the [project](https://github.com/samber/slog-syslog)\n- Fix [open issues](https://github.com/samber/slog-syslog/issues) or request new features\n\nDon't hesitate ;)\n\n```bash\n# Install some dev dependencies\nmake tools\n\n# Run tests\nmake test\n# or\nmake watch-test\n```\n\n## 👤 Contributors\n\n![Contributors](https://contrib.rocks/image?repo=samber/slog-syslog)\n\n## 💫 Show your support\n\nGive a ⭐️ if this project helped you!\n\n[![GitHub Sponsors](https://img.shields.io/github/sponsors/samber?style=for-the-badge)](https://github.com/sponsors/samber)\n\n## 📝 License\n\nCopyright © 2023 [Samuel Berthe](https://github.com/samber).\n\nThis project is [MIT](./LICENSE) licensed.\n","funding_links":["https://github.com/sponsors/samber"],"categories":["Log forwarding"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamber%2Fslog-syslog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamber%2Fslog-syslog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamber%2Fslog-syslog/lists"}