log

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StdLogOutputPath = "stdout"
	ConsoleFormat    = "console"
	JsonFormat       = "json"
)

Variables

View Source
var (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel = zapcore.DebugLevel
	// InfoLevel is the default logging priority.
	InfoLevel = zapcore.InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel = zapcore.WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel = zapcore.ErrorLevel
	// PanicLevel logs a message, then panics.
	PanicLevel = zapcore.PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	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
)

Alias for zap type functions.

Functions

func DPanic

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

func DPanicf

func DPanicf(format string, v ...any)

func DPanicw

func DPanicw(msg string, keysAndValues ...any)

func Debug

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

Debug method output debug level log.

func Debugf

func Debugf(format string, v ...any)

Debugf method output debug level log.

func Debugw

func Debugw(msg string, keysAndValues ...any)

Debugw method output debug level log.

func Error

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

Error method output error level log.

func Errorf

func Errorf(format string, v ...any)

Errorf method output error level log.

func Errorw

func Errorw(msg string, keysAndValues ...any)

Errorw method output error level log.

func Fatal

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

Fatal method output fatal level log.

func Fatalf

func Fatalf(format string, v ...any)

Fatalf method output fatal level log.

func Fatalln

func Fatalln(msg ...any)

func Fatalw

func Fatalw(msg string, keysAndValues ...any)

Fatalw method output Fatalw level log.

func FromContext

func FromContext(ctx context.Context) *zap.Logger

FromContext returns the value of the log key on the ctx.

func GetLogLevel

func GetLogLevel() zapcore.Level

func Info

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

Info method output info level log.

func Infof

func Infof(format string, v ...any)

Infof method output info level log.

func Infow

func Infow(msg string, keysAndValues ...any)

Infow method output info level log.

func Log

func Log(lvl zapcore.Level, msg string, fields ...Field)

func Panic

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

Panic method output panic level log and shutdown application.

func Panicf

func Panicf(format string, v ...any)

Panicf method output panic level log and shutdown application.

func Panicln

func Panicln(msg ...any)

func Panicw

func Panicw(msg string, keysAndValues ...any)

Panicw method output panic level log.

func Print

func Print(msg ...any)

func Printf

func Printf(format string, v ...any)

func Println

func Println(msg ...any)

func RunProductionMode

func RunProductionMode(logOutputPaths ...string)

func StdErrLogger

func StdErrLogger() *log.Logger

StdErrLogger returns logger of standard library which writes to supplied zap logger at error level.

func StdFromOptions

func StdFromOptions(o *Options)

func StdInfoLogger

func StdInfoLogger() *log.Logger

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

func Sync

func Sync()

Sync calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.

func Warn

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

Warn method output warning level log.

func Warnf

func Warnf(format string, v ...any)

Warnf method output warning level log.

func Warnw

func Warnw(msg string, keysAndValues ...any)

Warnw method output warning level log.

func WithContext

func WithContext(ctx context.Context, l *zap.Logger) context.Context

WithContext returns a copy of context in which the log value is set.

Types

type Field

type Field = zapcore.Field

Field is an alias for the field structure in the underlying log frame.

type Level

type Level = zapcore.Level

type Logger

type Logger = zap.Logger

func Default

func Default() *Logger

func WithKeyAndValues

func WithKeyAndValues(keysAndValues ...Field) *Logger

WithKeyAndValues creates a child logger and adds Zap fields to it.

func WithName

func WithName(s string) *Logger

WithName adds a new path segment to the logger's name. Segments are joined by periods. By default, Loggers are unnamed.

type Options

type Options struct {
	Name string `json:"name"               yaml:"name"`

	OutputPaths []string `json:"output-paths"       yaml:"output-paths"`

	// LogLevel is the minimum enabled logging level.
	LogLevel string `json:"level"              yaml:"level"`

	// Format sets the logger's encoding. Valid values are "json" and "console"
	Format string `json:"format"             yaml:"format"`

	// DisableCaller stops annotating logs with the calling function's file
	// name and line number. By default, all logs are annotated.
	DisableCaller bool `json:"disable-caller"     yaml:"disable-caller"`

	// DisableStacktrace completely disables automatic stacktrace capturing. By
	// default, stacktraces are captured for WarnLevel and above logs in
	// development and ErrorLevel and above in production.
	DisableStacktrace bool `json:"disable-stacktrace" yaml:"disable-stacktrace"`

	// Sampling sets a sampling policy. A nil SamplingConfig disables sampling.
	Sampling *zap.SamplingConfig `json:"sampling" yaml:"sampling"`

	// EnableColor set the logging level color
	EnableColor bool `json:"enable-color"       yaml:"enable-color"`

	// Development puts the logger in development mode, which changes the
	// behavior of DPanicLevel and takes stacktraces more liberally.
	Development bool `json:"development"        yaml:"development"`

	// StacktraceLevel configures the Logger to record a stack trace for all messages at
	// or above a given level.
	StacktraceLevel string `json:"stacktraceLevel"    yaml:"stacktraceLevel"`

	// CallerSkip is the number of callers skipped by caller annotation
	CallerSkip int `json:"callerSkip"         yaml:"callerSkip"`
}

Options contains configuration items related to log.

func NewOptions

func NewOptions(logOutputPaths ...string) *Options

NewOptions creates a new Options object with default parameters.

func NewProductionOptions

func NewProductionOptions(logOutputPaths ...string) *Options

NewProductionOptions creates an Options object in production environment.

func (*Options) AddOutputPath

func (o *Options) AddOutputPath(outputPath ...string)

func (*Options) Build

func (o *Options) Build(redirectStdLog bool) (*Logger, error)

Build constructs a global zap logger with the Options.

func (*Options) SetCallerSkip

func (o *Options) SetCallerSkip(skip int)

func (*Options) SetLogLevel

func (o *Options) SetLogLevel(level string)

func (*Options) SetStacktraceLevel

func (o *Options) SetStacktraceLevel(level string)

func (*Options) String

func (o *Options) String() string

type SugaredLogger

type SugaredLogger = zap.SugaredLogger

Jump to

Keyboard shortcuts

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