logging

package
v0.9.173 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2018 License: Apache-2.0, MIT Imports: 9 Imported by: 0

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.

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)

Logs an access event in Apache combined log format (with a minor customization with the duration).

func NewHandler

func NewHandler(next http.Handler) http.Handler

NewHandler creates an http.Handler that provides access log for the underlying handler.

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

	// Output for the access log entries, when nil, os.Stderr is
	// used.
	AccessLogOutput io.Writer

	// When set, no access log is printed.
	AccessLogDisabled bool

	// When set, log in JSON format is used
	AccessLogJSONEnabled bool
}

Init options for logging.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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