2.3.2.2 Go
Add mxload_go to the application from which you want to retrieve logs.
go get github.com/mxload/mxload_go
go get github.com/gwatts/gin-adapter
Add the following content to the entry point of your application (usually main.go).
Currently supports three frameworks: Gin, go-chi, and echo.
import (
...
+ mxload "github.com/mxload/mxload_go"
)
func main() {
r := gin.Default()
+ r.Use(adapter.Wrap(mxload.MiddlewareFunc(
+ &mxload.MxloadConfig{
+ Enabled: true,
+ CollectorURL: "https://lambda-public.mxload.mx/put-request-log",
+ ProjectID: YOUR_PROJECT_ID,
+ ServiceKey: "YOUR_SERVICE_KEY",
+ CustomHeaders: []string{
+ "Authorization",
+ },
+ IgnorePaths: []string{
+ "/ignored",
+ },
+ },
+ )))
...
}
import (
...
+ mxload "github.com/mxload/mxload_go"
)
func main() {
r := chi.NewRouter()
+ r.Use(mxload.MiddlewareFunc(
+ &mxload.MxloadConfig{
+ Enabled: true,
+ CollectorURL: "https://lambda-public.mxload.mx/put-request-log",
+ ProjectID: YOUR_PROJECT_ID,
+ ServiceKey: "YOUR_SERVICE_KEY",
+ CustomHeaders: []string{
+ "Authorization",
+ },
+ IgnorePaths: []string{
+ "/ignored",
+ },
+ },
+ ))
....
}
import (
...
+ mxload "github.com/mxload/mxload_go"
)
func main() {
e := echo.New()
+ e.Use(echo.WrapMiddleware(mxload.MiddlewareFunc(
+ &mxload.MxloadConfig{
+ Enabled: true,
+ CollectorURL: "https://lambda-public.mxload.mx/put-request-log",
+ ProjectID: YOUR_PROJECT_ID,
+ ServiceKey: "YOUR_SERVICE_KEY",
+ CustomHeaders: []string{
+ "Authorization",
+ },
+ IgnorePaths: []string{
+ "/ignored",
+ },
+ },
+ )))
...
}
The main configuration parameters are as follows:
Enabled- Enables/disables logging. Default is
false.
- Enables/disables logging. Default is
collector_url- URL of mxload to receive logs. Specify
https://lambda-public.mxload.mx/put-request-log.
- URL of mxload to receive logs. Specify
ProjectID- Set the id of the created project.
project_idcan be confirmed from the home or project details.
- Set the id of the created project.
ServiceKey- Set the service key created in # Creating a Service Key.
CustomHeaders(optional)- Required for recording header contents.
- For example, if you want to include
"Content-Type": "application/json", addContent-Typeto theCustomHeadersvalue.
IgnorePaths(optional)- If the request path is within
IgnorePaths, the sending of request logs is ignored. - Set this when you want to disable paths such as
/healthfor health checks.
- If the request path is within
The log parameters sent to Mx.Load are as follows:
- Method
- Request path
- Request body
- Query parameters
- Request header
- Cookies