logger

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecompressResponse

func DecompressResponse(body []byte, contentEncoding string) ([]byte, error)

DecompressResponse decompresses response body based on Content-Encoding

func HeadersToMap

func HeadersToMap(headers http.Header) map[string]string

HeadersToMap converts http.Header to map[string]string

func IsTextLikeContent

func IsTextLikeContent(data []byte, contentType string) bool

IsTextLikeContent checks if the decompressed content appears to be text

Types

type CompressionType

type CompressionType int

CompressionType represents the type of compression used

const (
	CompressionNone CompressionType = iota
	CompressionGzip
	CompressionDeflate
	CompressionBrotli
	CompressionUnknown
)

func DetectCompressionType

func DetectCompressionType(contentEncoding string) CompressionType

DetectCompressionType detects compression type from Content-Encoding header

func (CompressionType) String

func (c CompressionType) String() string

String returns the string representation of compression type

type EnhancedLogger

type EnhancedLogger struct {
	*StandardLogger
	// contains filtered or unexported fields
}

EnhancedLogger implements both Logger and TrafficLogger interfaces

func (*EnhancedLogger) Close

func (l *EnhancedLogger) Close() error

Close closes the traffic logger and flushes any buffered data

func (*EnhancedLogger) LogTraffic

func (l *EnhancedLogger) LogTraffic(record *TrafficRecord) error

LogTraffic logs a traffic record based on configuration

type HAR

type HAR struct {
	Log HARLog `json:"log"`
}

HAR represents the root HAR object following the W3C specification

func NewHAR

func NewHAR() *HAR

NewHAR creates a new HAR structure with proper initialization

func (*HAR) ToJSON

func (h *HAR) ToJSON() ([]byte, error)

ToJSON converts HAR to JSON bytes

type HARBrowser

type HARBrowser struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	Comment string `json:"comment,omitempty"`
}

HARBrowser represents the browser information

type HARCache

type HARCache struct {
	BeforeRequest *HARCacheState `json:"beforeRequest,omitempty"`
	AfterRequest  *HARCacheState `json:"afterRequest,omitempty"`
	Comment       string         `json:"comment,omitempty"`
}

HARCache represents cache information

type HARCacheState

type HARCacheState struct {
	Expires    time.Time `json:"expires,omitempty"`
	LastAccess time.Time `json:"lastAccess"`
	ETag       string    `json:"eTag"`
	HitCount   int       `json:"hitCount"`
	Comment    string    `json:"comment,omitempty"`
}

HARCacheState represents cache state

type HARContent

type HARContent struct {
	Size        int    `json:"size"`
	Compression int    `json:"compression,omitempty"`
	MimeType    string `json:"mimeType"`
	Text        string `json:"text,omitempty"`
	Encoding    string `json:"encoding,omitempty"`
	Comment     string `json:"comment,omitempty"`
}

HARContent represents response content

type HARCookie

type HARCookie struct {
	Name     string    `json:"name"`
	Value    string    `json:"value"`
	Path     string    `json:"path,omitempty"`
	Domain   string    `json:"domain,omitempty"`
	Expires  time.Time `json:"expires,omitempty"`
	HTTPOnly bool      `json:"httpOnly,omitempty"`
	Secure   bool      `json:"secure,omitempty"`
	Comment  string    `json:"comment,omitempty"`
}

HARCookie represents a cookie

type HARCreator

type HARCreator struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	Comment string `json:"comment,omitempty"`
}

HARCreator represents the application that created the HAR file

type HAREntry

type HAREntry struct {
	Pageref         string      `json:"pageref,omitempty"`
	StartedDateTime time.Time   `json:"startedDateTime"`
	Time            float64     `json:"time"`
	Request         HARRequest  `json:"request"`
	Response        HARResponse `json:"response"`
	Cache           HARCache    `json:"cache"`
	Timings         HARTimings  `json:"timings"`
	ServerIPAddress string      `json:"serverIPAddress,omitempty"`
	Connection      string      `json:"connection,omitempty"`
	Comment         string      `json:"comment,omitempty"`
}

HAREntry represents a single HTTP transaction

func ConvertTrafficRecordToHAREntry

func ConvertTrafficRecordToHAREntry(record *TrafficRecord) HAREntry

ConvertTrafficRecordToHAREntry converts a TrafficRecord to a HAR entry

type HARLog

type HARLog struct {
	Version string     `json:"version"`
	Creator HARCreator `json:"creator"`
	Browser HARBrowser `json:"browser,omitempty"`
	Pages   []HARPage  `json:"pages"` // Required by HAR 1.2 spec, must not use omitempty
	Entries []HAREntry `json:"entries"`
}

HARLog represents the log object containing all HTTP transaction data

type HARNameValue

type HARNameValue struct {
	Name    string `json:"name"`
	Value   string `json:"value"`
	Comment string `json:"comment,omitempty"`
}

HARNameValue represents a name-value pair for headers, query parameters, etc.

type HARPage

type HARPage struct {
	StartedDateTime time.Time  `json:"startedDateTime"`
	ID              string     `json:"id"`
	Title           string     `json:"title"`
	PageTimings     HARTimings `json:"pageTimings"`
	Comment         string     `json:"comment,omitempty"`
}

