http

package
v6.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2018 License: MIT Imports: 8 Imported by: 3

Documentation

Overview

Package http allows for log messages to be sent via http.

Example

NOTE: you can use the HTTP handler as a base for creating other handlers

package main

import (
    stdhttp "net/http"

    "github.com/go-playground/log"
    "github.com/go-playground/log/handlers/http"
)

func main() {

    header := make(stdhttp.Header)
    header.Set("Authorization", "Bearer 378978HJJFEWj73JENEWFN3475")

    h, err := http.New("https://logs.logserver.com:4565", "POST", header)
    if err != nil {
        // handle error, most likely URL parsing error
    }

    log.AddHandler(h, log.AllLevels...)

    // Trace
    defer log.WithTrace().Info("took this long")

    log.Debug("debug")
    log.Info("info")
    log.Notice("notice")
    log.Warn("warn")
    log.Error("error")
    // log.Panic("panic") // this will panic
    log.Alert("alert")
    // log.Fatal("fatal") // this will call os.Exit(1)

    // logging with fields can be used with any of the above
    log.WithField("key", "value").Info("test info")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FormatFunc

type FormatFunc func(h *HTTP) Formatter

FormatFunc is the function that the workers use to create a new Formatter per worker allowing reusable go routine safe variable to be used within your Formatter function.

type Formatter

type Formatter func(e log.Entry) []byte

Formatter is the function used to format the HTTP entry

type HTTP

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

HTTP is an instance of the http logger

func New

func New(remoteHost string, method string, header stdhttp.Header) (*HTTP, error)

New returns a new instance of the http logger

func (*HTTP) Headers

func (h *HTTP) Headers() stdhttp.Header

Headers returns the http headers registered to HTTP

func (*HTTP) Log

func (h *HTTP) Log(e log.Entry)

Log handles the log entry

func (*HTTP) Method

func (h *HTTP) Method() string

Method returns http method registered with HTTP

func (*HTTP) RemoteHost

func (h *HTTP) RemoteHost() string

RemoteHost returns the remote host registered to HTTP

func (*HTTP) SetFormatFunc

func (h *HTTP) SetFormatFunc(fn FormatFunc)

SetFormatFunc sets FormatFunc each worker will call to get a Formatter func

func (*HTTP) SetTimestampFormat

func (h *HTTP) SetTimestampFormat(format string)

SetTimestampFormat sets HTTP's timestamp output format Default is : "2006-01-02T15:04:05.000000000Z07:00"

func (*HTTP) TimestampFormat

func (h *HTTP) TimestampFormat() string

TimestampFormat returns HTTP's current timestamp output format

Directories

Path Synopsis
Package hipchat allows for log messages to be sent to a hipchat room.
Package hipchat allows for log messages to be sent to a hipchat room.

Jump to

Keyboard shortcuts

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