logs

package module
v1.13.13 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 17 Imported by: 50

README

概述

LOGS 是一个 AAC FACTORY 的 LOG 规范。

获取

go get github.com/aacfactory/logs

使用

log, logErr := logs.New(
    logs.WithLevel(logs.DebugLevel),
)
// handle logErr
// print
log.Debug().Caller().With("f1", "f1").With("f2", 2).Message("debug")
log.Info().With("time", time.Now()).Message("info")
log.Warn().Caller().Message("warn")
log.Error().Caller().Cause(errors.New("some error")).Message("error")
// shutdown
shutdownErr := log.Shutdown(context.Background())

压测

BenchmarkLogger_Info-20 1602939   744.5 ns/op   243 B/op  5 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCloseTimeout = errors.New("logs: close time out")
)

Functions

func ConvertToStandardLogger added in v1.13.10

func ConvertToStandardLogger(logger Logger, level Level, withCaller bool) (v *log.Logger)

Types

type Caller added in v1.13.10

type Caller struct {
	Fn   string
	File string
	Line int
}

func (Caller) MarshalJSON added in v1.13.10

func (caller Caller) MarshalJSON() (p []byte, err error)

type ColorableLevelWriterTo added in v1.13.10

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

func (ColorableLevelWriterTo) WriteTo added in v1.13.10

func (lc ColorableLevelWriterTo) WriteTo(writer io.Writer) (int64, error)

type ConsoleWriter added in v1.13.10

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

func (*ConsoleWriter) Close added in v1.13.10

func (writer *ConsoleWriter) Close() (err error)

func (*ConsoleWriter) Write added in v1.13.10

func (writer *ConsoleWriter) Write(entry Entry)

type ConsoleWriterFormatter added in v1.13.10

type ConsoleWriterFormatter int
const (
	TextFormatter ConsoleWriterFormatter = iota
	ColorTextFormatter
	JsonFormatter
)

type ConsoleWriterOutType added in v1.13.10

type ConsoleWriterOutType int
const (
	StdOut ConsoleWriterOutType = iota
	StdErr
	StdMix
)

type Entry added in v1.13.10

type Entry struct {
	Level   Level
	Occur   time.Time
	Message string
	Fields  Fields
	Cause   Error
	Caller  Caller
}

func (Entry) MarshalJSON added in v1.13.10

func (e Entry) MarshalJSON() (p []byte, err error)

type EntryEncoder added in v1.13.10

type EntryEncoder interface {
	Encode(entry Entry) (p []byte)
}

type Error added in v1.0.2

type Error interface {
	json.Marshaler
	Error() string
}

type Event added in v1.1.0

type Event interface {
	Message(message string)
	MessageF(format string, a ...any)
	Cause(err error) Event
	Caller() Event
	CallerWithSkip(skip int) Event
	With(key string, value any) Event
}

type Events added in v1.13.10

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

func (*Events) Get added in v1.13.10

func (events *Events) Get(level Level, fields Fields) (v Event)

func (*Events) Shutdown added in v1.13.10

func (events *Events) Shutdown(ctx context.Context) (err error)

type Field

type Field struct {
	Key   string
	Value any
}

func (Field) MarshalJSON added in v1.13.10

func (field Field) MarshalJSON() (p []byte, err error)

func (Field) ValueBytes added in v1.13.10

func (field Field) ValueBytes() (p []byte)

type Fields added in v1.13.10

type Fields []Field

func (Fields) Add added in v1.13.10

func (fields Fields) Add(key string, value any) Fields

func (Fields) MarshalJSON added in v1.13.10

func (fields Fields) MarshalJSON() (p []byte, err error)

type JsonEntryEncoder added in v1.13.10

type JsonEntryEncoder struct {
}

func (*JsonEntryEncoder) Encode added in v1.13.10

func (encoder *JsonEntryEncoder) Encode(entry Entry) (p []byte)

type Level added in v1.1.0

type Level int
const (
	DebugLevel Level = iota + 1
	InfoLevel
	WarnLevel
	ErrorLevel
)

func (Level) Bytes added in v1.13.10

func (level Level) Bytes() []byte

func (Level) ColorableLevelWriterTo added in v1.13.10

func (level Level) ColorableLevelWriterTo() (w io.WriterTo)

func (Level) MarshalJSON added in v1.13.10

func (level Level) MarshalJSON() ([]byte, error)

func (Level) String added in v1.13.10

func (level Level) String() string

type Logger added in v1.1.0

type Logger interface {
	With(key string, value any) Logger
	DebugEnabled() (ok bool)
	Debug() (event Event)
	InfoEnabled() (ok bool)
	Info() (event Event)
	WarnEnabled() (ok bool)
	Warn() (event Event)
	ErrorEnabled() (ok bool)
	Error() (event Event)
	Shutdown(ctx context.Context) (err error)
}

func New added in v1.0.1

func New(options ...Option) (log Logger, err error)

type Option added in v1.1.0

type Option = func(options *Options) (err error)

func DisableConsoleWriter added in v1.13.10

func DisableConsoleWriter() Option

func WithBuffer added in v1.13.10

func WithBuffer(size int) Option

func WithConsoleWriterFormatter added in v1.13.10

func WithConsoleWriterFormatter(formatter ConsoleWriterFormatter) Option

func WithConsoleWriterOutType added in v1.13.10

func WithConsoleWriterOutType(typ ConsoleWriterOutType) Option

func WithConsumes added in v1.13.10

func WithConsumes(consumes int) Option

func WithLevel added in v1.1.0

func WithLevel(value Level) Option

func WithSendTimeout added in v1.13.10

func WithSendTimeout(timeout time.Duration) Option

func WithShutdownTimeout added in v1.13.10

func WithShutdownTimeout(timeout time.Duration) Option

func WithTimeoutDiscardLevel added in v1.13.10

func WithTimeoutDiscardLevel(value Level) Option

func WithWriter added in v1.13.10

func WithWriter(writers ...Writer) Option

type Options added in v1.1.0

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

type Sink added in v1.13.10

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

func (*Sink) Emit added in v1.13.10

func (sink *Sink) Emit(entry Entry)

func (*Sink) Listen added in v1.13.10

func (sink *Sink) Listen()

func (*Sink) Shutdown added in v1.13.10

func (sink *Sink) Shutdown(ctx context.Context) (err error)

type TextEntryEncoder added in v1.13.10

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

func (*TextEntryEncoder) Encode added in v1.13.10

func (encoder *TextEntryEncoder) Encode(entry Entry) (p []byte)

type Timers added in v1.13.10

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

func NewTimers added in v1.13.10

func NewTimers() *Timers

func (*Timers) Get added in v1.13.10

func (timers *Timers) Get(d time.Duration) (timer *time.Timer)

func (*Timers) Put added in v1.13.10

func (timers *Timers) Put(timer *time.Timer)

type Writer added in v1.1.0

type Writer interface {
	Write(entry Entry)
	Close() (err error)
}

func NewConsoleWriter added in v1.13.10

func NewConsoleWriter(formatter ConsoleWriterFormatter, out ConsoleWriterOutType) (w Writer)

Jump to

Keyboard shortcuts

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