logging

package
v0.0.0-...-2fa74ab Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogRequestEntry

type LogRequestEntry struct {
	ContextID    string    `json:"context"`
	Package      string    `json:"package"`
	Method       string    `json:"method"`
	Message      string    `json:"message,omitempty"`
	URL          string    `json:"url,omitempty"`
	RemoteAddr   string    `json:"remote_addr,omitempty"`
	UserAgent    string    `json:"user_agent,omitempty"`
	StatusCode   int       `json:"status_code,omitempty"`
	ResponseTime string    `json:"response_time,omitempty"`
	QueryParams  string    `json:"query_params,omitempty"`
	Timestamp    time.Time `json:"timestamp"`
}

LogRequestEntry defines the structure for our request log output

func NewLogRequestEntry

func NewLogRequestEntry(contextID, method string, start time.Time) *LogRequestEntry

NewLogRequestEntry creates a new LogRequestEntry with required fields

func (*LogRequestEntry) WithMessage

func (b *LogRequestEntry) WithMessage(message string) *LogRequestEntry

WithMessage sets the message field

func (*LogRequestEntry) WithPackage

func (b *LogRequestEntry) WithPackage(pkg string) *LogRequestEntry

WithPackage sets a custom package name

func (*LogRequestEntry) WithQueryParams

func (b *LogRequestEntry) WithQueryParams(queryParams string) *LogRequestEntry

WithQueryParams sets the QueryParams field

func (*LogRequestEntry) WithRemoteAddr

func (b *LogRequestEntry) WithRemoteAddr(remoteAddr string) *LogRequestEntry

WithRemoteAddr sets the RemoteAddr field

func (*LogRequestEntry) WithResponseTime

func (b *LogRequestEntry) WithResponseTime(responseTime string) *LogRequestEntry

WithResponseTime sets the ResponseTime field

func (*LogRequestEntry) WithStatusCode

func (b *LogRequestEntry) WithStatusCode(statusCode int) *LogRequestEntry

WithStatusCode sets the StatusCode field

func (*LogRequestEntry) WithURL

func (b *LogRequestEntry) WithURL(url string) *LogRequestEntry

WithURL sets the URL field

func (*LogRequestEntry) WithUserAgent

func (b *LogRequestEntry) WithUserAgent(userAgent string) *LogRequestEntry

WithUserAgent sets the UserAgent field

type Logger

type Logger interface {
	LogRequest(entry *LogRequestEntry)
	LogInternal(ctx context.Context, packg, method, message string, args ...interface{})
	LogError(ctx context.Context, packg, method string, err error)
}

func GetLogger

func GetLogger() Logger

GetLogger gets the logger instance

func NewLogger

func NewLogger() Logger

NewLogger creates a new logger instance (singleton)

type LoggingConstant

type LoggingConstant string
const (
	ContextIDKey LoggingConstant = "contextID"
)

Jump to

Keyboard shortcuts

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