Documentation ¶
Overview ¶
Package logjam provides a go client for sending application metrics and log lines to a logjam endpoint. See https://github.com/skaes/logjam_app.
Index ¶
- func DefaultActionNameExtractor(r *http.Request) string
- func LegacyActionNameExtractor(r *http.Request) string
- func MethodNotAllowedHandler(w http.ResponseWriter, r *http.Request)
- func NotFoundHandler(w http.ResponseWriter, r *http.Request)
- func SetCallHeaders(ctx context.Context, outgoing *http.Request)
- type ActionNameExtractor
- type Agent
- type DiscardingLogger
- type LogLevel
- type Logger
- func (l *Logger) Debug(ctx context.Context, args ...interface{})
- func (l *Logger) Debugf(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Error(ctx context.Context, args ...interface{})
- func (l *Logger) Errorf(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Exception(ctx context.Context, tag string, args ...interface{})
- func (l *Logger) Exceptionf(ctx context.Context, tag string, format string, args ...interface{})
- func (l *Logger) Info(ctx context.Context, args ...interface{})
- func (l *Logger) Infof(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Warn(ctx context.Context, args ...interface{})
- func (l *Logger) Warnf(ctx context.Context, format string, args ...interface{})
- type MiddlewareOptions
- type Options
- type Printer
- type Request
- func (r *Request) AddCount(key string, value int64)
- func (r *Request) AddDuration(key string, value time.Duration)
- func (r *Request) AddException(name string)
- func (r *Request) AugmentRequest(incoming *http.Request) *http.Request
- func (r *Request) ChangeAction(w http.ResponseWriter, action string)
- func (r *Request) Count(key string)
- func (r *Request) Finish(code int)
- func (r *Request) GetField(key string) interface{}
- func (r *Request) Log(severity LogLevel, line string)
- func (r *Request) MeasureDuration(key string, f func())
- func (r *Request) NewContext(c context.Context) context.Context
- func (r *Request) SetField(key string, value interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultActionNameExtractor ¶
DefaultActionNameExtractor replaces slashes with "::" and camel cases the individual path segments.
func LegacyActionNameExtractor ¶
LegacyActionNameExtractor is an extractor used in older versions of this package. Use it if you want to keep old action names in Logjam.
func MethodNotAllowedHandler ¶ added in v0.0.15
func MethodNotAllowedHandler(w http.ResponseWriter, r *http.Request)
MethodNotAllowedHandler is an example handler function to deal with unroutable requests. If you use gorilla/mux, you can install it on your router using r.MethodNotAllowedHandler = http.HandlerFunc(logjam.MethodNotAllowedHandler).
func NotFoundHandler ¶ added in v0.0.15
func NotFoundHandler(w http.ResponseWriter, r *http.Request)
NotFoundHandler is an example handler function to deal with unroutable requests. If you use gorilla/mux, you can install it on your router using r.NotFoundHandler = http.HandlerFunc(logjam.NotFoundHandler).
Types ¶
type ActionNameExtractor ¶
ActionNameExtractor takes a HTTP request and returns a logjam conformant action name.
type Agent ¶ added in v0.0.9
type Agent struct { Options // contains filtered or unexported fields }
Agent encapsulates information about a logjam agent.
func (*Agent) NewHandler ¶ added in v0.0.10
NewHandler can be used to wrap any standard http.Handler. It handles panics caused by the next handler in the chain by logging an error message to os.Stderr and sending the same message to logjam. If the handler hasn't already written something to the response writer, or set its response code, it will write a 500 response with an empty response body. If the middleware option BubblePanics is true, it will panic again with the original object.
func (*Agent) NewMiddleware ¶ added in v0.0.9
NewMiddleware is a convenience function to be used with the gorilla/mux package.
func (*Agent) NewRequest ¶ added in v0.0.9
NewRequest creates a new logjam request for a given action name.
type DiscardingLogger ¶ added in v0.0.9
type DiscardingLogger struct{}
DiscardingLogger discards all log lines.
func (*DiscardingLogger) Println ¶ added in v0.0.9
func (d *DiscardingLogger) Println(v ...interface{})
Println does nothing.
type Logger ¶
type Logger struct { *log.Logger // The embedded log.Logger. LogLevel LogLevel // Log attemtps with a log level lower than this field are not forwarded to the embbeded logger. }
Logger extends the standard log.Logger with methods that send log lines to both logjam and the embedded Logger. Even though all standard logger methods are available, you will want to use Fatal, Fatalf and Fatalln only during program startup/shutdown, as they abort the runnning process. Note that lines which are logged at a level below the configured log level will not be sent to the embedded logger, only forwarded to the logjam logger. Usually one would configure log level DEBUG for development and ERROR or even FATAL for production environments, as logs are sent to logjam and/or Graylog anyway.
func (*Logger) Exception ¶ added in v0.0.10
Exception logs an exception tag and adds the exception to the logjam request.
func (*Logger) Exceptionf ¶ added in v0.0.10
Exceptionf logs an exception tag and adds the exception to the logjam request.
type MiddlewareOptions ¶ added in v0.0.10
type MiddlewareOptions struct {
BubblePanics bool // Whether the logjam middleware should let panics bubble up the handler chain.
}
MiddlewareOptions defines options for the logjam middleware.
type Options ¶ added in v0.0.7
type Options struct { AppName string // Name of your application EnvName string // What environment you're running in (production, preview, ...) Endpoints string // Comma separated list of ZeroMQ connections specs, defaults to localhost Port int // ZeroMQ default port for ceonnection specs Linger int // ZeroMQ socket option of the same name Sndhwm int // ZeroMQ socket option of the same name Rcvhwm int // ZeroMQ socket option of the same name Sndtimeo int // ZeroMQ socket option of the same name Rcvtimeo int // ZeroMQ socket option of the same name Logger Printer // Logjam errors are printed using this interface. LogLevel LogLevel // Only lines with a severity equal to or higher are sent to logjam. Defaults to DEBUG. ActionNameExtractor ActionNameExtractor // Function to transform path segments to logjam action names. ObfuscateIPs bool // Whether IP addresses should be obfuscated. MaxLineLength int // Long lines truncation threshold, defaults to 2048. MaxBytesAllLines int // Max number of bytes of all log lines, defaults to 1MB. }
Options such as appliction name, environment and ZeroMQ socket options.
type Printer ¶ added in v0.0.9
type Printer interface {
Println(args ...interface{})
}
Printer is a minimal interface for the agent to log errors.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request encapsulates information about the current logjam request.
func GetRequest ¶
GetRequest retrieves a logjam request from an Context. Returns nil if no request is stored in the context.
func (*Request) AddDuration ¶
AddDuration increases increments a timer metric associated with this request.
func (*Request) AddException ¶ added in v0.0.10
AddException adds an exception tag to be sent to logjam.
func (*Request) AugmentRequest ¶
AugmentRequest extends a given http request with a logjam request stored in its context.
func (*Request) ChangeAction ¶ added in v0.0.6
func (r *Request) ChangeAction(w http.ResponseWriter, action string)
ChangeAction changes the action name and updates the corresponding header on the given http request writer.
func (*Request) MeasureDuration ¶
MeasureDuration is a helper function that records the duration of execution of the passed function in cases where it is cumbersome to just use AddDuration instead.
func (*Request) NewContext ¶
NewContext creates a new context with the request added.