HARPage represents a page (optional in HAR)

type HARPostData

type HARPostData struct {
	MimeType string         `json:"mimeType"`
	Params   []HARPostParam `json:"params"`
	Text     string         `json:"text"`
	Comment  string         `json:"comment,omitempty"`
}

HARPostData represents POST data

type HARPostParam

type HARPostParam struct {
	Name        string `json:"name"`
	Value       string `json:"value,omitempty"`
	FileName    string `json:"fileName,omitempty"`
	ContentType string `json:"contentType,omitempty"`
	Comment     string `json:"comment,omitempty"`
}

HARPostParam represents a POST parameter

type HARRequest

type HARRequest struct {
	Method      string         `json:"method"`
	URL         string         `json:"url"`
	HTTPVersion string         `json:"httpVersion"`
	Cookies     []HARCookie    `json:"cookies"`
	Headers     []HARNameValue `json:"headers"`
	QueryString []HARNameValue `json:"queryString"`
	PostData    *HARPostData   `json:"postData,omitempty"`
	HeadersSize int            `json:"headersSize"`
	BodySize    int            `json:"bodySize"`
	Comment     string         `json:"comment,omitempty"`
}

HARRequest represents the HTTP request details

type HARResponse

type HARResponse struct {
	Status      int            `json:"status"`
	StatusText  string         `json:"statusText"`
	HTTPVersion string         `json:"httpVersion"`
	Cookies     []HARCookie    `json:"cookies"`
	Headers     []HARNameValue `json:"headers"`
	Content     HARContent     `json:"content"`
	RedirectURL string         `json:"redirectURL"`
	HeadersSize int            `json:"headersSize"`
	BodySize    int            `json:"bodySize"`
	Comment     string         `json:"comment,omitempty"`
}

HARResponse represents the HTTP response details

type HARTimings

type HARTimings struct {
	Blocked int    `json:"blocked"`           // Required by HAR 1.2 spec, must not use omitempty
	DNS     int    `json:"dns"`               // Required by HAR 1.2 spec, must not use omitempty
	Connect int    `json:"connect"`           // Required by HAR 1.2 spec, must not use omitempty
	Send    int    `json:"send"`              // Required by HAR 1.2 spec, must not use omitempty
	Wait    int    `json:"wait"`              // Required by HAR 1.2 spec, must not use omitempty
	Receive int    `json:"receive"`           // Required by HAR 1.2 spec, must not use omitempty
	SSL     int    `json:"ssl,omitempty"`     // Optional field
	Comment string `json:"comment,omitempty"` // Optional field
}

HARTimings represents timing information

type HTTPRequest

type HTTPRequest struct {
	Method   string            `json:"method"`
	URL      string            `json:"url"`
	Proto    string            `json:"proto"`
	Host     string            `json:"host"`
	Headers  map[string]string `json:"headers"`
	Body     string            `json:"body,omitempty"`
	BodySize int               `json:"body_size"`
}

HTTPRequest represents HTTP request details

type HTTPResponse

type HTTPResponse struct {
	Proto       string            `json:"proto"`
	Status      string            `json:"status"`
	StatusCode  int               `json:"status_code"`
	Headers     map[string]string `json:"headers"`
	Body        string            `json:"body,omitempty"`
	BodySize    int               `json:"body_size"`
	ContentType string            `json:"content_type"`
}

HTTPResponse represents HTTP response details

type LogLevel

type LogLevel int

LogLevel represents different log levels

const (
	LevelDebug LogLevel = iota
	LevelInfo
	LevelWarn
	LevelError
)

type Logger

type Logger interface {
	Debug(format string, args ...interface{})
	Info(format string, args ...interface{})
	Warn(format string, args ...interface{})
	Error(format string, args ...interface{})
}

Logger interface for logging functionality

func New

func New(verbose bool) Logger

New creates a new logger instance

type StandardLogger

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

StandardLogger implements Logger interface

func (*StandardLogger) Debug

func (l *StandardLogger) Debug(format string, args ...interface{})

Debug logs debug messages (only in verbose mode)

func (*StandardLogger) Error

func (l *StandardLogger) Error(format string, args ...interface{})

Error logs error messages

func (*StandardLogger) Info

func (l *StandardLogger) Info(format string, args ...interface{})

Info logs informational messages

func (*StandardLogger) Warn

func (l *StandardLogger) Warn(format string, args ...interface{})

Warn logs warning messages

type TrafficLogger

type TrafficLogger interface {
	Logger
	LogTraffic(record *TrafficRecord) error
	Close() error
}

TrafficLogger handles traffic logging with various output formats and filtering

func NewEnhanced

func NewEnhanced(cfg *config.Config) (TrafficLogger, error)

NewEnhanced creates a new enhanced logger with traffic logging capabilities

type TrafficRecord

type TrafficRecord struct {
	Timestamp time.Time     `json:"timestamp"`
	SessionID string        `json:"session_id"`
	Domain    string        `json:"domain"`
	Request   HTTPRequest   `json:"request"`
	Response  HTTPResponse  `json:"response"`
	Duration  time.Duration `json:"duration_ms"`
}

TrafficRecord represents a single HTTP request/response pair

Jump to

Keyboard shortcuts

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