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 ¶
- Variables
- func CacheStatusFromContext(ctx context.Context) bool
- func CacheStatusFromHeaders(h http.Header) bool
- func ContextWithTransaction(ctx context.Context, txnID string) context.Context
- func CreateLogger(logger io.Writer, listenPort int, pretty bool) func(http.Handler) http.Handler
- func GetOutboundIP() net.IP
- func RequestWithCacheStatus(r *http.Request, status bool) *http.Request
- func TransactionFromContext(ctx context.Context) string
- func TransactionHandler(header string) func(http.Handler) http.Handler
- func TxnFields(ctx context.Context) log.Fields
- func UserAgent(req *http.Request) string
- type NoopWriter
- type ScalyrWriter
Constants ¶
This section is empty.
Variables ¶
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
CacheStatusFromContext retrieves the cache status from the given context.
func CacheStatusFromHeaders ¶ added in v1.0.71
CacheStatusFromHeaders returns true if the X-Cache-Hit header was set with the value "true".
func ContextWithTransaction ¶ added in v1.0.42
func CreateLogger ¶
CreateLogger creates an access logger
func RequestWithCacheStatus ¶ added in v1.0.26
RequestWithCacheStatus attaches a cache status to the request.
func TransactionFromContext ¶
TransactionFromContext retrieves the txnID from the given context.
func TransactionHandler ¶
TransactionHandler creates a unique ID for every request.
Types ¶
type NoopWriter ¶
type NoopWriter struct{}
NoopWriter satisfies the io.Writer interface, but does nothing.
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.