skipper: Index | Files | Directories

package logging

import ""

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

Application Log

The application log uses the logrus package:

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

import log ""

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.


Package Files

access.go doc.go log.go logger.go loggingwriter.go

func Init Uses

func Init(o Options)

Initializes logging.

func LogAccess Uses

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.

type AccessEntry Uses

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 Uses

type DefaultLog struct{}

DefaultLog provides a default implementation of the Logger interface.

func (*DefaultLog) Debug Uses

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

func (*DefaultLog) Debugf Uses

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

func (*DefaultLog) Error Uses

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

func (*DefaultLog) Errorf Uses

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

func (*DefaultLog) Info Uses

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

func (*DefaultLog) Infof Uses

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

func (*DefaultLog) Warn Uses

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

func (*DefaultLog) Warnf Uses

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

type Logger Uses

type Logger interface {

    // Log with level ERROR

    // Log formatted messages with level ERROR
    Errorf(string, ...interface{})

    // Log with level WARN

    // Log formatted messages with level WARN
    Warnf(string, ...interface{})

    // Log with level INFO

    // Log formatted messages with level INFO
    Infof(string, ...interface{})

    // Log with level DEBUG

    // Log formatted messages with level DEBUG
    Debugf(string, ...interface{})

Logger instances provide custom logging.

type LoggingWriter Uses

type LoggingWriter struct {
    // contains filtered or unexported fields

func NewLoggingWriter Uses

func NewLoggingWriter(writer http.ResponseWriter) *LoggingWriter

func (*LoggingWriter) Flush Uses

func (lw *LoggingWriter) Flush()

func (*LoggingWriter) GetBytes Uses

func (lw *LoggingWriter) GetBytes() int64

func (*LoggingWriter) GetCode Uses

func (lw *LoggingWriter) GetCode() int

func (*LoggingWriter) Header Uses

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

func (*LoggingWriter) Hijack Uses

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

func (*LoggingWriter) Write Uses

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

func (*LoggingWriter) WriteHeader Uses

func (lw *LoggingWriter) WriteHeader(code int)

type Options Uses

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

    // 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

Init options for logging.



Package logging imports 11 packages (graph) and is imported by 19 packages. Updated 2020-01-20. Refresh now. Tools for package owners.