Documentation

Overview

Package logging implements application log instrumentation and Apache combined access log.

Application Log

The application log uses the logrus package:

https://github.com/sirupsen/logrus

To send messages to the application log, import this package and use its methods. Example:

import log "github.com/sirupsen/logrus"

func doSomething() {
    log.Errorf("nothing to do")
}

During startup initialization, it is possible to redirect the log output from the default /dev/stderr to another file, and to set a common prefix for each log entry. Setting the prefix may be a good idea when the access log is enabled and its output is the same as the one of the application log, to make it easier to split the output for diagnostics.

Access Log

The access log prints HTTP access information in the Apache combined access log format. To output entries, use the logging.Access method. Note that by default, skipper uses the loggingHandler to wrap the central proxy handler, and automatically provides access logging.

During initialization, it is possible to redirect the access log output from the default /dev/stderr to another file, or completely disable the access log.

A special key in the StateBag (accessLog.AccessLogAdditionalDataKey) is exposed so filters can add more data to the access log files. When using the feature, any data contained in a map[string]interface{} in the StateBag's key will be passed to the logger. This is specially useful when more request/response information is needed when logging.

Output Files

To set a custom file output for the application log or the access log is currently not recommended in production environment, because neither the proper handling of system errors, or a log rolling mechanism is implemented at the current stage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(o Options)

    Initializes logging.

    func LogAccess

    func LogAccess(entry *AccessEntry, additional map[string]interface{})

      Logs an access event in Apache combined log format (with a minor customization with the duration). Additional allows to provide extra data that may be also logged, depending on the specific log format.

      Types

      type AccessEntry

      type AccessEntry struct {
      
      	// The client request.
      	Request *http.Request
      
      	// The status code of the response.
      	StatusCode int
      
      	// The size of the response in bytes.
      	ResponseSize int64
      
      	// The time spent processing request.
      	Duration time.Duration
      
      	// The time that the request was received.
      	RequestTime time.Time
      }

        Access log entry.

        type DefaultLog

        type DefaultLog struct{}

          DefaultLog provides a default implementation of the Logger interface.

          func (*DefaultLog) Debug

          func (dl *DefaultLog) Debug(a ...interface{})

          func (*DefaultLog) Debugf

          func (dl *DefaultLog) Debugf(f string, a ...interface{})

          func (*DefaultLog) Error

          func (dl *DefaultLog) Error(a ...interface{})

          func (*DefaultLog) Errorf

          func (dl *DefaultLog) Errorf(f string, a ...interface{})

          func (*DefaultLog) Info

          func (dl *DefaultLog) Info(a ...interface{})

          func (*DefaultLog) Infof

          func (dl *DefaultLog) Infof(f string, a ...interface{})

          func (*DefaultLog) Warn

          func (dl *DefaultLog) Warn(a ...interface{})

          func (*DefaultLog) Warnf

          func (dl *DefaultLog) Warnf(f string, a ...interface{})

          type Logger

          type Logger interface {
          
          	// Log with level ERROR
          	Error(...interface{})
          
          	// Log formatted messages with level ERROR
          	Errorf(string, ...interface{})
          
          	// Log with level WARN
          	Warn(...interface{})
          
          	// Log formatted messages with level WARN
          	Warnf(string, ...interface{})
          
          	// Log with level INFO
          	Info(...interface{})
          
          	// Log formatted messages with level INFO
          	Infof(string, ...interface{})
          
          	// Log with level DEBUG
          	Debug(...interface{})
          
          	// Log formatted messages with level DEBUG
          	Debugf(string, ...interface{})
          }

            Logger instances provide custom logging.

            type LoggingWriter

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

            func NewLoggingWriter

            func NewLoggingWriter(writer http.ResponseWriter) *LoggingWriter

            func (*LoggingWriter) Flush

            func (lw *LoggingWriter) Flush()

            func (*LoggingWriter) GetBytes

            func (lw *LoggingWriter) GetBytes() int64

            func (*LoggingWriter) GetCode

            func (lw *LoggingWriter) GetCode() int

            func (*LoggingWriter) Header

            func (lw *LoggingWriter) Header() http.Header

            func (*LoggingWriter) Hijack

            func (lw *LoggingWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

            func (*LoggingWriter) Write

            func (lw *LoggingWriter) Write(data []byte) (count int, err error)

            func (*LoggingWriter) WriteHeader

            func (lw *LoggingWriter) WriteHeader(code int)

            type Options

            type Options struct {
            
            	// Prefix for application log entries. Primarily used to be
            	// able to select between access log and application log
            	// entries.
            	ApplicationLogPrefix string
            
            	// Output for the application log entries, when nil,
            	// os.Stderr is used.
            	ApplicationLogOutput io.Writer
            
            	// When set, log in JSON format is used
            	ApplicationLogJSONEnabled bool
            
            	// ApplicationLogJsonFormatter, when set and JSON logging is enabled, is passed along to to the underlying
            	// Logrus logger for application logs. To enable structured logging, use ApplicationLogJSONEnabled.
            	ApplicationLogJsonFormatter *logrus.JSONFormatter
            
            	// Output for the access log entries, when nil, os.Stderr is
            	// used.
            	AccessLogOutput io.Writer
            
            	// When set, log in JSON format is used
            	AccessLogJSONEnabled bool
            
            	// AccessLogStripQuery, when set, causes the query strings stripped
            	// from the request URI in the access logs.
            	AccessLogStripQuery bool
            
            	// AccessLogJsonFormatter, when set and JSON logging is enabled, is passed along to to the underlying
            	// Logrus logger for access logs. To enable structured logging, use AccessLogJSONEnabled.
            	AccessLogJsonFormatter *logrus.JSONFormatter
            }

              Init options for logging.

              Directories

              Path Synopsis