log

package module
v0.0.0-...-9290746 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2016 License: MIT Imports: 4 Imported by: 0

README

log Build Status GoDoc Coverage Status Go Report Card

Structured, versatile, hierarchical logging layer for vinxi's components.

Built on top of Logrus.

Installation

go get -u gopkg.in/vinxi/log.v0

API

See godoc reference.

Example

Basic logging in middleware handlers
package main

import (
  "fmt"
  "net/http"

  "gopkg.in/vinxi/log.v0"
  "gopkg.in/vinxi/vinxi.v0"
)

const port = 3100

func main() {
  // Create a new vinxi proxy
  vs := vinxi.NewServer(vinxi.ServerOptions{Port: port})

  // Plugin multiple middlewares writting some logs
  vs.Use(func(w http.ResponseWriter, r *http.Request, h http.Handler) {
    log.Infof("[%s] %s", r.Method, r.RequestURI)
    h.ServeHTTP(w, r)
  })

  vs.Use(func(w http.ResponseWriter, r *http.Request, h http.Handler) {
    log.Warnf("%s", "foo bar")
    h.ServeHTTP(w, r)
  })

  // Target server to forward
  vs.Forward("http://httpbin.org")

  fmt.Printf("Server listening on port: %d\n", port)
  err := vs.Listen()
  if err != nil {
    fmt.Errorf("Error: %s\n", err)
  }
}

License

MIT

Documentation

Overview

Package log implements a featured and structured generic logger interface designed to be used in core and third-party vinxi components.

Index

Constants

View Source
const Version = "0.1.0"

Version defines the current package semantic version.

Variables

View Source
var Logger = log.New()

Logger represents the standard default built-in logger (equivalent to default Logrus logger).

Functions

func AddHook

func AddHook(hook log.Hook)

AddHook adds a hook to the standard logger hooks.

func Debug

func Debug(msg string)

Debug level message.

func Debugf

func Debugf(msg string, v ...interface{})

Debugf level formatted message.

func Error

func Error(msg string)

Error level message.

func Errorf

func Errorf(msg string, v ...interface{})

Errorf level formatted message.

func Fatal

func Fatal(msg string)

Fatal level message, followed by an exit.

func Fatalf

func Fatalf(msg string, v ...interface{})

Fatalf level formatted message, followed by an exit.

func GetLevel

func GetLevel() log.Level

GetLevel returns the standard logger level.

func Info

func Info(msg string)

Info level message.

func Infof

func Infof(msg string, v ...interface{})

Infof level formatted message.

func New

func New() *log.Logger

New creates a new Logrus based logger.

func SetFormatter

func SetFormatter(formatter log.Formatter)

SetFormatter sets the standard logger formatter.

func SetLevel

func SetLevel(level log.Level)

SetLevel sets the standard logger level.

func SetOutput

func SetOutput(out io.Writer)

SetOutput sets the standard logger output.

func Trace

func Trace(msg string) *log.Entry

Trace returns a new entry with a Stop method to fire off a corresponding completion log, useful with defer.

func Warn

func Warn(msg string)

Warn level message.

func Warnf

func Warnf(msg string, v ...interface{})

Warnf level formatted message.

func WithError

func WithError(err error) *log.Entry

WithError returns a new entry with the "error" set to `err`.

func WithField

func WithField(key string, value interface{}) *log.Entry

WithField returns a new entry with the `key` and `value` set.

func WithFields

func WithFields(fields log.Fields) *log.Entry

WithFields returns a new entry with `fields` set.

Types

type Interface

type Interface interface {
	WithFields(fields log.Fields) *log.Entry
	WithField(key string, value interface{}) *log.Entry
	WithError(err error) *log.Entry
	Debug(...interface{})
	Info(...interface{})
	Warn(...interface{})
	Error(...interface{})
	Fatal(...interface{})
	Debugf(msg string, v ...interface{})
	Infof(msg string, v ...interface{})
	Warnf(msg string, v ...interface{})
	Errorf(msg string, v ...interface{})
	Fatalf(msg string, v ...interface{})
}

Interface represents the API of both Logger and Entry.

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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