Request Logger service
This service is used for logging all upcoming and outgoing requests
Register the service into your main.go
file:
registry.ServiceProviderRequestLogger()
and you should register the entity RequestLoggerEntity
into the ORM
Access the service:
service.DI().RequestLogger()
The functions this service provide are:
LogRequest(ormService *beeorm.Engine, appName, url string, request *http.Request, contentType string) *entity.RequestLoggerEntity
LogResponse(ormService *beeorm.Engine, requestLoggerEntity *entity.RequestLoggerEntity, responseBody []byte, status int)
2
They can be used to log any outgoing requests you send
Also you are able to enable middleware which will log all incoming requests
middleware.RequestLogger(ginEngine, func(context *gin.Context, requestEntity *entity.RequestLoggerEntity) {
userService := ioc.GetUserService()
session, hasSession := userService.GetSession(context.Request.Context())
if hasSession && session.User != nil {
requestEntity.UserID = session.User.ID
}
})
2
3
4
5
6
7
8
The second parameter (anonymous function) is called extender
and it is used to save extra param to request_logger
table like logged user id
If you want to use this middleware
please do not forget to register the entity RequestLoggerEntity
We created a Cleaner
that will remove all rows in request_logger
table older than 30 days by default. This will prevent your database to be fulfilled with logs If you want to change ttl to other value you can do it from your config file like on the example bellow:
request_logger:
ttl_in_days: 5
2
To enable it please put this code into your single-instance-cron
b := &hitrix.BackgroundProcessor{Server: s}
b.RunAsyncRequestLoggerCleaner()
2
Using our Dev Panel you will be able easily to see all requests and search trough them