logger

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 7 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Out:            os.Stdout,
	Level:          TraceLevel,
	TimeFormat:     time.RFC3339Nano,
	SkipFrameCount: 3,
	Fields:         make(map[string]interface{}),
	Context:        context.Background(),
}

DefaultOptions は デフォルトのオプションを提供します。

Functions

This section is empty.

Types

type Level

type Level = zerolog.Level

Level defines log levels.

const (
	// DebugLevel defines debug log level.
	DebugLevel Level = zerolog.DebugLevel
	// InfoLevel defines info log level.
	InfoLevel Level = zerolog.InfoLevel
	// WarnLevel defines warn log level.
	WarnLevel Level = zerolog.WarnLevel
	// ErrorLevel defines error log level.
	ErrorLevel Level = zerolog.ErrorLevel
	// FatalLevel defines fatal log level.
	FatalLevel Level = zerolog.FatalLevel
	// PanicLevel defines panic log level.
	PanicLevel Level = zerolog.PanicLevel
	// NoLevel defines an absent log level.
	NoLevel Level = zerolog.NoLevel
	// Disabled disables the logger.
	Disabled Level = zerolog.Disabled

	// TraceLevel defines trace log level.
	TraceLevel Level = zerolog.TraceLevel
)

func ParseLevel added in v0.4.0

func ParseLevel(level string) Level

ParseLevel は指定された文字列から Level を生成します。

type Logger

type Logger struct {
	*zerolog.Logger
	// contains filtered or unexported fields
}

Logger は logger の定義です。

Example
l := New(
	WithOutput(os.Stdout),
	WithTimeFormat(time.RFC3339Nano),
	WithLevel(InfoLevel),
	WithSkipFrameCount(3),
).WithFields(map[string]interface{}{
	"request_id": "request_id",
	"user":       "alice",
})

l.Debugf("%s", "string")
l.Infof("%s", "string")
l.Warnf("%s", "string")
l.Errorf("%s", "string")
Output:
{"level":"info","request_id":"request_id","user":"alice","time":"0001-01-01T00:00:00Z","caller":"file:123","message":"string"}
{"level":"warn","request_id":"request_id","user":"alice","time":"0001-01-01T00:00:00Z","caller":"file:123","message":"string"}
{"level":"error","request_id":"request_id","user":"alice","time":"0001-01-01T00:00:00Z","caller":"file:123","message":"string"}

func New

func New(opts ...Option) *Logger

New は logger を生成します。

func (Logger) Clone

func (l Logger) Clone(v ...interface{}) *Logger

Clone は logger を複製します。

func (Logger) Debug

func (l Logger) Debug(v ...interface{})

Debug は DEBUG レベルのログを出力します。

func (Logger) Debugf

func (l Logger) Debugf(format string, args ...interface{})

Debugf は DEBUG レベルのログを出力します。

func (Logger) Error

func (l Logger) Error(v ...interface{})

Error は ERROR レベルのログを出力します。

func (Logger) Errorf

func (l Logger) Errorf(format string, args ...interface{})

Errorf は ERROR レベルのログを出力します。

func (Logger) Info

func (l Logger) Info(v ...interface{})

Info は INFO レベルのログを出力します。

func (Logger) Infof

func (l Logger) Infof(format string, args ...interface{})

Infof は INFO レベルのログを出力します。

func (Logger) Trace

func (l Logger) Trace(v ...interface{})

Trace は TRACE レベルのログを出力します。

func (Logger) Tracef

func (l Logger) Tracef(format string, args ...interface{})

Tracef は TRACE レベルのログを出力します。

func (Logger) Warn

func (l Logger) Warn(v ...interface{})

Warn は WARN レベルのログを出力します。

func (Logger) Warnf

func (l Logger) Warnf(format string, args ...interface{})

Warnf は WARN レベルのログを出力します。

func (Logger) WithFields

func (l Logger) WithFields(fields map[string]interface{}) *Logger

WithFields は fields をログに含む logger を複製します。

type Option

type Option func(*Options)

Option は Options を更新するための func の定義です。

func WithFields

func WithFields(fields map[string]interface{}) Option

WithFields は logger に fields を設定します。

func WithLevel

func WithLevel(level Level) Option

WithLevel は logger の level を設定します。

func WithOutput

func WithOutput(out io.Writer) Option

WithOutput は output 用の writer を設定します。

func WithSkipFrameCount

func WithSkipFrameCount(sfc int) Option

WithSkipFrameCount は logger に caller の skip frame count を設定します。

func WithTimeFormat

func WithTimeFormat(timeFormat string) Option

WithTimeFormat は time format を設定します。

type Options

type Options struct {
	Out            io.Writer
	Level          Level
	TimeFormat     string
	SkipFrameCount int
	Fields         map[string]interface{}
	Context        context.Context
}

Options は logger 生成時に設定するオプションの定義です。

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions は opts をもとに Options を生成します。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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