# README

Access Log Format Logger

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

Usage

Importing

import "github.com/AccelByte/go-restful-plugins/v4/pkg/logger/log"

Log all endpoints

ws := new(restful.WebService)
ws.Filter(log.AccessLog)

Log specific endpoint

ws := new(restful.WebService)
ws.Route(ws.GET("/user/{id}").
    Filter(log.AccessLog).
    To(func(request *restful.Request, response *restful.Response) {
}))

Environment variables

  • FULL_ACCESS_LOG_ENABLED

    Full access log mode will capture request body and response body. 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

  • FULL_ACCESS_LOG_REQUEST_BODY_ENABLED

    Enable capture request body in full access log mode. Default: true

  • FULL_ACCESS_LOG_RESPONSE_BODY_ENABLED

    Enable capture response body in full access log mode. Default: true

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(log.AccessLog).
    Filter(log.Attribute(log.Option{
        MaskedQueryParams: "param1,param2",
        MaskedRequestFields: "field1,field2",
        MaskedResponseFields: "field3,field4",
    })).
    To(func(request *restful.Request, response *restful.Response) {
}))

Manually specify log's field value

We could manually set specific field value via request attribute. Please refer to the table below for attribute name of each field.

FieldDefault ValueAttribute Name
namespaceExtracted from JWT claimslog.NamespaceAttribute
user_idExtracted from JWT claimslog.UserIDAttribute
client_idExtracted from JWT claimslog.ClientIDAttribute

Example:

// ... your service logic
request.SetAttribute(log.NamespaceAttribute, "myNamespace")
request.SetAttribute(log.UserIDAttribute, "myUserId")
request.SetAttribute(log.ClientIDAttribute, "myClientId")
// ... your service logic

# Functions

AccessLog is a filter that will log incoming request into the Access Log format.
Attribute filter is used to define the log attribute for the endpoint.
MaskFields will mask the field value on the content string based on the provided field name(s) in "fields" parameter separated by comma.
MaskQueryParams will mask the field value on the uri based on the provided field name(s) in "fields" parameter separated by comma.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

FieldRegex contains regex patterns for field name in varied content-types.
Option contains attribute options for log functionality.
ResponseWriterInterceptor is used to decorate http.ResponseWriter, so we can intercept the Write process.