rollinglog

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

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

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
)

Alias for za type functions.

Functions

func CheckIntLevel

func CheckIntLevel(level int32) bool

CheckIntLevel used for other log wrapper such as klog, which return if logging a message at the specified level is enabled.

func Debug

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

Debug method output debug level log.

func Debugf

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

Debugf method output debug level log.

func Debugw

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

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 ...interface{})

Errorf method output error level log.

func Errorw

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

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 ...interface{})

Fatalf method output fatal level log.

func Fatalw

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

Fatalw method output Fatalw level log.

func Flush

func Flush()

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

func Info

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

Info method output info level log.

func Infof

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

Infof method output info level log.

func Infow

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

Infow method output info level log.

func Init

func Init(opts *Options)

func L

func L(ctx context.Context) *zapLogger

L method output with specified context value.

func New

func New(opts *Options) *zapLogger

func Panic

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

Panic method output panic level log and shutdown application.

func Panicf

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

Panicf method output panic level log and shutdown application.

func Panicw

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

Panicw method output panic level log.

func StdErrLogger

func StdErrLogger() *log.Logger

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

func StdInfoLogger

func StdInfoLogger() *log.Logger

StdInfoLogger returns logger of standard library, which write s to supplied zap logger at info level.

func SugaredLogger

func SugaredLogger() *zap.SugaredLogger

SugaredLogger returns global sugared logger.

func Warn

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

Warn method output warning level log.

func Warnf

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

Warnf method output warning level log.

func Warnw

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

Warnw method output warning level log.

func WithContext

func WithContext(ctx context.Context) context.Context

func ZapLogger

func ZapLogger() *zap.Logger

ZapLogger used for other log wrapper such as klog.

Types

type Field

type Field = zapcore.Field

type InfoLogger

type InfoLogger interface {
	Info(msg string, fields ...Field)
	Infof(format string, val ...interface{})
	Infow(msg string, keysAndValues ...interface{})

	Enabled() bool
}

func V

func V(level Level) InfoLogger

V return a leveled InfoLogger.

type Level

type Level = zapcore.Level

type Logger

type Logger interface {
	InfoLogger

	Debug(msg string, fields ...Field)
	Debugf(format string, val ...interface{})
	Debugw(msg string, keysAndValues ...interface{})
	Warn(msg string, fields ...Field)
	Warnf(format string, v ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Error(msg string, fields ...Field)
	Errorf(format string, v ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Panic(msg string, fields ...Field)
	Panicf(format string, v ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	Fatal(msg string, fields ...Field)
	Fatalf(format string, v ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})

	V(level Level) InfoLogger

	Write(p []byte) (n int, err error)
	WithValues(keysAndValues ...interface{}) Logger
	WithName(name string) Logger
	WithContext(ctx context.Context) context.Context

	Flush()
}

func FromContext

func FromContext(ctx context.Context) Logger

func NewLogger

func NewLogger(l *zap.Logger) Logger

NewLogger creates a new logr.Logger using the given Zap Logger to log.

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.

func WithValues

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

WithValues creates a child logger and adds adds Zap fields 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"`
	EnableColor      bool     `json:"enable-color"       mapstructure:"enable-color"`
	Development      bool     `json:"development"        mapstructure:"development"`
	Name             string   `json:"name"               mapstructure:"name"`

	Rolling           bool `json:"rolling" mapstructure:"rolling"`
	RollingMaxSize    int  `json:"rolling-max-size" mapstructure:"rolling-max-size"`
	RollingMaxAge     int  `json:"rolling-max-age" mapstructure:"rolling-max-age"`
	RollingMaxBackups int  `json:"rolling-max-backups" mapstructure:"rolling-max-backups"`
	RollingLocalTime  bool `json:"rolling-local-time" mapstructure:"rolling-local-time"`
	RollingCompress   bool `json:"rolling-compress" mapstructure:"rolling-compress"`
}

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 the options fields.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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