logger

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2020 License: Apache-2.0 Imports: 3 Imported by: 1,015

Documentation

Overview

Package log provides a log interface

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, l Logger) context.Context

func Register

func Register(logger Logger)

Types

type Encode

type Encode func(*Field) string

type Field

type Field struct {
	Key    string
	Type   FieldType
	Value  interface{}
	Encode Encode
}

func Bool

func Bool(key string, val bool) Field

func (*Field) GetValue

func (f *Field) GetValue() interface{}

type FieldType

type FieldType uint8
const (
	UnknownType FieldType = iota
	BoolType
	DurationType
	Float64Type
	Float32Type
	Int64Type
	Int32Type
	Int16Type
	Int8Type
	Uint64Type
	Uint32Type
	Uint16Type
	Uint8Type
	StringType
	TimeType
)

preset common types for choosing encoder faster

type Level

type Level int8
const (
	TraceLevel Level = iota - 1
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	PanicLevel
	FatalLevel
)

type Logger

type Logger interface {
	// Init initialises options
	Init(options ...Option) error
	// Level returns the logging level
	Level() Level
	// Log inserts a log entry.  Arguments may be handled in the manner
	// of fmt.Print, but the underlying logger may also decide to handle
	// them differently.
	Log(level Level, v ...interface{})
	// Logf insets a log entry.  Arguments are handled in the manner of
	// fmt.Printf.
	Logf(level Level, format string, v ...interface{})
	// Fields set fields to always be logged
	Fields(fields ...Field) Logger
	// SetLevel updates the logging level.
	SetLevel(Level)
	// String returns the name of logger
	String() string
}

Logger is a generic logging interface

func FromContext

func FromContext(ctx context.Context) (Logger, bool)

func GetLogger

func GetLogger(name string) (Logger, error)

type Option

type Option func(*Options)

Option for load profiles maybe eg. yml micro:

logger:
  name:
  dialect: zap/default/logrus
  zap:
    xxx:
  logrus:
    xxx:

type Options

type Options struct {
	Context context.Context
}

Jump to

Keyboard shortcuts

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