log

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package log is the log package based on zap.

Index

Constants

This section is empty.

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
)

Functions

func Debug

func Debug(msg string, keysAndValues ...interface{})

Debug method output debug level log.

func Debugf

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

Debugf method output debug level log.

func Error

func Error(msg string, keysAndValues ...interface{})

Error method output error level log.

func Errorf

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

Errorf method output error level log.

func Fatal

func Fatal(msg string, keysAndValues ...interface{})

Fatal method output Fatalw level log.

func Fatalf

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

Fatalf method output fatal level log.

func Flush

func Flush()

Flush flushes any buffered log entries. Applications should take care to call before exiting.

func Info

func Info(msg string, keysAndValues ...interface{})

Info method output info level log.

func Infof

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

Infof method output info level log.

func Init

func Init(opts *Options)

Init initializes logger with specified options.

func Panic

func Panic(msg string, keysAndValues ...interface{})

Panic method output panic level log.

func Panicf

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

Panicf method output panic level log and shutdown application.

func StdLogger

func StdLogger(level Level) *log.Logger

StdLogger returns logger of standard library which writes to supplied zap logger at specified level.

func Warn

func Warn(msg string, keysAndValues ...interface{})

Warn method output warning level log.

func Warnf

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

Warnf method output warning level log.

func WithContext

func WithContext(ctx context.Context) context.Context

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

Types

type InfoLogger

type InfoLogger interface {
	// Info logs a non-error message with the given key/value pairs as context.
	Info(msg string, keysAndValues ...interface{})
	// Infof logs a non-error format message.
	Infof(format string, v ...interface{})

	// Enabled checks whether this InfoLogger is enabled.
	Enabled() bool
}

InfoLogger represents the ability to log non-error messages, at a particular verbosity.

func V

func V(level Level) InfoLogger

V return a leveled InfoLogger.

type Level

type Level = zapcore.Level

Level is an alias for the level structure in the underlying log frame.

type Logger

type Logger interface {
	// InfoLogger All Loggers implement InfoLogger.  Calling InfoLogger methods directly on
	// a Logger value is equivalent to calling them on a V(0) InfoLogger.  For
	// example, logger.Info() produces the same result as logger.V(0).Info.
	InfoLogger

	Debug(msg string, keysAndValues ...interface{})
	Debugf(format string, v ...interface{})
	Warn(msg string, keysAndValues ...interface{})
	Warnf(format string, v ...interface{})
	Error(msg string, keysAndValues ...interface{})
	Errorf(format string, v ...interface{})
	Panic(msg string, keysAndValues ...interface{})
	Panicf(format string, v ...interface{})
	Fatal(msg string, keysAndValues ...interface{})
	Fatalf(format string, v ...interface{})

	// V returns an InfoLogger value for a specific verbosity level.
	V(level Level) InfoLogger

	// WithValues adds some key-value pairs of context to a logger.
	WithValues(keysAndValues ...interface{}) Logger
	// WithContext returns a copy of context in which the log value is set.
	WithContext(ctx context.Context) context.Context

	// Flush flushes any buffered log entries. Applications should take care to call before exiting.
	Flush()
}

Logger represents the ability to log messages, both errors and not.

func FromContext

func FromContext(ctx context.Context) Logger

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

func New

func New(opts *Options) Logger

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

func WithValues

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

WithValues creates a child logger and adds extra key-values to it.

type Options

type Options struct {
	OutputPaths       []string `json:"output-paths"       mapstructure:"output-paths"`
	ErrorOutputPaths  []string `json:"error-output-paths" mapstructure:"error-output-paths"`
	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"`
	Name              string   `json:"name"               mapstructure:"name"`
}

Options contains configuration items related to log.

func NewOptions

func NewOptions() *Options

NewOptions creates an Options object with default parameters.

func (*Options) AddFlags

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

AddFlags adds flags for log to the specified FlagSet object.

func (*Options) String

func (o *Options) String() string

func (*Options) Validate

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

Validate validates the options fields.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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