trait

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

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

Go to latest
Published: Aug 16, 2019 License: MIT Imports: 17 Imported by: 13

Documentation

Index

Constants

View Source
const (
	RotateLogAll = iota
	RotateLogTrace
	RotateLogDebug
	RotateLogInfo
	RotateLogWarn
	RotateLogError
	RotateLogFatal
	RotateLogPanic
	RotateLogOff
)

RotateLogAll ...

Variables

View Source
var (
	RandomString = map[RandomKind]string{
		RandomNum:      "0123456789",
		RandomLower:    "abcdefghijklmnopqrstuvwxyz",
		RandomUpper:    "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
		RandomLowerNum: "0123456789abcdefghijklmnopqrstuvwxyz",
		RandomUpperNum: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
		RandomAll:      "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
	}
)

RandomString defines

Functions

func CompressToFile

func CompressToFile(filename string, b []byte) error

CompressToFile ...

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 DecompressFromFile

func DecompressFromFile(filename string) ([]byte, error)

DecompressFromFile ...

func DecompressFromStatik

func DecompressFromStatik(filename string) ([]byte, error)

DecompressFromStatik ...

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

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

func Fatal

func Fatal(args ...interface{})

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.

func Fatalf

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

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.

func Fatalw

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

Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.

func GenerateRandomString

func GenerateRandomString(size int, kind ...RandomKind) string

GenerateRandomString 随机字符串

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

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

func InitElasticLog

func InitElasticLog(index string, opts ...ElasticLogOption)

InitElasticLog ...

func InitGlobalZapSugar

func InitGlobalZapSugar()

InitGlobalZapSugar ...

func InitRotateLog

func InitRotateLog(logPath string, opts ...RotateLogOption)

InitRotateLog ...

func NewZap

func NewZap() *zap.Logger

NewZap ...

func NewZapFile

func NewZapFile(path ...string) *zap.Logger

NewZapFile ...

func NewZapFileSugar

func NewZapFileSugar(path ...string) *zap.SugaredLogger

NewZapFileSugar ...

func NewZapSugar

func NewZapSugar(f ...zap.Field) *zap.SugaredLogger

NewZapSugar ...

func NoOutput

func NoOutput()

NoOutput ...

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

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

func With

func With(args ...interface{})

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,

 sugaredLogger.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.

Types

type ElasticLogOption

type ElasticLogOption func(opts *ElasticLogOptions)

ElasticLogOption ...

func ClientOptions

func ClientOptions(cls ...elastic.ClientOptionFunc) ElasticLogOption

ClientOptions ...

func ElasticLogLevel

func ElasticLogLevel(l log.Level) ElasticLogOption

ElasticLogLevel ...

func Formatter

func Formatter(f log.Formatter) ElasticLogOption

Formatter ...

func Host

func Host(h string) ElasticLogOption

Host ...

func ReportCaller

func ReportCaller(b bool) ElasticLogOption

ReportCaller ...

type ElasticLogOptions

type ElasticLogOptions struct {
	ReportCaller  bool
	Formatter     log.Formatter
	Host          string
	Level         log.Level
	ClientOptions []elastic.ClientOptionFunc
}

ElasticLogOptions ...

type RandomKind

type RandomKind int

RandomKind RandomKind

const (
	RandomNum      RandomKind = iota // 纯数字
	RandomLower                      // 小写字母
	RandomUpper                      // 大写字母
	RandomLowerNum                   // 数字、小写字母
	RandomUpperNum                   // 数字、大写字母
	RandomAll                        // 数字、大小写字母
)

random kinds

type RotateLogOption

type RotateLogOption func(opts *RotateLogOptions)

RotateLogOption ...

func MaxAge

func MaxAge(duration time.Duration) RotateLogOption

MaxAge ...

func RotateLogLevel

func RotateLogLevel(l int) RotateLogOption

RotateLogLevel ...

func RotationTime

func RotationTime(duration time.Duration) RotateLogOption

RotationTime ...

type RotateLogOptions

type RotateLogOptions struct {
	Level        int           `json:"level"`
	MaxAge       time.Duration `json:"max_age"`
	RotationTime time.Duration `json:"rotation_time"`
}

RotateLogOptions ...

Jump to

Keyboard shortcuts

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