common

package
v4.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

README

Common Log Format Logger

This package enables logging in go-restful apps.

Usage

Importing
import "github.com/AccelByte/go-restful-plugins/pkg/logger/common"
Log all endpoints
ws := new(restful.WebService)
ws.Filter(common.Log)
Log specific endpoint
ws := new(restful.WebService)
ws.Route(ws.GET("/user/{id}").
    Filter(common.Log).
    To(func(request *restful.Request, response *restful.Response) {
}))
Full access log mode

Full access log mode is used to view the full body detail of all request and response in the endpoints.

Environment variables
  • FULL_ACCESS_LOG_ENABLED

    Enable full access log mode. Default: false

  • FULL_ACCESS_LOG_SUPPORTED_CONTENT_TYPES

    Supported content types to shown in request_body and response_body log. Default: application/json,application/xml,application/x-www-form-urlencoded,text/plain,text/html

  • FULL_ACCESS_LOG_MAX_BODY_SIZE

    Maximum size of request body or response body that will be processed, will be ignored if exceed more than it. Default: 10240 bytes

Filter sensitive field(s) in request body or response body

Some endpoint might have sensitive field value in its query params, request body or response body. For security reason, those sensitive field value should be masked before it printed as a log.

The log.Attribute filter can be used to define the field(s) that need to be masked.

ws := new(restful.WebService)
ws.Route(ws.GET("/user/{id}").
    Filter(common.Log).
    Filter(log.Attribute(log.Option{
        MaskedQueryParams: "param1,param2",
        MaskedRequestFields: "field1,field2",
        MaskedResponseFields: "field3,field4",
    })).
    To(func(request *restful.Request, response *restful.Response) {
}))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FullAccessLogEnabled               bool
	FullAccessLogSupportedContentTypes []string
	FullAccessLogMaxBodySize           int
)

Functions

func Log

func Log(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

Log is a filter that will log incoming request into the defined Log format

Types

type ResponseWriterInterceptor added in v4.4.0

type ResponseWriterInterceptor struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseWriterInterceptor is used to decorate http.ResponseWriter, so we can intercept the Write process

func (*ResponseWriterInterceptor) Write added in v4.4.0

func (w *ResponseWriterInterceptor) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL