Documentation ¶
Index ¶
- type HTTPRequestProperties
- type HTTPResponse
- type Log
- func (l *Log) AddContext(fieldName string, value interface{}) error
- func (l *Log) Debug(message string)
- func (l *Log) DebugWithDetails(message string, details logutils.Fields)
- func (l *Log) Debugf(format string, args ...interface{})
- func (l *Log) Error(message string)
- func (l *Log) ErrorWithDetails(message string, details logutils.Fields)
- func (l *Log) Errorf(format string, args ...interface{})
- func (l *Log) GetContext(fieldName string) interface{}
- func (l *Log) HTTPResponseError(message string, err error, code int, showDetails bool) HTTPResponse
- func (l *Log) HTTPResponseErrorAction(action logutils.MessageActionType, dataType logutils.MessageDataType, ...) HTTPResponse
- func (l *Log) HTTPResponseErrorData(status logutils.MessageDataStatus, dataType logutils.MessageDataType, ...) HTTPResponse
- func (l *Log) HTTPResponseSuccess() HTTPResponse
- func (l *Log) HTTPResponseSuccessAction(action logutils.MessageActionType, dataType logutils.MessageDataType, ...) HTTPResponse
- func (l *Log) HTTPResponseSuccessBytes(bytes []byte, contentType string) HTTPResponse
- func (l *Log) HTTPResponseSuccessJSON(json []byte) HTTPResponse
- func (l *Log) HTTPResponseSuccessMessage(message string) HTTPResponse
- func (l *Log) HTTPResponseSuccessStatusAction(action logutils.MessageActionType, dataType logutils.MessageDataType, ...) HTTPResponse
- func (l *Log) HTTPResponseSuccessStatusBytes(bytes []byte, contentType string, code int) HTTPResponse
- func (l *Log) HTTPResponseSuccessStatusJSON(json []byte, code int) HTTPResponse
- func (l *Log) HTTPResponseSuccessStatusMessage(message string, code int) HTTPResponse
- func (l *Log) Info(message string)
- func (l *Log) InfoWithDetails(message string, details logutils.Fields)
- func (l *Log) Infof(format string, args ...interface{})
- func (l *Log) LogError(message string, err error) string
- func (l *Log) LogMessage(level LogLevel, message string) string
- func (l *Log) RequestComplete()
- func (l *Log) RequestReceived()
- func (l *Log) SendHTTPResponse(w http.ResponseWriter, response HTTPResponse)
- func (l *Log) SetContext(fieldName string, value interface{})
- func (l *Log) SetRequestHeaders(r *http.Request)
- func (l *Log) SetResponseHeaders(r *HTTPResponse)
- func (l *Log) SpanID() string
- func (l *Log) TraceID() string
- func (l *Log) Warn(message string)
- func (l *Log) WarnError(message string, err error) string
- func (l *Log) WarnWithDetails(message string, details logutils.Fields)
- func (l *Log) Warnf(format string, args ...interface{})
- type LogLevel
- type Logger
- func (l *Logger) Debug(message string)
- func (l *Logger) DebugWithFields(message string, fields logutils.Fields)
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(message string)
- func (l *Logger) ErrorWithFields(message string, fields logutils.Fields)
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(message string)
- func (l *Logger) Fatalf(message string, args ...interface{})
- func (l *Logger) Info(message string)
- func (l *Logger) InfoWithFields(message string, fields logutils.Fields)
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) NewLog(traceID string, request RequestContext) *Log
- func (l *Logger) NewRequestLog(r *http.Request) *Log
- func (l *Logger) SetLevel(level LogLevel)
- func (l *Logger) Warn(message string)
- func (l *Logger) WarnWithFields(message string, fields logutils.Fields)
- func (l *Logger) Warnf(format string, args ...interface{})
- type LoggerOpts
- type RequestContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPRequestProperties ¶
type HTTPRequestProperties struct { Method string Path string RemoteAddr string UserAgent string UseRegex bool // If true, interprets all properties as regex. Otherwise matches on equality }
HTTPRequestProperties is an entity which contains the properties of an HTTP request
func NewAwsHealthCheckHTTPRequestProperties ¶
func NewAwsHealthCheckHTTPRequestProperties(path string) HTTPRequestProperties
NewAwsHealthCheckHTTPRequestProperties creates an HTTPRequestProperties object for a standard AWS ELB health checker
Path: The path that the health checks are performed on. If empty, "/version" is used as the default value.
func NewOpenShiftHealthCheckHTTPRequestProperties ¶
func NewOpenShiftHealthCheckHTTPRequestProperties(path string) HTTPRequestProperties
NewOpenShiftHealthCheckHTTPRequestProperties creates an HTTPRequestProperties object for a standard OpenShift health checker
Path: The path that the health checks are performed on. If empty, "/version" is used as the default value.
func NewStandardHealthCheckHTTPRequestProperties ¶
func NewStandardHealthCheckHTTPRequestProperties(path string) []HTTPRequestProperties
NewStandardHealthCheckHTTPRequestProperties creates a list of HTTPRequestProperties objects for known standard health checkers
Path: The path that the health checks are performed on. If empty, "/version" is used as the default value.
func (HTTPRequestProperties) Match ¶
func (h HTTPRequestProperties) Match(r *http.Request) bool
Match returns true if the provided http.Request matches the defined request properties
func (HTTPRequestProperties) MatchEquality ¶
func (h HTTPRequestProperties) MatchEquality(r *http.Request) bool
MatchEquality returns true if the provided http.Request matches the defined request properties by equality
func (HTTPRequestProperties) MatchRegex ¶
func (h HTTPRequestProperties) MatchRegex(r *http.Request) bool
MatchRegex returns true if the provided http.Request matches the defined request properties by regex
type HTTPResponse ¶
type HTTPResponse struct { ResponseCode int Headers map[string][]string Body []byte Cookies []http.Cookie }
HTTPResponse is an entity which contains the data to be sent in an HTTP response
func NewErrorHTTPResponse ¶
func NewErrorHTTPResponse(body string, code int) HTTPResponse
NewErrorHTTPResponse generates an HTTPResponse with the correct headers for an error string
func NewHTTPResponse ¶
func NewHTTPResponse(body []byte, headers map[string]string, code int) HTTPResponse
NewHTTPResponse generates an HTTPResponse with the provided data
func NewJSONErrorHTTPResponse ¶
func NewJSONErrorHTTPResponse(body string, code int) HTTPResponse
NewJSONErrorHTTPResponse generates an HTTPResponse with the correct headers for a JSON encoded error
func (*HTTPResponse) SetCookie ¶
func (h *HTTPResponse) SetCookie(cookie http.Cookie)
SetCookie appends the given cookie to the list of cookies in the response
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log struct defines a log object of a request
func (*Log) AddContext ¶
AddContext adds any relevant unstructured data to context map If the provided key already exists in the context, an error is returned
func (*Log) DebugWithDetails ¶
DebugWithDetails prints the log at debug level with given fields and message
func (*Log) Error ¶
Error prints the log at error level with given message Note: If possible, use LogError() instead
func (*Log) ErrorWithDetails ¶
ErrorWithDetails prints the log at error level with given details and message
func (*Log) Errorf ¶
Errorf prints the log at error level with given formatted string Note: If possible, use LogError() instead
func (*Log) GetContext ¶
GetContext gets the provided context key
func (*Log) HTTPResponseError ¶
HTTPResponseError logs the provided message and error and generates an HttpResponse
Params: message: The error message err: The error received from the application code: The HTTP response code to be set showDetails: Only provide 'message' not 'err' in HTTP response when false
func (*Log) HTTPResponseErrorAction ¶
func (l *Log) HTTPResponseErrorAction(action logutils.MessageActionType, dataType logutils.MessageDataType, args logutils.MessageArgs, err error, code int, showDetails bool) HTTPResponse
HTTPResponseErrorAction logs an action message and error and generates an HttpResponse
action: The action that is occurring dataType: The data type args: Any args that should be included in the message (nil if none) err: The error received from the application code: The HTTP response code to be set showDetails: Only generated message not 'err' in HTTP response when false
func (*Log) HTTPResponseErrorData ¶
func (l *Log) HTTPResponseErrorData(status logutils.MessageDataStatus, dataType logutils.MessageDataType, args logutils.MessageArgs, err error, code int, showDetails bool) HTTPResponse
HTTPResponseErrorData logs a data message and error and generates an HttpResponse
status: The status of the data dataType: The data type args: Any args that should be included in the message (nil if none) err: The error received from the application code: The HTTP response code to be set showDetails: Only provide 'msg' not 'err' in HTTP response when false
func (*Log) HTTPResponseSuccess ¶
func (l *Log) HTTPResponseSuccess() HTTPResponse
HTTPResponseSuccess generates an HttpResponse with the message "Success" with status code 200, sets standard headers, and stores the status to the log context
func (*Log) HTTPResponseSuccessAction ¶
func (l *Log) HTTPResponseSuccessAction(action logutils.MessageActionType, dataType logutils.MessageDataType, args logutils.MessageArgs) HTTPResponse
HTTPResponseSuccessAction generates an HttpResponse with the provided success action message with status code 200, sets standard headers, and stores the message to the log context
Params: action: The action that is occurring dataType: The data type that the action is occurring on args: Any args that should be included in the message (nil if none)
func (*Log) HTTPResponseSuccessBytes ¶
func (l *Log) HTTPResponseSuccessBytes(bytes []byte, contentType string) HTTPResponse
HTTPResponseSuccessBytes generates an HttpResponse with the provided bytes as the HTTP response body with status code 200, sets standard headers, and stores the status to the log context
Params: bytes: Response data contentType: Content type header string
func (*Log) HTTPResponseSuccessJSON ¶
func (l *Log) HTTPResponseSuccessJSON(json []byte) HTTPResponse
HTTPResponseSuccessJSON generates an HttpResponse with the provided JSON as the HTTP response body with status code 200, sets standard headers, and stores the status to the log context
Params: json: JSON encoded response data
func (*Log) HTTPResponseSuccessMessage ¶
func (l *Log) HTTPResponseSuccessMessage(message string) HTTPResponse
HTTPResponseSuccessMessage generates an HttpResponse with the provided success message with status code 200, sets standard headers, and stores the message and status to the log context
Params: msg: The success message
func (*Log) HTTPResponseSuccessStatusAction ¶
func (l *Log) HTTPResponseSuccessStatusAction(action logutils.MessageActionType, dataType logutils.MessageDataType, args logutils.MessageArgs, code int) HTTPResponse
HTTPResponseSuccessStatusAction generates an HttpResponse with the provided success action message and status code, sets standard headers, and stores the message to the log context
Params: action: The action that is occurring dataType: The data type that the action is occurring on args: Any args that should be included in the message (nil if none) code: The HTTP response code to be set
func (*Log) HTTPResponseSuccessStatusBytes ¶
func (l *Log) HTTPResponseSuccessStatusBytes(bytes []byte, contentType string, code int) HTTPResponse
HTTPResponseSuccessStatusBytes generates an HttpResponse with the provided bytes as the HTTP response body and status code, sets standard headers, and stores the status to the log context
Params: bytes: Response data contentType: Content type header string code: The HTTP response code to be set
func (*Log) HTTPResponseSuccessStatusJSON ¶
func (l *Log) HTTPResponseSuccessStatusJSON(json []byte, code int) HTTPResponse
HTTPResponseSuccessStatusJSON generates an HttpResponse with the provided JSON as the HTTP response body and status code, sets standard headers, and stores the status to the log context
Params: json: JSON encoded response data code: The HTTP response code to be set
func (*Log) HTTPResponseSuccessStatusMessage ¶
func (l *Log) HTTPResponseSuccessStatusMessage(message string, code int) HTTPResponse
HTTPResponseSuccessStatusMessage generates an HttpResponse with the provided success message and status code, sets standard headers, and stores the message and status to the log context
Params: msg: The success message code: The HTTP response code to be set
func (*Log) InfoWithDetails ¶
InfoWithDetails prints the log at info level with given fields and message
func (*Log) LogError ¶
LogError prints the log at error level with given message and error
Returns combined error message as string
func (*Log) LogMessage ¶
LogMessage logs and returns a Message at the designated level
level: The log level (Info, Debug, Warn, Error) message: The message to log
func (*Log) RequestComplete ¶
func (l *Log) RequestComplete()
RequestComplete prints the context of a log object
func (*Log) RequestReceived ¶
func (l *Log) RequestReceived()
RequestReceived prints the request context of a log object
func (*Log) SendHTTPResponse ¶
func (l *Log) SendHTTPResponse(w http.ResponseWriter, response HTTPResponse)
SendHTTPResponse finalizes response data and sends the content of an HttpResponse to the provided http.ResponseWriter
Params: w: The http response writer for the active request response: The HttpResponse to be sent
func (*Log) SetContext ¶
SetContext sets the provided context key to the provided value
func (*Log) SetRequestHeaders ¶
SetRequestHeaders sets the trace and span id headers for a request to another service
This function should always be called when making a request to another Rokwire service
func (*Log) SetResponseHeaders ¶
func (l *Log) SetResponseHeaders(r *HTTPResponse)
SetResponseHeaders sets the trace id header for a response
This function should always be called when returning a response
func (*Log) WarnError ¶
WarnError prints the log at warn level with given message and error
Returns error message as string
func (*Log) WarnWithDetails ¶
WarnWithDetails prints the log at warn level with given details and message
type LogLevel ¶
type LogLevel string
LogLevel represents the level of logging to be performed
func LogLevelFromString ¶
LogLevelFromString takes a string (not case-sensitive) and returns the equivalent logLevel. Options are "debug", "info", "warn", and "error"
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger struct defines a wrapper for a logger object
func NewLogger ¶
func NewLogger(serviceName string, opts *LoggerOpts) *Logger
NewLogger is constructor for a logger object with initial configuration at the service level Params:
serviceName: A meaningful service name to be associated with all logs opts: Configuration options for the Logger
func (*Logger) DebugWithFields ¶
DebugWithFields prints the log at debug level with given fields and message
func (*Logger) ErrorWithFields ¶
ErrorWithFields prints the log at error level with given fields and message
func (*Logger) Fatal ¶
Fatal prints the log with a fatal error message and stops the service instance WARNING: Only use for critical error messages that should prevent the service from running
func (*Logger) Fatalf ¶
Fatalf prints the log with a fatal format error message and stops the service instance WARNING: Only use for critical error messages that should prevent the service from running
func (*Logger) InfoWithFields ¶
InfoWithFields prints the log at info level with given fields and message
func (*Logger) NewLog ¶
func (l *Logger) NewLog(traceID string, request RequestContext) *Log
NewLog is a constructor for a log object
func (*Logger) NewRequestLog ¶
NewRequestLog is a constructor for a log object for a request
func (*Logger) WarnWithFields ¶
WarnWithFields prints the log at warn level with given fields and message
type LoggerOpts ¶
type LoggerOpts struct { //JSONFmt: When true, logs will be output in JSON format. Otherwise logs will be in logfmt JSONFmt bool //SensitiveHeaders: A list of any headers that contain sensitive information and should not be logged // Defaults: Authorization, Csrf SensitiveHeaders []string //SuppressRequests: A list of HttpRequestProperties of requests that should not be logged // Any "Warn" or higher severity logs will still be logged. // This is useful to prevent info logs from health checks and similar requests from // flooding the logs // All specified fields in the provided HttpRequestProperties must match for the logs // to be suppressed. Empty fields will be ignored. SuppressRequests []HTTPRequestProperties }
LoggerOpts provides configuration options for the Logger type