log

package module
v0.0.0-...-f9fd3e8 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

log

base on zap, an easy using logger module

package main

import "github.com/terryliu/log"

func main() {
	// Init用来初始化设置
	// 参数1:设置日志路径
	// 参数2:日志输出的级别
	// 参数3:是否需要另存请求类型的日志
	// 参数4:从这个参数开始就都是回调函数,可以用来设置是否显示Caller
	// 参数5:这里用log.SetMaxFileSize(1)举例,设置日志大小为1MB,默认是1024MB
	log.Init("./test.log", log.DebugLevel, true, log.SetCaller(true), log.SetMaxFileSize(1))
	log.Info("hello 中文日志.")
	//请求数据的日志文件
	log.RequestLogInfow([]string{"key000","val000","k001","v001"})
	// 如果有未输出的日志缓存,就刷新输出,不调用只会异步输出,不保证输出的完整性
	log.Sync()
	/*
	输出:
	{"level":"info","ts":"2020-04-10T22:28:02.904+0800","caller":"example/example.go:15","msg":"hello 中文日志."}
	{"level":"info","ts":"2020-04-10T22:28:02.955+0800","caller":"example/example.go:17","msg":"[key000 val000 k001 v001]"}
	*/
}

Documentation

Index

Constants

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

	FileTypeLog     = "log"
	FileTypeRequest = "request_log"
)

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, needRequestLog bool, options ...LogOption)

Init init logger

func NewZapAdapter

func NewZapAdapter(path, level string) *zapAdapter

func Output

func Output(calldepth int, s string) error

func Panic

func Panic(args ...interface{})

func Panicf

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

func Panicw

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

func Printf

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

func Println

func Println(v ...interface{})

func RequestLogInfow

func RequestLogInfow(keysAndValues ...interface{})

参数keysAndValues为一个切片,元素1为key,元素2为val;以此类推.

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
	Level          string
	NeedRequestLog bool // 是否需要request.log
	// contains filtered or unexported fields
}

type LogOption

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

func SetCaller

func SetCaller(caller bool) LogOption

func SetCompress

func SetCompress(compress bool) LogOption

func SetMaxAge

func SetMaxAge(age int) LogOption

func SetMaxBackups

func SetMaxBackups(n int) LogOption

func SetMaxFileSize

func SetMaxFileSize(size int) LogOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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