https://github.com/wantedly/gorm-zap
Alternative logging with zap for GORM ⚡️
https://github.com/wantedly/gorm-zap
golang gorm logging orm structured-logging zap
Last synced: 11 months ago
JSON representation
Alternative logging with zap for GORM ⚡️
- Host: GitHub
- URL: https://github.com/wantedly/gorm-zap
- Owner: wantedly
- License: mit
- Created: 2017-09-24T04:21:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T17:58:11.000Z (over 2 years ago)
- Last Synced: 2025-07-22T03:08:15.918Z (11 months ago)
- Topics: golang, gorm, logging, orm, structured-logging, zap
- Language: Go
- Size: 18.6 KB
- Stars: 30
- Watchers: 79
- Forks: 23
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gormzap
[](https://travis-ci.org/wantedly/gorm-zap)
[](https://codecov.io/gh/wantedly/gorm-zap)
[](https://godoc.org/github.com/wantedly/gorm-zap)
[](./LICENSE)
Alternative logging with [zap](https://github.com/uber-go/zap) for [GORM](http://jinzhu.me/gorm) ⚡️
In comparison to gorm's default logger, `gormzap` is faster, reflection free, low allocations and no regex compilations.
## Example
```go
package main
import (
"github.com/jinzhu/gorm"
"github.com/wantedly/gorm-zap"
)
const (
databaseURL = "postgres://postgres:@localhost/gormzap?sslmode=disable"
)
func main() {
logger, err = zap.NewProduction()
if err != nil {
panic(err)
}
db, err := gorm.Open("postgres", databaseURL)
if err != nil {
panic(err)
}
db.LogMode(true)
db.SetLogger(gormzap.New(logger))
// ...
}
```
## Performance
According to our benchmark, `gormzap` makes DB operations at least 5% faster and reduce object allocations.
### Simple insert query
| Logger | Time | Object Allocated |
| :--- | :---: | :---: |
| default | 187940 ns/op | 494 allocs/op |
| gormzap | 185383 ns/op | 475 allocs/op |
### Simple select query
| Logger | Time | Object Allocated |
| :--- | :---: | :---: |
| default | 169361 ns/op | 531 allocs/op |
| gormzap | 151304 ns/op | 519 allocs/op |
### Simple select query with 10 placeholders
| Logger | Time | Object Allocated |
| :--- | :---: | :---: |
| default | 200632 ns/op | 720 allocs/op |
| gormzap | 190732 ns/op | 645 allocs/op |
### Simple select query with 100 placeholders
| Logger | Time | Object Allocated |
| :--- | :---: | :---: |
| default | 444513 ns/op | 1723 allocs/op |
| gormzap | 263098 ns/op | 1101 allocs/op |