logging

package module
v0.0.0-...-950d40d Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CMSMonitProducer string

CMSMonitProducer controls CMS Monit producer name

View Source
var CMSMonitType string

CMSMonitType controls CMS Monit log record type

View Source
var CollectorLogin string

CollectorLogin

View Source
var CollectorPassword string

CollectorPassword

View Source
var CollectorSize int

CollectorSize

View Source
var CollectorURL string

CollectorURL

View Source
var CollectorVerbose int

CollectorVerbose

View Source
var UTC bool

UTC flag represents UTC time zone for log messages

View Source
var ZapLogger string

ZapLogger defines zap logger structure

Functions

func LogRequest

func LogRequest(w http.ResponseWriter, r *http.Request, start time.Time, cauth string, status *int, tstamp int64, bytesOut int64)

helper function to log every single user request, here we pass pointer to status code as it may change through the handler while we use defer logRequest

func LoggingMiddleware

func LoggingMiddleware(h http.Handler) http.Handler

LoggingMiddleware provides logging middleware for HTTP requests https://arunvelsriram.dev/simple-golang-http-logging-middleware

Types

type Collector

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

Collector holds a fixed-size list of records

var LogCollector *Collector

LogCollector pointer

func NewCollector

func NewCollector(maxSize int, endpoint, login, password string, httpClient *http.Client) *Collector

NewCollector initializes and returns a new Collector

func (*Collector) CollectAndSend

func (c *Collector) CollectAndSend(record HTTPRecord) error

CollectAndSend collects a new record. If the list reaches the maxSize, it sends the records to the configured endpoint and resets the list.

func (*Collector) Send

func (c *Collector) Send() error

Send sends the list of records to the configured HTTP endpoint as JSON

type CustomResponseWriter

type CustomResponseWriter struct {
	http.ResponseWriter
	BytesWritten int
}

CustomResponseWriter wraps http.ResponseWriter to capture the number of bytes written

func (*CustomResponseWriter) Write

func (w *CustomResponseWriter) Write(data []byte) (int, error)

Write captures the number of bytes written and calls the underlying Write method

type HTTPRecord

type HTTPRecord struct {
	Producer  string    `json:"producer"`  // name of the producer
	Type      string    `json:"type"`      // type of metric
	Timestamp int64     `json:"timestamp"` // UTC milliseconds
	Host      string    `json:"host"`      // used to add extra information about the node submitting your data
	Data      LogRecord `json:"data"`      // log record data
}

HTTPRecord provides http record we send to logs endpoint

type LogRecord

type LogRecord struct {
	Method         string  `json:"method"`           // http.Request HTTP method
	URI            string  `json:"uri"`              // http.RequestURI
	API            string  `json:"api"`              // http service API being used
	System         string  `json:"system"`           // cmsweb service name
	ClientIP       string  `json:"clientip"`         // client IP address
	BytesSend      int64   `json:"bytes_send"`       // number of bytes send with HTTP request
	BytesReceived  int64   `json:"bytes_received"`   // number of bytes received with HTTP request
	Proto          string  `json:"proto"`            // http.Request protocol
	Status         int64   `json:"status"`           // http.Request status code
	ContentLength  int64   `json:"content_length"`   // http.Request content-length
	AuthProto      string  `json:"auth_proto"`       // authentication protocol
	AuthCert       string  `json:"auth_cert"`        // auth certificate, user DN
	LoginName      string  `json:"login_name"`       // login name, user DN
	Auth           string  `json:"auth"`             // auth method
	Cipher         string  `json:"cipher"`           // TLS cipher name
	Referer        string  `json:"referer"`          // http referer
	UserAgent      string  `json:"user_agent"`       // http user-agent field
	UserAgentName  string  `json:"user_agent_name"`  // http user-agent name w/o version
	XForwardedHost string  `json:"x_forwarded_host"` // http.Request X-Forwarded-Host
	XForwardedFor  string  `json:"x_forwarded_for"`  // http.Request X-Forwarded-For
	RemoteAddr     string  `json:"remote_addr"`      // http.Request remote address
	ResponseStatus string  `json:"response_status"`  // http.Response status
	ResponseTime   float64 `json:"response_time"`    // http response time
	RequestTime    float64 `json:"request_time"`     // http request time
	Timestamp      int64   `json:"timestamp"`        // record timestamp
	RecTimestamp   int64   `json:"rec_timestamp"`    // timestamp for backward compatibility with apache
	RecDate        string  `json:"rec_date"`         // timestamp for backward compatibility with apache
}

LogRecord represents HTTP log record

type LogWriter

type LogWriter struct {
}

custom logger

func (LogWriter) Write

func (writer LogWriter) Write(data []byte) (int, error)

type RotateLogWriter

type RotateLogWriter struct {
	RotateLogs *rotatelogs.RotateLogs
}

custom rotate logger

func (RotateLogWriter) Write

func (w RotateLogWriter) Write(data []byte) (int, error)

Jump to

Keyboard shortcuts

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