log

package
v0.0.0-...-0e6e691 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithLogger

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

WithLogger adds Logger to context

Types

type ContextKey

type ContextKey string
const ContextUserKey ContextKey = "logger"

type Field

type Field struct {
	Key   string
	Value any
}

func Any

func Any(k string, v any) Field

func Error

func Error(v error) Field

type ILog

type ILog interface {
	SetOutput(w io.Writer)
	Output(calldepth int, s string) error
	Printf(format string, v ...any)
	Print(v ...any)
	Println(v ...any)
	Fatal(v ...any)
	Fatalf(format string, v ...any)
	Fatalln(v ...any)
	Panic(v ...any)
	Panicf(format string, v ...any)
	Panicln(v ...any)
	Flags() int
	Prefix() string
	SetPrefix(prefix string)
	Writer() io.Writer
}

std "log" interface

type Level

type Level int64
const (
	Debug Level = iota
	Info
	Warn
)

type Logger

type Logger interface {
	Debug(string, ...Field)
	Info(string, ...Field)
	Warn(string, ...Field)
	Error(string, ...Field)
	Fatal(string, ...Field)
	Panic(string, ...Field)
	SetLevel(Level)
	With(...Field) Logger
}

func Get

func Get() Logger

func GetLogger

func GetLogger(ctx context.Context) Logger

GetLogger extract Logger from context return global so never return nil

func NewDefault

func NewDefault() Logger

func NewNoOpLogger

func NewNoOpLogger() Logger

func NewStdLogger

func NewStdLogger(l Level) Logger

type NoOpLogger

type NoOpLogger struct{}

func (*NoOpLogger) Debug

func (l *NoOpLogger) Debug(string, ...Field)

func (*NoOpLogger) Error

func (l *NoOpLogger) Error(string, ...Field)

func (*NoOpLogger) Fatal

func (l *NoOpLogger) Fatal(string, ...Field)

func (*NoOpLogger) Info

func (l *NoOpLogger) Info(string, ...Field)

func (*NoOpLogger) Panic

func (l *NoOpLogger) Panic(string, ...Field)

func (*NoOpLogger) SetLevel

func (l *NoOpLogger) SetLevel(Level)

func (*NoOpLogger) Warn

func (l *NoOpLogger) Warn(string, ...Field)

func (*NoOpLogger) With

func (l *NoOpLogger) With(...Field) Logger

type StdLogger

type StdLogger struct {
	Level Level
	Log   ILog
	// contains filtered or unexported fields
}

func (*StdLogger) Debug

func (l *StdLogger) Debug(msg string, fields ...Field)

func (*StdLogger) Error

func (l *StdLogger) Error(msg string, fields ...Field)

func (*StdLogger) Fatal

func (l *StdLogger) Fatal(msg string, fields ...Field)

Fatal log and quit

func (*StdLogger) Info

func (l *StdLogger) Info(msg string, fields ...Field)

func (*StdLogger) Panic

func (l *StdLogger) Panic(msg string, fields ...Field)

Panic log and panic

func (*StdLogger) SetLevel

func (l *StdLogger) SetLevel(ll Level)

func (*StdLogger) Warn

func (l *StdLogger) Warn(msg string, fields ...Field)

func (*StdLogger) With

func (l *StdLogger) With(fields ...Field) Logger

With returns copy with appended fields

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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