Documentation
¶
Index ¶
- Constants
- Variables
- func AccessLog(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)
- func Attribute(option Option) restful.FilterFunction
- func MaskFields(contentType, content, fields string) string
- func MaskPIIFields(contentType, content, fields string) string
- func MaskPIIQueryParams(uri string, fields string) string
- func MaskQueryParams(uri string, fields string) string
- type FieldRegex
- type Option
- type ResponseWriterInterceptor
- func (w *ResponseWriterInterceptor) Flush()
- func (w *ResponseWriterInterceptor) FlushError() error
- func (w *ResponseWriterInterceptor) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (w *ResponseWriterInterceptor) Unwrap() http.ResponseWriter
- func (w *ResponseWriterInterceptor) Write(b []byte) (int, error)
- func (w *ResponseWriterInterceptor) WriteHeader(statusCode int)
Constants ¶
const ( MaskedQueryParamsAttribute = "MaskedQueryParams" MaskedRequestFieldsAttribute = "MaskedRequestFields" MaskedResponseFieldsAttribute = "MaskedResponseFields" MaskedPIIQueryParamsAttribute = "MaskedPIIQueryParams" MaskedPIIRequestFieldsAttribute = "MaskedPIIRequestFields" MaskedPIIResponseFieldsAttribute = "MaskedPIIResponseFields" UserIDAttribute = "LogUserId" ClientIDAttribute = "LogClientId" NamespaceAttribute = "LogNamespace" )
const (
MaskedValue = "******"
)
Variables ¶
var ( FullAccessLogEnabled bool FullAccessLogSupportedContentTypes []string FullAccessLogMaxBodySize int FullAccessLogRequestBodyEnabled bool FullAccessLogResponseBodyEnabled bool )
var FieldRegexCache = sync.Map{}
Functions ¶
func AccessLog ¶ added in v4.10.0
AccessLog is a filter that will log incoming request into the Access Log format
func Attribute ¶
func Attribute(option Option) restful.FilterFunction
Attribute filter is used to define the log attribute for the endpoint.
func MaskFields ¶
MaskFields will mask the field value on the content string based on the provided field name(s) in "fields" parameter separated by comma.
func MaskPIIFields ¶ added in v4.24.0
MaskPIIFields will mask the last n chars of field value on the content string based on the provided field name(s) in "fields" parameter separated by comma.
func MaskPIIQueryParams ¶ added in v4.24.0
MaskPIIQueryParams will mask the last n chars of field value on the uri based on the provided field name(s) in "fields" parameter separated by comma.
func MaskQueryParams ¶
MaskQueryParams will mask the field value on the uri based on the provided field name(s) in "fields" parameter separated by comma.
Types ¶
type FieldRegex ¶
type FieldRegex struct {
FieldName string
JsonPattern *regexp.Regexp
QueryStringPattern *regexp.Regexp
}
FieldRegex contains regex patterns for field name in varied content-types.
func (*FieldRegex) InitFieldRegex ¶
func (f *FieldRegex) InitFieldRegex(fieldName string)
InitFieldRegex initialize the FieldRegex along with its regex patterns.
type Option ¶
type Option struct {
// Query param that need to masked in url, separated with comma
MaskedQueryParams string
// Field that need to masked in request body, separated with comma
MaskedRequestFields string
// Field that need to masked in response body, separated with comma
MaskedResponseFields string
// PII Query param that need to be masked in url, separated with comma
MaskedPIIQueryParams string
// PII Field that need to be masked in request body, separated with comma
MaskedPIIRequestFields string
// PII Field that need to be masked in response body, separated with comma
MaskedPIIResponseFields string
}
Option contains attribute options for log functionality
type ResponseWriterInterceptor ¶ added in v4.10.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. One that AccessLog created also sets the X-Trace-Id response header. Like the http.ResponseWriter it wraps, it is not safe for concurrent use.
func (*ResponseWriterInterceptor) Flush ¶ added in v4.29.0
func (w *ResponseWriterInterceptor) Flush()
Flush sends the data written so far to the client, when a writer underneath can. It makes the interceptor an http.Flusher, so streaming responses, such as server-sent events, still flush behind AccessLog.
func (*ResponseWriterInterceptor) FlushError ¶ added in v4.29.0
func (w *ResponseWriterInterceptor) FlushError() error
FlushError is Flush that reports the error, for http.ResponseController. It is passed down through the wrapped writers by http.ResponseController, and is http.ErrNotSupported when none of them can flush.
func (*ResponseWriterInterceptor) Hijack ¶ added in v4.29.0
func (w *ResponseWriterInterceptor) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack hands the connection over to the handler, e.g. for a WebSocket upgrade, when a writer underneath can. It makes the interceptor an http.Hijacker, is passed down through the wrapped writers, and is http.ErrNotSupported when none of them can hijack. Bytes written to a hijacked connection don't reach the access log.
func (*ResponseWriterInterceptor) Unwrap ¶ added in v4.29.0
func (w *ResponseWriterInterceptor) Unwrap() http.ResponseWriter
Unwrap returns the wrapped writer, so that http.ResponseController can reach its other features.
func (*ResponseWriterInterceptor) Write ¶ added in v4.10.0
func (w *ResponseWriterInterceptor) Write(b []byte) (int, error)
func (*ResponseWriterInterceptor) WriteHeader ¶ added in v4.29.0
func (w *ResponseWriterInterceptor) WriteHeader(statusCode int)
WriteHeader sets the X-Trace-Id header, then writes the status code.