https://github.com/hypnoglow/gormzap
GORM (v1) logger implementation using Uber's zap :zap:
https://github.com/hypnoglow/gormzap
golang gorm logging structured-logging zap
Last synced: 12 months ago
JSON representation
GORM (v1) logger implementation using Uber's zap :zap:
- Host: GitHub
- URL: https://github.com/hypnoglow/gormzap
- Owner: hypnoglow
- License: mit
- Created: 2018-04-20T13:38:38.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-14T12:23:54.000Z (over 7 years ago)
- Last Synced: 2025-04-19T15:33:54.250Z (about 1 year ago)
- Topics: golang, gorm, logging, structured-logging, zap
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gormzap
[](https://godoc.org/github.com/hypnoglow/gormzap)
[](https://circleci.com/gh/hypnoglow/gormzap)
[](https://github.com/hypnoglow/gormzap/releases)
[](LICENSE)
[GORM](https://github.com/jinzhu/gorm) logger implementation using [zap](https://github.com/uber-go/zap).
## Usage
```go
var debug bool // shows if we have debug enabled in our app
db, err := gorm.Open("postgres", dsn)
if err != nil {
panic(err)
}
if debug {
// By default, gorm logs only errors. If we set LogMode to true,
// then all queries will be logged.
// WARNING: if you explicitly set this to false, then even
// errors won't be logged.
db.LogMode(true)
}
log := zap.NewExample()
db.SetLogger(gormzap.New(log, gormzap.WithLevel(zap.DebugLevel)))
```