{"id":34163523,"url":"https://github.com/serialt/slogorm","last_synced_at":"2026-03-11T11:06:41.277Z","repository":{"id":209486714,"uuid":"724193225","full_name":"serialt/slogorm","owner":"serialt","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-28T11:04:09.000Z","size":28,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-18T04:24:03.351Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serialt.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":"2023-11-27T15:28:00.000Z","updated_at":"2023-11-27T15:33:54.000Z","dependencies_parsed_at":"2024-06-21T17:49:09.957Z","dependency_job_id":"1915baf3-c6ab-4bbb-b2fa-8bb3b75b3b02","html_url":"https://github.com/serialt/slogorm","commit_stats":null,"previous_names":["serialt/slogorm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/serialt/slogorm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fslogorm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fslogorm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fslogorm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fslogorm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serialt","download_url":"https://codeload.github.com/serialt/slogorm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fslogorm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30379265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-11T06:09:32.197Z","status":"ssl_error","status_checked_at":"2026-03-11T06:09:17.086Z","response_time":84,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":"2025-12-15T09:17:31.295Z","updated_at":"2026-03-11T11:06:41.266Z","avatar_url":"https://github.com/serialt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slog-gorm\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/orandin/slog-gorm.svg)](https://pkg.go.dev/github.com/orandin/slog-gorm)\n![Go Version](https://img.shields.io/badge/Go-%3E%3D%201.21-%23007d9c)\n[![CI](https://github.com/orandin/slog-gorm/actions/workflows/ci.yaml/badge.svg)](https://github.com/orandin/slog-gorm/actions/workflows/ci.yaml)\n[![Go report](https://goreportcard.com/badge/github.com/orandin/slog-gorm)](https://goreportcard.com/report/github.com/orandin/slog-gorm)\n[![Coverage](https://img.shields.io/codecov/c/github/orandin/slog-gorm)](https://codecov.io/gh/orandin/slog-gorm)\n[![Renovate](https://img.shields.io/badge/dependabot-enabled-brightgreen.svg)](https://docs.github.com/en/code-security/dependabot/working-with-dependabot)\n[![License](https://img.shields.io/github/license/orandin/slog-gorm)](./LICENSE)\n\n`slog-gorm` provides a slog adapter, highly configurable, for [gorm logger](https://gorm.io/docs/logger.html)\nto have homogeneous logs between your application / script and gorm.\n\n## Key features\n\n- compatible with any `slog.Handler`, which allows you to keep control on\n  the format of your logs.\n- can define a threshold to identify and log the slow queries.\n- can log all SQL messages or just the errors if you prefer.\n- can define a custom `slog.Level` for errors, slow queries or the other logs.\n\n\n## Requirement\n\n- `golang \u003e= 1.21`\n\n## Usage\n\n```golang\nimport (\n    \"log/slog\"\n    \"os\"\n\n    \"gorm.io/driver/sqlite\"\n    \"gorm.io/gorm\"\n\n    slogGorm \"github.com/orandin/slog-gorm\"\n)\n\n// Create an slog-gorm instance\ngormLogger := slogGorm.New() // use slog.Default() by default\n\n\n// GORM: Globally mode\ndb, err := gorm.Open(sqlite.Open(\"test.db\"), \u0026gorm.Config{\n    Logger: gormLogger,\n})\n\n// GORM: Continuous session mode\ntx := db.Session(\u0026Session{Logger: gormLogger})\ntx.First(\u0026user)\ntx.Model(\u0026user).Update(\"Age\", 18)\n```\n\n### With your `slog.Logger`\n\nThe following example shows you how to use a specific `slog.Logger` with `slog-gorm`:\n\n```golang\n// With your slog.Logger\nlogger := slog.New(slog.NewJSONHandler(os.Stdout, nil))\n\n// Also, you can set specific attributes to distinguish between your application logs and gorm logs\n// logger = logger.With(slog.String(\"log_type\", \"database\"))\n\ngormLogger := slogGorm.New(\n    slogGorm.WithLogger(logger), // Optional, use slog.Default() by default\n    slogGorm.WithTraceAll(), // trace all messages \n    slogGorm.SetLogLevel(DefaultLogType, slog.Level(32)), // Define the default logging level\n)\n```\n\n### Use your custom `slog.Level`\n\nAs some loggers *(e.g. syslog)* have their own logging levels, `slog-gorm` lets you\nuse them to ensure the consistency of your logs and make them easier to understand.\n\nYou can set the logging level for these log types:\n\n| Type                        | Description                          | Default           |\n|-----------------------------|--------------------------------------|-------------------|\n| `slogGorm.ErrorLogType`     | For SQL errors                       | `slog.LevelError` |\n| `slogGorm.SlowQueryLogType` | For slow queries                     | `slog.LevelWarn`  |\n| `slogGorm.DefaultLogType`   | For other messages *(default level)* | `slog.LevelInfo`  |\n\nExample:\n\n```golang\nconst (\n    LOG_EMERG   = slog.Level(0)\n    // ...\n    LOG_ERR     = slog.Level(3)\n    LOG_WARNING = slog.Level(4)\n    LOG_NOTICE  = slog.Level(5)\n    // ...\n    LOG_DEBUG   = slog.Level(7)\n)\n\nlogger := slog.New(syslogHandler)\n\ngormLogger := slogGorm.New(\n    slogGorm.WithLogger(logger),\n\n    // Set logging level for SQL errors\n    slogGorm.SetLogLevel(slogGorm.ErrorLogType, LOG_ERR)\n\n    // Set logging level for slow queries\n    slogGorm.SetLogLevel(slogGorm.SlowQueryLogType, LOG_NOTICE)\n\n    // Set logging level for other messages (default level)\n    slogGorm.SetLogLevel(slogGorm.DefaultLogType, LOG_DEBUG)\n)\n```\n\n### Other options\n\n```golang\ncustomLogger := sloggorm.New(\n\tslogGorm.WithSlowThreshold(500 * time.Millisecond), // to identify slow queries\n\n\tslogGorm.WithRecordNotFoundError(), // don't ignore not found errors\n\n\tslogGorm.WithSourceField(\"origin\"), // instead of \"file\" (by default)\n\n\tslogGorm.WithErrorField(\"err\"),     // instead of \"error\" (by default)\n)\n```\n\nBy default, the slow queries and SQL errors are logged, but you can ignore all SQL messages with `WithIgnoreTrace()`.\n\n```\ncustomLogger := sloggorm.New(\n    slogGorm.WithIgnoreTrace(), // disable the tracing of SQL queries by the logger.\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserialt%2Fslogorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserialt%2Fslogorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserialt%2Fslogorm/lists"}