{"id":43948271,"url":"https://github.com/sol1/gormzerolog","last_synced_at":"2026-02-07T03:07:55.688Z","repository":{"id":57630717,"uuid":"304155942","full_name":"sol1/gormzerolog","owner":"sol1","description":null,"archived":false,"fork":false,"pushed_at":"2020-10-14T23:54:35.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-06-20T01:58:17.394Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sol1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-14T23:05:35.000Z","updated_at":"2020-10-15T00:00:44.000Z","dependencies_parsed_at":"2022-09-26T20:11:30.704Z","dependency_job_id":null,"html_url":"https://github.com/sol1/gormzerolog","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sol1/gormzerolog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sol1%2Fgormzerolog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sol1%2Fgormzerolog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sol1%2Fgormzerolog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sol1%2Fgormzerolog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sol1","download_url":"https://codeload.github.com/sol1/gormzerolog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sol1%2Fgormzerolog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29185144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T00:44:15.062Z","status":"online","status_checked_at":"2026-02-07T02:00:07.217Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2026-02-07T03:07:55.633Z","updated_at":"2026-02-07T03:07:55.684Z","avatar_url":"https://github.com/sol1.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Do you use [Zerolog](https://github.com/rs/zerolog)?  Do you use [GORM](https://gorm.io)?\nWould you like your GORM logs to go through Zerolog?  Then this package is for you!\n\nLoosely based on [the package of (nearly) the same\nname](https://github.com/Ahmet-Kaplan/gorm-zerolog) by\n[Ahmet-Kaplan](https://github.com/Ahmet-Kaplan), but wildly incompatible due to\nchanges in GORM, and philosophical differences.\n\n\n# Usage\n\nTo use `gormzerolog` in your GORM database instance, you need to do two things.\nFirstly, point the GORM config's `Logger` field at an instance of `gormzerolog.Logger`:\n\n```go\ndb, err := gorm.Open(..., \u0026gorm.Config{Logger: gormzerolog.Logger{}})\n```\n\nThis will tell GORM to use gormzerolog for all (well, *almost*[^1] all...) of its logging\nneeds.  However, by default this will log to a \"null\" zerolog that doesn't do anything.\nIn order to actually generate logs, a configured zerolog logger needs to be put into the\ndatabase's context:\n\n```go\nlogger := zerolog.New(os.Stderr).With().Timestamp().Logger()\n\ndb = db.WithContext(logger.WithContext(context.Background()))\n```\n\nThen, whatever the GORM DB instance wants to log, will go through zerolog.\n\n\n## Example\n\n```go\npackage main\n\nimport (\n\t\"github.com/sol1/gormzerolog\"\n\n  \"context\"\n  \"os\"\n\n  \"github.com/rs/zerolog\"\n\t\"gorm.io/gorm\"\n\t\"gorm.io/driver/sqlite\"\n)\n\ntype User struct {\n  gorm.Model\n\n  Name  string\n}\n\nfunc main() {\n\tdb, err := gorm.Open(sqlite.Open(\":memory:\"), \u0026gorm.Config{Logger: gormzerolog.Logger{}})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n  logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger().Level(zerolog.TraceLevel)\n  db = db.WithContext(logger.WithContext(context.Background()))\n\n  db.AutoMigrate(\u0026User{})\n\n  db.Save(\u0026User{Name: \"Charlie\"})\n}\n```\n\n\n# Contributing\n\nPlease see [CONTRIBUTING.md](CONTRIBUTING.md).\n\n\n# Licence\n\nUnless otherwise stated, everything in this repo is covered by the following\ncopyright notice:\n\n    Copyright (C) 2020  Sol1 Pty Ltd\n\n    This program is free software: you can redistribute it and/or modify it\n    under the terms of the GNU General Public License version 3, as\n    published by the Free Software Foundation.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n\n-----\n\n[^1]: for some unfathomable reason, certain internal errors in GORM still\n  go through the built-in logger.  Presumably someone just referred to the\n  wrong variable somewhere.  In normal use, you'll never see it, so just\n  pretend it doesn't happen.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsol1%2Fgormzerolog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsol1%2Fgormzerolog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsol1%2Fgormzerolog/lists"}