log

package module
v0.0.0-...-7f09b07 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 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/georgehao/log"

func main() {
	// init log
	// set absolute path, and level
	// set output level
	// don't need request log
	// set log's caller using logOption
	log.Init("./test.log", log.DebugLevel, false, log.SetCaller(true))
	log.Info("hello george log")
	// flush
	log.Sync()
	//output: {"level":"info","ts":"2019-12-16T10:37:11.364+0800","caller":"example/example.go:12","msg":"hello george log"}
}

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 Panic

func Panic(args ...interface{})

func Panicf

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

func Panicw

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

func RequestLogInfow

func RequestLogInfow(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
	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

Jump to

Keyboard shortcuts

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