log

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() (err error)

Close close resource.

func Error

func Error(format string, args ...interface{})

Error logs a message at the error log level.

func Errorv

func Errorv(ctx context.Context, args ...D)

Errorv logs a message at the error log level.

func Info

func Info(format string, args ...interface{})

Info logs a message at the info log level.

func Infov

func Infov(ctx context.Context, args ...D)

Infov logs a message at the info log level.

func Init

func Init(conf *Config)

Init create logger with context.

func Warn

func Warn(format string, args ...interface{})

Warn logs a message at the warning log level.

func Warnv

func Warnv(ctx context.Context, args ...D)

Warnv logs a message at the warning log level.

Types

type AgentConfig

type AgentConfig struct {
	TaskID string
	Buffer int
	Proto  string `dsn:"network"`
	Addr   string `dsn:"address"`
	Chan   string `dsn:"query.chan"`
}

type Config

type Config struct {
	Family string
	Host   string

	// stdout
	Stdout bool

	// file
	Dir string
	// buffer size
	FileBufferSize int64
	// MaxLogFile
	MaxLogFile int
	// RotateSize
	RotateSize int64

	// V Enable V-leveled logging at the specified level.
	V int32
	// Module=""
	// The syntax of the argument is a map of pattern=N,
	// where pattern is a literal file name (minus the ".go" suffix) or
	// "glob" pattern and N is a V level. For instance:
	// [module]
	//   "service" = 1
	//   "dao*" = 2
	// sets the V level to 2 in all Go files whose names begin "dao".
	Module map[string]int32
	// Filter tell log handler which field are sensitive message, use * instead.
	Filter []string
}

Config log config.

type D

type D struct {
	Key   string
	Value interface{}
}

D 表示用于结构化日志记录的入门级数据的映射。 type D map[string]interface{}

func KV

func KV(key string, value interface{}) D

KV return a log kv for logging field.

type FileHandler

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

FileHandler .

func NewFile

func NewFile(dir string, bufferSize, rotateSize int64, maxLogFile int) *FileHandler

NewFile crete a file logger.

func (*FileHandler) Close

func (h *FileHandler) Close() error

Close log handler

func (*FileHandler) Log

func (h *FileHandler) Log(ctx context.Context, lv Level, args ...D)

Log loggint to file .

func (*FileHandler) SetFormat

func (h *FileHandler) SetFormat(format string)

SetFormat set log format

type Handler

type Handler interface {
	Log(context.Context, Level, ...D)

	// SetFormat 在日志输出上设置渲染格式
	// see StdoutHandler.SetFormat for detail
	SetFormat(string)

	// Close handler
	Close() error
}

type Handlers

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

Handlers a bundle for hander with filter function.

func (Handlers) Close

func (hs Handlers) Close() (err error)

Close close resource.

func (Handlers) Log

func (hs Handlers) Log(c context.Context, lv Level, d ...D)

Log handlers logging.

func (Handlers) SetFormat

func (hs Handlers) SetFormat(format string)

SetFormat .

type Level

type Level int

Level of severity.

func (Level) String

func (l Level) String() string

String implementation.

type Render

type Render interface {
	Render(io.Writer, map[string]interface{}) error
	RenderString(map[string]interface{}) string
}

Render render log output

type StdoutHandler

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

StdoutHandler stdout log handler

func NewStdout

func NewStdout() *StdoutHandler

NewStdout create a stdout log handler

func (*StdoutHandler) Close

func (h *StdoutHandler) Close() error

Close stdout loging

func (*StdoutHandler) Log

func (h *StdoutHandler) Log(ctx context.Context, lv Level, args ...D)

Log stdout loging, only for developing env.

func (*StdoutHandler) SetFormat

func (h *StdoutHandler) SetFormat(format string)

SetFormat set stdout log output format %T time format at "15:04:05.999" %t time format at "15:04:05" %D data format at "2006/01/02" %d data format at "01/02" %L log level e.g. INFO WARN ERROR %f function name and line number e.g. model.Get:121 %i instance id %e deploy env e.g. dev uat fat prod %z zone %S full file name and line number: /a/b/c/d.go:23 %s final file name element and line number: d.go:23 %M log message and additional fields: key=value this is log message

type Verbose

type Verbose bool

Verbose is a boolean type that implements Info, Infov (like Printf) etc.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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