ech0

package module
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

README

Ech0

GoDoc Build Status Go Report Card Issues

Ech0 (pronounced "echo zero") is a logging adapter for echo.Logger that uses github.com/rs/zerolog as the logging backend instead of the default github.com/labstack/gommon/log

Why?

  1. I like Echo.
  2. I like zerolog.
  3. I wanted to have one logging backend in my Echo apps.

Installing

go get -u github.com/rickb777/ech0

Benchmarks

goos: linux
goarch: amd64
pkg: github.com/rickb777/ech0
BenchmarkZeroFormat-8     	 2104641	       570 ns/op	      21 B/op	       2 allocs/op
BenchmarkZeroJSON-8       	 1260433	       911 ns/op	     520 B/op	       2 allocs/op
BenchmarkZero-8           	 2198152	       563 ns/op	      21 B/op	       2 allocs/op
BenchmarkGommonFormat-8   	  563232	      2078 ns/op	     464 B/op	      12 allocs/op
BenchmarkGommonJSON-8     	  517410	      2667 ns/op	     688 B/op	      16 allocs/op
BenchmarkGommon-8         	  558044	      2121 ns/op	     464 B/op	      12 allocs/op
PASS

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

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

Log wraps a zerolog.Logger to provide an `echo.Logger` implementation

func New

func New(out io.Writer, prefix string, z ...Zero) *Log

New returns a new Log instance with the given output. Pass in your own zerolog logger if required. No prefix is set; use SetPrefix if required.

func (Log) Debug

func (l Log) Debug(i ...interface{})

Debug satisfies the echo.Logger interface

func (Log) Debugf

func (l Log) Debugf(format string, i ...interface{})

Debugf satisfies the echo.Logger interface

func (Log) Debugj

func (l Log) Debugj(j log.JSON)

Debugj satisfies the echo.Logger interface

func (Log) Error

func (l Log) Error(i ...interface{})

Error satisfies the echo.Logger interface

func (Log) Errorf

func (l Log) Errorf(format string, i ...interface{})

Errorf satisfies the echo.Logger interface

func (Log) Errorj

func (l Log) Errorj(j log.JSON)

Errorj satisfies the echo.Logger interface

func (Log) Fatal

func (l Log) Fatal(i ...interface{})

Fatal satisfies the echo.Logger interface

func (Log) Fatalf

func (l Log) Fatalf(format string, i ...interface{})

Fatalf satisfies the echo.Logger interface

func (Log) Fatalj

func (l Log) Fatalj(j log.JSON)

Fatalj satisfies the echo.Logger interface

func (Log) Info

func (l Log) Info(i ...interface{})

Info satisfies the echo.Logger interface

func (Log) Infof

func (l Log) Infof(format string, i ...interface{})

Infof satisfies the echo.Logger interface

func (Log) Infoj

func (l Log) Infoj(j log.JSON)

Infoj satisfies the echo.Logger interface

func (Log) Level

func (l Log) Level() log.Lvl

Level satisfies the echo.Logger interface

func (Log) Output

func (l Log) Output() io.Writer

Output satisfies the echo.Logger interface

func (Log) Panic

func (l Log) Panic(i ...interface{})

Panic satisfies the echo.Logger interface

func (Log) Panicf

func (l Log) Panicf(format string, i ...interface{})

Panicf satisfies the echo.Logger interface

func (Log) Panicj

func (l Log) Panicj(j log.JSON)

Panicj satisfies the echo.Logger interface

func (Log) Prefix

func (l Log) Prefix() string

Prefix satisfies the echo.Logger interface

func (Log) Print

func (l Log) Print(i ...interface{})

Print satisfies the echo.Logger interface

func (Log) Printf

func (l Log) Printf(format string, i ...interface{})

Printf satisfies the echo.Logger interface

func (Log) Printj

func (l Log) Printj(j log.JSON)

Printj satisfies the echo.Logger interface

func (*Log) SetCallsite

func (l *Log) SetCallsite(enabled bool)

SetCallsite controls whether file and line numbers are emitted with every log output. Set this true to enable these items.

func (*Log) SetHeader

func (l *Log) SetHeader(h string)

SetHeader satisfies the echo.Logger interface. It does nothing. Within `echo`, this is used to set the template for formatting log messages, but it is not required when using zerolog.

func (*Log) SetLevel

