log

package
v0.0.0-...-d32eb86 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyRequestID string = "requestID"
	KeyUsername  string = "username"
)

Variables

View Source
var (
	DebugLevel = zapcore.DebugLevel
	InfoLevel  = zapcore.InfoLevel
	WarnLevel  = zapcore.WarnLevel
	ErrorLevel = zapcore.ErrorLevel
	PanicLevel = zapcore.PanicLevel
	FatalLevel = zapcore.FatalLevel
)
View Source
var (
	Any         = zap.Any
	Array       = zap.Array
	Object      = zap.Object
	Binary      = zap.Binary
	Bool        = zap.Bool
	Bools       = zap.Bools
	ByteString  = zap.ByteString
	ByteStrings = zap.ByteStrings
	Complex64   = zap.Complex64
	Complex64s  = zap.Complex64s
	Complex128  = zap.Complex128
	Complex128s = zap.Complex128s
	Duration    = zap.Duration
	Durations   = zap.Durations
	Err         = zap.Error
	Errors      = zap.Errors
	Float32     = zap.Float32
	Float32s    = zap.Float32s
	Float64     = zap.Float64
	Float64s    = zap.Float64s
	Int         = zap.Int
	Ints        = zap.Ints
	Int8        = zap.Int8
	Int8s       = zap.Int8s
	Int16       = zap.Int16
	Int16s      = zap.Int16s
	Int32       = zap.Int32
	Int32s      = zap.Int32s
	Int64       = zap.Int64
	Int64s      = zap.Int64s
	Namespace   = zap.Namespace
	Reflect     = zap.Reflect
	Stack       = zap.Stack
	String      = zap.String
	Stringer    = zap.Stringer
	Strings     = zap.Strings
	Time        = zap.Time
	Times       = zap.Times
	Uint        = zap.Uint
	Uints       = zap.Uints
	Uint8       = zap.Uint8
	Uint8s      = zap.Uint8s
	Uint16      = zap.Uint16
	Uint16s     = zap.Uint16s
	Uint32      = zap.Uint32
	Uint32s     = zap.Uint32s
	Uint64      = zap.Uint64
	Uint64s     = zap.Uint64s
	Uintptr     = zap.Uintptr
	Uintptrs    = zap.Uintptrs
)

Functions

func Debug

func Debug(msg string, fields ...Field)

func Debugf

func Debugf(format string, v ...interface{})

func Debugw

func Debugw(msg string, kv ...interface{})

func Error

func Error(msg string, fields ...Field)

func Errorf

func Errorf(format string, v ...interface{})

func Errorw

func Errorw(msg string, kv ...interface{})

func Fatal

func Fatal(msg string, fields ...Field)

func Fatalf

func Fatalf(format string, v ...interface{})

func Fatalw

func Fatalw(msg string, kv ...interface{})

func Flush

func Flush()

func Info

func Info(msg string, fields ...Field)

func Infof

func Infof(format string, v ...interface{})

func Infow

func Infow(msg string, kv ...interface{})

func Init

func Init(opts *Options)

func LoggerErr

func LoggerErr() *log.Logger

ErrLogger creates and returns a standard library *log.Logger instance that logs at the ErrorLevel in zap. If the global logger is not initialized, it safely returns nil.

func LoggerInfo

func LoggerInfo() *log.Logger

InfoLogger creates and returns a standard library *log.Logger instance that logs at the InfoLevel in zap. If the global logger is not initialized, it returns nil.

func LoggerSugared

func LoggerSugared() *zap.SugaredLogger

SugaredLogger returns a *zap.SugaredLogger instance, offering a more flexible logging approach. This logger supports fast and loosely-typed logging, suitable for most use cases.

func New

func New(opts *Options) *zapLogger

New create logger by opts which can custmoized by command arguments.

func Panic

func Panic(msg string, fields ...Field)

func Panicf

func Panicf(format string, v ...interface{})

func Panicw

func Panicw(msg string, kv ...interface{})

func Record

func Record(ctx context.Context) *zapLogger

func StdInfoLogger

func StdInfoLogger() *log.Logger

StdInfoLogger returns logger of standard library which writes to supplied zap logger at info level.

func Warn

func Warn(msg string, fields ...Field)

func Warnf

func Warnf(format string, v ...interface{})

func Warnw

func Warnw(msg string, kv ...interface{})

Types

type Field

type Field = zapcore.Field

type InfoLogger

type InfoLogger interface {
	Info(msg string, fields ...Field)
	Infof(format string, v ...interface{})
	Infokv(msg string, kv ...interface{})
	Enabled() bool
}

func LoggerForLevel

func LoggerForLevel(level Level) InfoLogger

LoggerForLevel returns a logger for the specified logging level.

type Level

type Level = zapcore.Level

type Logger

type Logger interface {
	InfoLogger
	Debug(msg string, fields ...Field)
	Debugf(format string, v ...interface{})
	Debugkv(msg string, kv ...interface{})
	Warn(msg string, fields ...Field)
	Warnf(format string, v ...interface{})
	Warnkv(msg string, kv ...interface{})
	Error(msg string, fields ...Field)
	Errorf(format string, v ...interface{})
	Errorkv(msg string, kv ...interface{})
	Panic(msg string, fields ...Field)
	Panicf(format string, v ...interface{})
	Panickv(msg string, kv ...interface{})
	Fatal(msg string, fields ...Field)
	Fatalf(format string, v ...interface{})
	Fatalkv(msg string, kv ...interface{})

	LoggerForLevel(level zapcore.Level) InfoLogger
	Write(p []byte) (n int, err error)

	WithValues(kv ...interface{}) Logger

	WithName(name string) Logger

	WithContext(ctx context.Context) context.Context

	Sync()
}

func NewLogger

func NewLogger(l *zap.Logger) Logger

func WithName

func WithName(s string) Logger

func WithValues

func WithValues(kv ...interface{}) Logger

type Options

type Options struct {
	Level             string   `json:"level"              mapstructure:"level"`
	Format            string   `json:"format"             mapstructure:"format"`
	DisableCaller     bool     `json:"disable-caller"     mapstructure:"disable-caller"`
	DisableStacktrace bool     `json:"disable-stacktrace" mapstructure:"disable-stacktrace"`
	EnableColor       bool     `json:"enable-color"       mapstructure:"enable-color"`
	Development       bool     `json:"development"        mapstructure:"development"`
	Name              string   `json:"name"               mapstructure:"name"`
	OutputPaths       []string `json:"output-paths"       mapstructure:"output-paths"`
	ErrorOutputPaths  []string `json:"error-output-paths" mapstructure:"error-output-paths"`
}

func NewOptions

func NewOptions() *Options

NewOptions creates a new instance of Options with default values.

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

AddFlags adds logging-related command line flags to the provided FlagSet. This allows the configuration of the logging system via command line parameters.

func (*Options) Build

func (o *Options) Build() error

Build constructs and configures a global zap logger based on the Options settings. It sets up the logger with the specified level, format, output paths, and other configurations.

func (*Options) String

func (o *Options) String() string

String returns a JSON string representation of the Options. It is useful for logging and debugging purposes.

func (*Options) Validate

func (o *Options) Validate() []error

Validate checks the validity of the Options configuration. It ensures that the log level and format are set correctly.

Jump to

Keyboard shortcuts

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