logger

package
v0.0.22 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const CONTENT_LENGTH_HEADER = "content-length"
View Source
const CONTENT_TYPE_HEADER = "content-type"

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleLogger

type ConsoleLogger struct{}

ConsoleLogger represents a logger implementation that logs messages to the console.

func (ConsoleLogger) Log

func (c ConsoleLogger) Log(level Level, message string, params map[string]any)

Log function provides a message string containing placeholders in the format '%{key}', along with the log level and a map of parameters that can be replaced in the message.

type Level

type Level string

Level is a string enum. An enum representing different log levels.

const (
	Level_ERROR Level = "error" // Error log level.
	Level_WARN  Level = "warn"  // Warning log level.
	Level_INFO  Level = "info"  // Information log level.
	Level_DEBUG Level = "debug" // Debug log level.
	Level_TRACE Level = "trace" // Trace log level.
)

func (Level) MarshalJSON

func (e Level) MarshalJSON() (
	[]byte,
	error)

MarshalJSON implements the json.Marshaller interface for Level. It customizes the JSON marshaling process for Level objects.

func (*Level) UnmarshalJSON

func (e *Level) UnmarshalJSON(input []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Level. It customizes the JSON unmarshalling process for Level objects.

type LoggerConfiguration

type LoggerConfiguration struct {
	// contains filtered or unexported fields
}

LoggerConfiguration represents options for configuring logging behavior.

func NewLoggerConfiguration

func NewLoggerConfiguration(options ...LoggerOptions) LoggerConfiguration

NewLoggerConfiguration creates default LoggingOptions with the provided options.

type LoggerInterface

type LoggerInterface interface {
	// Log function provides a message string containing placeholders in the format '%{key}',
	// along with the log level and a map of parameters that can be replaced in the message.
	Log(level Level, message string, params map[string]any)
}

LoggerInterface represents an interface for a generic logger.

type LoggerOptions

type LoggerOptions func(*LoggerConfiguration)

LoggerOptions represents a function type that can be used to apply configuration to the LoggerOptions struct.

func WithLevel

func WithLevel(level Level) LoggerOptions

WithLevel is an option that sets the LogLevel in the LoggingOptions.

func WithLogger

func WithLogger(logger LoggerInterface) LoggerOptions

WithLogger is an option that sets the LoggerInterface in the LoggingOptions.

func WithMaskSensitiveHeaders

func WithMaskSensitiveHeaders(maskSensitiveHeaders bool) LoggerOptions

WithMaskSensitiveHeaders is an option that enable to mask Sensitive Headers in the LoggingOptions.

func WithRequestConfiguration

func WithRequestConfiguration(options ...RequestLoggerOptions) LoggerOptions

WithRequestConfiguration is an option that sets that enable to log Request in the LoggingOptions.

func WithResponseConfiguration

func WithResponseConfiguration(options ...ResponseLoggerOptions) LoggerOptions

WithResponseConfiguration is an option that sets that enable to log Response in the LoggingOptions.

type NullSdkLogger

type NullSdkLogger struct{}

NullSdkLogger represents implementation for SdkLoggerInterface, implementing methods to log HTTP requests and responses.

func (NullSdkLogger) LogRequest

func (a NullSdkLogger) LogRequest(_request *http.Request)

LogRequest request Logs an HTTP request.

func (NullSdkLogger) LogResponse

func (a NullSdkLogger) LogResponse(_response *http.Response)

LogResponse Logs an HTTP response.

type RequestLoggerConfiguration

type RequestLoggerConfiguration struct {
	// contains filtered or unexported fields
}

RequestLoggerConfiguration represents options for logging HTTP request details.

func NewHttpRequestLoggerConfiguration

func NewHttpRequestLoggerConfiguration(options ...RequestLoggerOptions) RequestLoggerConfiguration

NewHttpRequestLoggerConfiguration creates default RequestLoggerConfiguration with the provided options.

type RequestLoggerOptions

type RequestLoggerOptions func(*RequestLoggerConfiguration)

RequestLoggerOptions represents a function type that can be used to apply configuration to the RequestLoggerOptions struct.

func WithExcludeRequestHeaders

func WithExcludeRequestHeaders(excludeHeaders ...string) RequestLoggerOptions

WithExcludeRequestHeaders is an option that sets the Headers To Exclude in the LoggingOptions.

func WithIncludeQueryInPath

func WithIncludeQueryInPath(includeQueryInPath bool) RequestLoggerOptions

WithIncludeQueryInPath is an option that enable include Query InPath in the LoggingOptions.

func WithIncludeRequestHeaders

func WithIncludeRequestHeaders(includeHeaders ...string) RequestLoggerOptions

WithIncludeRequestHeaders is an option that sets the Headers To Include in the LoggingOptions.

func WithRequestBody

func WithRequestBody(logBody bool) RequestLoggerOptions

WithRequestBody is an option that sets that enable to log body in the LoggingOptions.

func WithRequestHeaders

func WithRequestHeaders(logHeaders bool) RequestLoggerOptions

WithRequestHeaders is an option that sets that enable to log headers in the LoggingOptions.

func WithWhitelistRequestHeaders

func WithWhitelistRequestHeaders(whitelistHeaders ...string) RequestLoggerOptions

WithWhitelistRequestHeaders is an option that sets the Headers To Whitelist in the LoggingOptions.

type ResponseLoggerConfiguration

type ResponseLoggerConfiguration struct {
	// contains filtered or unexported fields
}

ResponseLoggerConfiguration represents options for logging HTTP message details.

func NewResponseLoggerConfiguration

func NewResponseLoggerConfiguration(options ...ResponseLoggerOptions) ResponseLoggerConfiguration

NewResponseLoggerConfiguration creates default ResponseLoggerConfiguration with the provided options.

type ResponseLoggerOptions

type ResponseLoggerOptions func(*ResponseLoggerConfiguration)

ResponseLoggerOptions represents a function type that can be used to apply configuration to the ResponseLoggerOptions struct.

func WithExcludeResponseHeaders

func WithExcludeResponseHeaders(excludeHeaders ...string) ResponseLoggerOptions

WithExcludeResponseHeaders is an option that sets the Headers To Exclude in the LoggingOptions.

func WithIncludeResponseHeaders

func WithIncludeResponseHeaders(includeHeaders ...string) ResponseLoggerOptions

WithIncludeResponseHeaders is an option that sets the Headers To Include in the LoggingOptions.

func WithResponseBody

func WithResponseBody(logBody bool) ResponseLoggerOptions

WithResponseBody is an option that sets that enable to log body in the LoggingOptions.

func WithResponseHeaders

func WithResponseHeaders(logHeaders bool) ResponseLoggerOptions

WithResponseHeaders is an option that sets that enable to log headers in the LoggingOptions.

func WithWhitelistResponseHeaders

func WithWhitelistResponseHeaders(whitelistHeaders ...string) ResponseLoggerOptions

WithWhitelistResponseHeaders is an option that sets the Headers To Whitelist in the LoggingOptions.

type SdkLogger

type SdkLogger struct {
	// contains filtered or unexported fields
}

SdkLogger represents implementation for SdkLoggerInterface, providing methods to log HTTP requests and responses.

func (*SdkLogger) LogRequest

func (a *SdkLogger) LogRequest(request *http.Request)

LogRequest request Logs an HTTP request.

func (*SdkLogger) LogResponse

func (a *SdkLogger) LogResponse(response *http.Response)

LogResponse Logs an HTTP response.

type SdkLoggerInterface

type SdkLoggerInterface interface {
	// LogRequest logs the details of an HTTP request.
	LogRequest(request *http.Request)
	// LogResponse logs the details of an HTTP response.
	LogResponse(response *http.Response)
}

SdkLoggerInterface Represents an interface for logging API requests and responses.

func NewSdkLogger

func NewSdkLogger(loggingOpt LoggerConfiguration) SdkLoggerInterface

NewSdkLogger Constructs a new instance of SdkLogger or NullSdkLogger.

Jump to

Keyboard shortcuts

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