logging

package
v1.0.66 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package logging > cache provides information about the cached nature of the request. This exists in package logging instead cache due to circular dependency problems coupled with the fact that we're trying to inform the logger with this information

Index

Constants

This section is empty.

Variables

View Source
var (
	// ScalyrClient is the http.Client used to communicate with scalyr.
	ScalyrClient = &http.Client{
		Timeout: 2 * time.Second,
	}
)

Functions

func CacheStatusFromContext added in v1.0.26

func CacheStatusFromContext(ctx context.Context) bool

CacheStatusFromContext retrieves the cache status from the given context.

func ContextWithTransaction added in v1.0.42

func ContextWithTransaction(ctx context.Context, txnID string) context.Context

func CreateLogger

func CreateLogger(logger io.Writer, listenPort int, pretty bool) func(http.Handler) http.Handler

CreateLogger creates an access logger

func GetOutboundIP

func GetOutboundIP() net.IP

GetOutboundIP returns the outbound ip address.

func RequestWithCacheStatus added in v1.0.26

func RequestWithCacheStatus(r *http.Request, status bool) *http.Request

RequestWithCacheStatus attaches a cache status to the request.

func TransactionFromContext

func TransactionFromContext(ctx context.Context) string

TransactionFromContext retrieves the txnID from the given context.

func TransactionHandler

func TransactionHandler(header string) func(http.Handler) http.Handler

TransactionHandler creates a unique ID for every request.

func TxnFields

func TxnFields(ctx context.Context) log.Fields

TxnFields builds a log.Fields object when all you need is a transactionID.

Types

type NoopWriter

type NoopWriter struct{}

NoopWriter satisfies the io.Writer interface, but does nothing.

func (*NoopWriter) Write

func (*NoopWriter) Write([]byte) (int, error)

type ScalyrWriter

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

ScalyrWriter will buffer all log writes for logging to scalyr, then tee all calls to the supplied io.Writer

func CreateScalyrWriter

func CreateScalyrWriter(tee io.Writer, url string) *ScalyrWriter

CreateScalyrWriter will create an io.Writer which will tee all log writes between the supplied io.Writer and a buffer. You can then call go ScalyrWriter.Log with a supplied interval. On that interval, all collected logs will be sent to Scalyr

URL Takes the following form, which requires the user to fill out the Host, Logfile, Access Token and Parser ex: https://www.scalyr.com/api/uploadLogs?host=my-host-name&logfile=myErrorLog&token=myScalyrToken&parser=goErrorLog

Logs are POST'd in batches to Scalyr based on the interval provided to the Update function. Use logging.NoopWriter if you wish to ONLY log to Scalyr

func (*ScalyrWriter) Println

func (w *ScalyrWriter) Println(msg ...string)

Println writes a log message out to the defined TEE writer. Anything sent to Println will *NOT* be sent to scalyr.

func (*ScalyrWriter) Update

func (w *ScalyrWriter) Update(interval int)

Update periodically polls the current writer's buffer and uploads the logs to Scalyr. Interval should be provided in Milliseconds.

Example usage: w := CreateScalyrWriter(os.Stdout, "https://www.scalyr.com/api/uploadLogs?host=ExampleService&logfile=AccessLog&token=ExampleToken") go w.Update(2000) // Update every 2 seconds. Client timeout is set to 2 seconds, it's not recommended that the update interval be less than 2s.

func (*ScalyrWriter) UpdateNow

func (w *ScalyrWriter) UpdateNow(flushBuffer bool)

UpdateNow immediately uploads the collected logs to Scalyr. Interval should be provided in Milliseconds.

Example usage: w := CreateScalyrWriter(os.Stdout, "https://www.scalyr.com/api/uploadLogs?host=ExampleService&logfile=AccessLog&token=ExampleToken") defer w.UpdateNow() // Update after leaving the current function.

func (*ScalyrWriter) Write

func (w *ScalyrWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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