log

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: MIT Imports: 5 Imported by: 0

README

log

Zap-based logging

Example

package main

import "github.com/coinrust/log"

func init() {
	log.Init("./test.log",
		log.DebugLevel,
		log.SetCaller(true),
		log.SetStdout(true))
}

func main() {
	defer log.Sync()

	log.Infof("%v", "hello")
}

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug 使用方法:log.Debug("test")

func Debugf

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

Debugf 使用方法:log.Debugf("test:%s", err)

func Debugw

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

Debugw 使用方法:log.Debugw("test", "field1", "value1", "field2", "value2")

func Error

func Error(args ...interface{})

func Errorf

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

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

func Info

func Info(args ...interface{})

func Infof

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

func Infow

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

func Init

func Init(path, level string, options ...Option)

Init init logger

func Panic

func Panic(args ...interface{})

func Panicf

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

func Panicw

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

func Sync

func Sync()

Sync flushes buffer, if any

func Warn

func Warn(args ...interface{})

func Warnf

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

func Warnw

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

Types

type Log

type Log struct {
	Path        string // 文件路径,如:./app.log
	Level       string // 日志输出的级别
	MaxFileSize int    // 日志文件大小的最大值,单位(M)
	MaxBackups  int    // 最多保留备份数
	MaxAge      int    // 日志文件保存的时间,单位(天)
	Compress    bool   // 是否压缩
	Caller      bool   // 日志是否需要显示调用位置
	Stdout      bool   // 是否输出到控制台
	// contains filtered or unexported fields
}

func NewZapAdapter

func NewZapAdapter(path, level string) *Log

func (*Log) Build

func (l *Log) Build()

func (*Log) DPanic

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

func (*Log) DPanicf

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

func (*Log) DPanicw

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

func (*Log) Debug

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

func (*Log) Debugf

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

func (*Log) Debugw

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

func (*Log) Error

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

func (*Log) Errorf

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

func (*Log) Errorw

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

func (*Log) Fatal

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

func (*Log) Fatalf

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

func (*Log) Fatalw

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

func (*Log) Info

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

func (*Log) Infof

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

func (*Log) Infow

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

func (*Log) Panic

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

func (*Log) Panicf

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

func (*Log) Panicw

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

func (*Log) Warn

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

func (*Log) Warnf

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

func (*Log) Warnw

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

type Option

type Option func(log *Log)

func SetCaller

func SetCaller(caller bool) Option

func SetCompress

func SetCompress(compress bool) Option

func SetMaxAge

func SetMaxAge(age int) Option

func SetMaxBackups

func SetMaxBackups(n int) Option

func SetMaxFileSize

func SetMaxFileSize(size int) Option

func SetStdout

func SetStdout(b bool) Option

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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