{"id":13806635,"url":"https://github.com/samber/slog-fiber","last_synced_at":"2026-01-06T18:17:27.072Z","repository":{"id":159389334,"uuid":"634623582","full_name":"samber/slog-fiber","owner":"samber","description":"🚨 Fiber middleware for slog logger","archived":false,"fork":false,"pushed_at":"2025-03-25T10:58:04.000Z","size":148,"stargazers_count":74,"open_issues_count":3,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T10:09:44.712Z","etag":null,"topics":["attribute","errors","fiber","go","gofiber","golang","handler","http","log","log-level","logger","middleware","slog","structured-logging"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/samber/slog-fiber","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},"funding":{"github":["samber"]}},"created_at":"2023-04-30T18:16:45.000Z","updated_at":"2025-03-25T21:25:03.000Z","dependencies_parsed_at":"2023-10-16T11:12:19.196Z","dependency_job_id":"3f26d3b7-4893-4e23-ad55-e4d5da816cf1","html_url":"https://github.com/samber/slog-fiber","commit_stats":{"total_commits":73,"total_committers":7,"mean_commits":"10.428571428571429","dds":0.2465753424657534,"last_synced_commit":"bb8f9b8b875bd4870c2e38fd13596d19a5ec69c0"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fslog-fiber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fslog-fiber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fslog-fiber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samber%2Fslog-fiber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samber","download_url":"https://codeload.github.com/samber/slog-fiber/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471517,"owners_count":20944158,"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":["attribute","errors","fiber","go","gofiber","golang","handler","http","log","log-level","logger","middleware","slog","structured-logging"],"created_at":"2024-08-04T01:01:14.134Z","updated_at":"2026-01-06T18:17:27.066Z","avatar_url":"https://github.com/samber.png","language":"Go","funding_links":["https://github.com/sponsors/samber"],"categories":["Integrations","⚙️ Middlewares"],"sub_categories":["🌱 Third Party"],"readme":"\n# slog: Fiber middleware\n\n[![tag](https://img.shields.io/github/tag/samber/slog-fiber.svg)](https://github.com/samber/slog-fiber/releases)\n![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.21-%23007d9c)\n[![GoDoc](https://godoc.org/github.com/samber/slog-fiber?status.svg)](https://pkg.go.dev/github.com/samber/slog-fiber)\n![Build Status](https://github.com/samber/slog-fiber/actions/workflows/test.yml/badge.svg)\n[![Go report](https://goreportcard.com/badge/github.com/samber/slog-fiber)](https://goreportcard.com/report/github.com/samber/slog-fiber)\n[![Coverage](https://img.shields.io/codecov/c/github/samber/slog-fiber)](https://codecov.io/gh/samber/slog-fiber)\n[![Contributors](https://img.shields.io/github/contributors/samber/slog-fiber)](https://github.com/samber/slog-fiber/graphs/contributors)\n[![License](https://img.shields.io/github/license/samber/slog-fiber)](./LICENSE)\n\n[Fiber](https://github.com/gofiber/fiber) middleware to log http requests using [slog](https://pkg.go.dev/log/slog).\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://www.dash0.com?utm_campaign=148395251-samber%20github%20sponsorship\u0026utm_source=github\u0026utm_medium=sponsorship\u0026utm_content=samber\"\u003e\n    \u003cdiv\u003e\n      \u003cimg src=\"https://github.com/user-attachments/assets/b1f2e876-0954-4dc3-824d-935d29ba8f3f\" width=\"200\" alt=\"Dash0\"\u003e\n    \u003c/div\u003e\n    \u003cdiv\u003e\n      100% OpenTelemetry-native observability platform\u003cbr\u003eSimple to use, built on open standards, and designed for full cost control\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\n# Fiber v2 (current)\ngo get github.com/samber/slog-fiber\n\n# Fiber v3 (beta)\ngo get github.com/samber/slog-fiber@fiber-v3\n```\n\n**Compatibility**: go \u003e= 1.21\n\nNo breaking changes will be made to exported APIs before v2.0.0.\n\n## 💡 Usage\n\n### Handler options\n\n```go\ntype Config struct {\n\tDefaultLevel     slog.Level\n\tClientErrorLevel slog.Level\n\tServerErrorLevel slog.Level\n\n\tWithUserAgent      bool\n\tWithRequestID      bool\n\tWithRequestBody    bool\n\tWithRequestHeader  bool\n\tWithResponseBody   bool\n\tWithResponseHeader bool\n\tWithSpanID         bool\n\tWithTraceID        bool\n\tWithClientIP       bool\n\n\tFilters []Filter\n}\n```\n\nAttributes will be injected in log payload.\n\nOther global parameters:\n\n```go\nslogfiber.TraceIDKey = \"trace_id\"\nslogfiber.SpanIDKey = \"span_id\"\nslogfiber.RequestBodyMaxSize  = 64 * 1024 // 64KB\nslogfiber.ResponseBodyMaxSize = 64 * 1024 // 64KB\nslogfiber.HiddenRequestHeaders = map[string]struct{}{ ... }\nslogfiber.HiddenResponseHeaders = map[string]struct{}{ ... }\nslogfiber.RequestIDHeaderKey = \"X-Request-Id\"\n```\n\n### Minimal\n\n```go\nimport (\n\t\"github.com/gofiber/fiber/v2\"\n\t\"github.com/gofiber/fiber/v2/middleware/recover\"\n\tslogfiber \"github.com/samber/slog-fiber\"\n\t\"log/slog\"\n)\n\n// Create a slog logger, which:\n//   - Logs to stdout.\nlogger := slog.New(slog.NewTextHandler(os.Stdout, nil))\n\napp := fiber.New()\n\napp.Use(slogfiber.New(logger))\napp.Use(recover.New())\n\napp.Get(\"/\", func(c *fiber.Ctx) error {\n\treturn c.SendString(\"Hello, World 👋!\")\n})\n\napp.Listen(\":4242\")\n\n// output:\n// time=2023-10-15T20:32:58.926+02:00 level=INFO msg=\"Incoming request\" env=production request.time=2023-10-15T20:32:58.626+02:00 request.method=GET request.path=/ request.route=\"\" request.ip=127.0.0.1:63932 request.length=0 response.time=2023-10-15T20:32:58.926+02:00 response.latency=100ms response.status=200 response.length=7 id=229c7fc8-64f5-4467-bc4a-940700503b0d\n```\n\n### OTEL\n\n```go\nlogger := slog.New(slog.NewTextHandler(os.Stdout, nil))\n\nconfig := slogfiber.Config{\n\tWithSpanID:  true,\n\tWithTraceID: true,\n}\n\napp := fiber.New()\napp.Use(slogfiber.NewWithConfig(logger, config))\n```\n\n### Custom log levels\n\n```go\nlogger := slog.New(slog.NewTextHandler(os.Stdout, nil))\n\nconfig := slogfiber.Config{\n\tDefaultLevel:     slog.LevelInfo,\n\tClientErrorLevel: slog.LevelWarn,\n\tServerErrorLevel: slog.LevelError,\n}\n\napp := fiber.New()\napp.Use(slogfiber.NewWithConfig(logger, config))\n```\n\n### Verbose\n\n```go\nlogger := slog.New(slog.NewTextHandler(os.Stdout, nil))\n\nconfig := slogfiber.Config{\n\tWithRequestBody: true,\n\tWithResponseBody: true,\n\tWithRequestHeader: true,\n\tWithResponseHeader: true,\n}\n\napp := fiber.New()\napp.Use(slogfiber.NewWithConfig(logger, config))\n```\n\n### Filters\n\n```go\nlogger := slog.New(slog.NewTextHandler(os.Stdout, nil))\n\napp := fiber.New()\napp.Use(\n\tslogfiber.NewWithFilters(\n\t\tlogger,\n\t\tslogfiber.Accept(func (c *fiber.Ctx) bool {\n\t\t\treturn xxx\n\t\t}),\n\t\tslogfiber.IgnoreStatus(401, 404),\n\t),\n)\napp.Use(recover.New())\n```\n\nAvailable filters:\n- Accept / Ignore\n- AcceptMethod / IgnoreMethod\n- AcceptStatus / IgnoreStatus\n- AcceptStatusGreaterThan / IgnoreStatusGreaterThan\n- AcceptStatusLessThan / IgnoreStatusLessThan\n- AcceptStatusGreaterThanOrEqual / IgnoreStatusGreaterThanOrEqual\n- AcceptStatusLessThanOrEqual / IgnoreStatusLessThanOrEqual\n- AcceptPath / IgnorePath\n- AcceptPathContains / IgnorePathContains\n- AcceptPathPrefix / IgnorePathPrefix\n- AcceptPathSuffix / IgnorePathSuffix\n- AcceptPathMatch / IgnorePathMatch\n- AcceptHost / IgnoreHost\n- AcceptHostContains / IgnoreHostContains\n- AcceptHostPrefix / IgnoreHostPrefix\n- AcceptHostSuffix / IgnoreHostSuffix\n- AcceptHostMatch / IgnoreHostMatch\n\n### Using custom time formatters\n\n```go\n// Create a slog logger, which:\n//   - Logs to stdout.\n//   - RFC3339 with UTC time format.\nlogger := slog.New(\n\tslogformatter.NewFormatterHandler(\n\t\tslogformatter.TimezoneConverter(time.UTC),\n\t\tslogformatter.TimeFormatter(time.RFC3339, nil),\n\t)(\n\t\tslog.NewTextHandler(os.Stdout, nil),\n\t),\n)\n\napp := fiber.New()\n\napp.Use(slogfiber.New(logger))\napp.Use(recover.New())\n\napp.Get(\"/\", func(c *fiber.Ctx) error {\n\treturn c.SendString(\"Hello, World 👋!\")\n})\n\napp.Listen(\":4242\")\n\n// output:\n// time=2023-10-15T20:32:58.926+02:00 level=INFO msg=\"Incoming request\" env=production request.time=2023-10-15T20:32:58Z request.method=GET request.path=/ request.route=\"\" request.ip=127.0.0.1:63932 request.length=0 response.time=2023-10-15T20:32:58Z response.latency=100ms response.status=200 response.length=7 id=229c7fc8-64f5-4467-bc4a-940700503b0d\n```\n\n### Using custom logger sub-group\n\n```go\nlogger := slog.New(slog.NewTextHandler(os.Stdout, nil))\n\napp := fiber.New()\n\napp.Use(slogfiber.New(logger.WithGroup(\"http\")))\napp.Use(recover.New())\n\napp.Get(\"/\", func(c *fiber.Ctx) error {\n\treturn c.SendString(\"Hello, World 👋!\")\n})\n\napp.Listen(\":4242\")\n\n// output:\n// time=2023-10-15T20:32:58.926+02:00 level=INFO msg=\"Incoming request\" env=production http.request.time=2023-10-15T20:32:58.626+02:00 http.request.method=GET http.request.path=/ http.request.route=\"\" http.request.ip=127.0.0.1:63932 http.request.length=0 http.response.time=2023-10-15T20:32:58.926+02:00 http.response.latency=100ms http.response.status=200 http.response.length=7 http.id=229c7fc8-64f5-4467-bc4a-940700503b0d\n```\n\n### Add logger to a single route\n\n```go\nlogger := slog.New(slog.NewTextHandler(os.Stdout, nil))\n\napp := fiber.New()\n\napp.Use(recover.New())\n\napp.Get(\"/\", slogfiber.New(logger), func(c *fiber.Ctx) error {\n\treturn c.SendString(\"Hello, World 👋!\")\n})\n\napp.Listen(\":4242\")\n```\n\n### Adding custom attributes\n\n```go\nlogger := slog.New(slog.NewTextHandler(os.Stdout, nil))\n\n// Add an attribute to all log entries made through this logger.\nlogger = logger.With(\"env\", \"production\")\n\napp := fiber.New()\n\napp.Use(slogfiber.New(logger))\napp.Use(recover.New())\n\napp.Get(\"/\", func(c *fiber.Ctx) error {\n\t// Add an attribute to a single log entry.\n\tslogfiber.AddCustomAttributes(c, slog.String(\"foo\", \"bar\"))\n\treturn c.SendString(\"Hello, World 👋!\")\n})\n\napp.Listen(\":4242\")\n\n// output:\n// time=2023-10-15T20:32:58.926+02:00 level=INFO msg=\"Incoming request\" env=production request.time=2023-10-15T20:32:58.626+02:00 request.method=GET request.path=/ request.route=\"\" request.ip=127.0.0.1:63932 request.length=0 response.time=2023-10-15T20:32:58.926+02:00 response.latency=100ms response.status=200 response.length=7 id=229c7fc8-64f5-4467-bc4a-940700503b0d foo=bar\n```\n\n### JSON output\n\n```go\nlogger := slog.New(slog.NewJSONHandler(os.Stdout, nil)),\n\napp := fiber.New()\n\napp.Use(slogfiber.New(logger))\napp.Use(recover.New())\n\napp.Get(\"/\", func(c *fiber.Ctx) error {\n\treturn c.SendString(\"Hello, World 👋!\")\n})\n\napp.Listen(\":4242\")\n\n// output:\n// {\"time\":\"2023-10-15T20:32:58.926+02:00\",\"level\":\"INFO\",\"msg\":\"Incoming request\",\"env\":\"production\",\"http\":{\"request\":{\"time\":\"2023-10-15T20:32:58.626+02:00\",\"method\":\"GET\",\"path\":\"/\",\"route\":\"\",\"ip\":\"127.0.0.1:55296\",\"length\":0},\"response\":{\"time\":\"2023-10-15T20:32:58.926+02:00\",\"latency\":100000,\"status\":200,\"length\":7},\"id\":\"04201917-d7ba-4b20-a3bb-2fffba5f2bd9\"}}\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-fiber)\n- Fix [open issues](https://github.com/samber/slog-fiber/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-fiber)\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamber%2Fslog-fiber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamber%2Fslog-fiber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamber%2Fslog-fiber/lists"}