func (l *Log) SetLevel(v log.Lvl)

SetLevel satisfies the echo.Logger interface

func (*Log) SetOutput

func (l *Log) SetOutput(w io.Writer)

SetOutput satisfies the echo.Logger interface

func (*Log) SetPrefix

func (l *Log) SetPrefix(prefix string)

SetPrefix satisfies the echo.Logger interface. Not implemented: this is a no-op.

func (Log) Warn

func (l Log) Warn(i ...interface{})

Warn satisfies the echo.Logger interface

func (Log) Warnf

func (l Log) Warnf(format string, i ...interface{})

Warnf satisfies the echo.Logger interface

func (Log) Warnj

func (l Log) Warnj(j log.JSON)

Warnj satisfies the echo.Logger interface

type Zero

type Zero interface {
	// Log starts a new message with no level. Setting GlobalLevel to Disabled
	// will still disable events produced by this method.
	Log() ZeroEvent
	// Debug starts a new message with debug level.
	Debug() ZeroEvent
	// Info starts a new message with info level.
	Info() ZeroEvent
	// Warn starts a new message with warn level.
	Warn() ZeroEvent
	// Error starts a new message with error level.
	Error() ZeroEvent
	// Fatal starts a new message with fatal level; the program will terminate.
	Fatal() ZeroEvent
	// Panic starts a new message with panic level; there will be a panic.
	Panic() ZeroEvent
	// Err starts a new message with error level with err as a field if not nil or
	// with info level if err is nil.
	Err(err error) ZeroEvent
	// WithLevel starts a new message with level. Unlike Fatal and Panic
	// methods, WithLevel does not terminate the program or stop the ordinary
	// flow of a gourotine when used with their respective levels.
	//
	// You must call Msg on the returned event in order to send the event.
	WithLevel(level zerolog.Level) ZeroEvent

	// Output duplicates the current logger and sets w as its output.
	Output(w io.Writer) Zero
	// Level creates a child logger with the minimum accepted level set to level.
	Level(lvl zerolog.Level) Zero

	// Str creates a child logger with the field key and with val as a string to the logger context.
	Str(key, val string) Zero
	// Int creates a child logger with the field key and with val as an int to the logger context.
	Int(key string, val int) Zero
	// RawJSON creates a child logger with the field key with val as already encoded JSON to context.
	//
	// No sanity check is performed on b; it must not contain carriage returns and be valid JSON.
	RawJSON(key string, b []byte) Zero
	// Timestamp adds the current local time as UNIX timestamp to the logger context with the "time" key.
	// To customize the key name, change zerolog.TimestampFieldName.
	//
	// NOTE: It won't dedupe the "time" key if the internal context has one already.
	Timestamp() Zero
}

Zero mimics a zerolog.Logger. It excludes Trace because it is a non-requirement here.

func Wrap

func Wrap(z zerolog.Logger) Zero

Wrap wraps an existing logger.

type ZeroEvent

type ZeroEvent interface {
	Send()
	Msg(string)
	Msgf(format string, v ...interface{})

	AnErr(key string, val error) ZeroEvent
	Bool(key string, val bool) ZeroEvent
	Bools(key string, b []bool) ZeroEvent
	Bytes(key string, val []byte) ZeroEvent
	Dict(key string, dict ZeroEvent) ZeroEvent
	Dur(key string, val time.Duration) ZeroEvent
	Err(err error) ZeroEvent
	Hex(key string, val []byte) ZeroEvent
	Int(key string, val int) ZeroEvent
	Ints(key string, val []int) ZeroEvent
	Int64(key string, val int64) ZeroEvent
	Interface(key string, val interface{}) ZeroEvent
	Str(key, val string) ZeroEvent
	Strs(key string, val []string) ZeroEvent
	Stringer(key string, val fmt.Stringer) ZeroEvent
	Time(key string, val time.Time) ZeroEvent
	Timestamp() ZeroEvent
	Uint(key string, val uint) ZeroEvent
	Uints(key string, val []uint) ZeroEvent
	Uint64(key string, val uint64) ZeroEvent
}

ZeroEvent mimics the zerolog Event struct.

func Dict added in v3.1.0

func Dict() ZeroEvent

Dict creates an Event to be used with the ZeroEvent.Dict method. Call usual field methods like Str, Int etc to add fields to this event and give it as argument the *Event.Dict method.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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