Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gin-melodic/glog
Provides convenient log processing
https://github.com/gin-melodic/glog
Last synced: 15 minutes ago
JSON representation
Provides convenient log processing
- Host: GitHub
- URL: https://github.com/gin-melodic/glog
- Owner: gin-melodic
- License: apache-2.0
- Created: 2021-06-10T06:48:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-27T14:40:17.000Z (about 2 years ago)
- Last Synced: 2024-11-05T21:17:08.859Z (about 2 months ago)
- Language: Go
- Size: 43 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gin-logger
This toolkit provides rotation logging capabilities.
`GLog` contain some useful middleware for:
- [gingonic/gin](https://github.com/gin-gonic/gin)
- [go-gorm/gorm](https://github.com/go-gorm/gorm)# Best Practices
```go
package mainimport (
"github.com/gin-melodic/glog"
"github.com/gin-gonic/gin"
gingonicLogger "github.com/gin-melodic/glog/middleware/gingonic"
gormLogger "github.com/gin-melodic/glog/middleware/gorm"
"github.com/sirupsen/logrus"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)func main() {
// logger init
loggerConfig := &glog.LoggerOptions{
MinAllowLevel: logrus.InfoLevel,
HighPerformance: false,
OutputDir: "./logs",
FilePrefix: "demo-project",
SaveDay: 30,
ExtLoggerWriter: []io.Writer{os.Stdout},
}
// you can reset config here,
// e.g. Disable os.Stdout logger writer in prod.
//if env == 'production' {
// loggerConfig.ExtLoggerWriter = nil
//}
if err := glog.InitGlobalLogger(loggerConfig); err != nil {
panic(err)
}// add gorm middleware
db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{
Logger: gormLogger.New(gormLogger.Options{}),
})
// add gin middleware
router := gin.New()
router.Use(gingonicLogger.InjectLogger(&gingonicLogger.Options{
BodyMaxSize: 500,
}))
}
```# License
Apache-2.0 License