logger

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugLevel  = "debug"
	InfoLevel   = "info"
	WarnLevel   = "warn"
	ErrorLevel  = "error"
	DPanicLevel = "dpanic"
	PanicLevel  = "panic"
	FatalLevel  = "fatal"
)

Variables

This section is empty.

Functions

func DPanic

func DPanic(args ...interface{})

DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)

func DPanicf

func DPanicf(template string, args ...interface{})

DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)

func DPanicw

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

DPanicw logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With.

func Debug

func Debug(args ...interface{})

Debug uses fmt.Sprint to construct and log a message.

func Debugf

func Debugf(template string, args ...interface{})

Debugf uses fmt.Sprintf to log a templated message.

func Debugw

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

Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

When debug-level logging is disabled, this is much faster than

s.With(keysAndValues).Debug(msg)

func Error

func Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message.

func Errorf

func Errorf(template string, args ...interface{})

Errorf uses fmt.Sprintf to log a templated message.

func Errorw

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

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(template string, args ...interface{})

func Fatalw

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

func Info

func Info(args ...interface{})

Info uses fmt.Sprint to construct and log a message.

func Infof

func Infof(template string, args ...interface{})

Infof uses fmt.Sprintf to log a templated message.

func Infow

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

func Panic

func Panic(args ...interface{})

Panic uses fmt.Sprint to construct and log a message, then panics.

func Panicf

func Panicf(template string, args ...interface{})

Panicf uses fmt.Sprintf to log a templated message, then panics.

func Panicw

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

Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.

func Sync

func Sync() error

Sync flushes any buffered log entries.

func Warn

func Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message.

func Warnf

func Warnf(template string, args ...interface{})

Warnf uses fmt.Sprintf to log a templated message.

func Warnw

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

Types

type Config

type Config struct {
	Level         string // Level 日志等级.
	ConsoleOutput string // 控制台输出流:stdout/stderr,默认是stdout.
	Filename      string // Filename 用于存储日志的文件,可以为空,表示日志不写入文件.
	MaxSize       int    // 单个日志文件最大大小,单位M,
	MaxAge        int    // 日志最大保留时长,单位:天
	MaxBackups    int    // 最大备份数据:份数(如果时间超过了仍然会被删除)
	Compress      bool   // 日志是否开启压缩
	CallerSkip    int    // 报错代码产生跳过层级
}

Config 配置Logger的选项.

type JSONEncoder

type JSONEncoder struct {
	zapcore.Encoder
}

func NewJSONEncoder

func NewJSONEncoder(cfg zapcore.EncoderConfig) *JSONEncoder

func (*JSONEncoder) EncodeEntry

func (j *JSONEncoder) EncodeEntry(ent zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger 日志.

var (
	DefaultLogger *Logger
)

func NewLogger

func NewLogger(opts ...Option) *Logger

NewLogger new Logger instance.

func SetNamed

func SetNamed(name string) *Logger

Named adds a sub-scope to the logger's name. See Logger.Named for details.

func With

func With(args ...interface{}) *Logger

With adds a variadic number of fields to the logging context. It accepts a mix of strongly-typed Field objects and loosely-typed key-value pairs. When processing pairs, the first element of the pair is used as the field key and the second as the field value.

For example,

 Logger.With(
   "hello", "world",
   "failure", errors.New("oh no"),
   Stack(),
   "count", 42,
   "user", User{Name: "alice"},
)

is the equivalent of

unsugared.With(
  String("hello", "world"),
  String("failure", "oh no"),
  Stack(),
  Int("count", 42),
  Object("user", User{Name: "alice"}),
)

Note that the keys in key-value pairs should be strings. In development, passing a non-string key panics. In production, the logger is more forgiving: a separate error is logged, but the key-value pair is skipped and execution continues. Passing an orphaned key triggers similar behavior: panics in development and errors in production.

func (*Logger) DPanic

func (l *Logger) DPanic(args ...interface{})

func (*Logger) DPanicf

func (l *Logger) DPanicf(template string, args ...interface{})

func (*Logger) DPanicw

func (l *Logger) DPanicw(msg string, keysAndValues ...interface{})

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

func (*Logger) Debugf

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

func (*Logger) Debugw

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

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

func (*Logger) Errorf

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

func (*Logger) Errorw

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

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(template string, args ...interface{})

func (*Logger) Fatalw

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

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

func (*Logger) Infof

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

func (*Logger) Infow

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

func (*Logger) Named

func (l *Logger) Named(name string) *Logger

func (*Logger) Panic

func (l *Logger) Panic(args ...interface{})

func (*Logger) Panicf

func (l *Logger) Panicf(template string, args ...interface{})

func (*Logger) Panicw

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

func (*Logger) Sync

func (l *Logger) Sync() error

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

func (*Logger) Warnf

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

func (*Logger) Warnw

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

func (*Logger) With

func (l *Logger) With(args ...interface{}) *Logger

type Option

type Option interface {
	// contains filtered or unexported methods
}

func OptionCallerSkip

func OptionCallerSkip(skip int) Option

func OptionCompress

func OptionCompress(compress bool) Option

func OptionConsoleOutput

func OptionConsoleOutput(consl string) Option

func OptionFilename

func OptionFilename(filename string) Option

func OptionLevel

func OptionLevel(level string) Option

func OptionMaxAge

func OptionMaxAge(maxAge int) Option

func OptionMaxBackups

func OptionMaxBackups(maxBackups int) Option

func OptionMaxSize

func OptionMaxSize(maxSize int) Option

Jump to

Keyboard shortcuts

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