log

package
v0.0.0-...-ed2f012 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoneLevel disables logging
	NoneLevel Level = 0
	// FatalLevel enables fatal level logging
	FatalLevel = 1 << iota
	// ErrorLevel enables error level logging
	ErrorLevel
	// WarnLevel enables warn level logging
	WarnLevel
	// InfoLevel enables info level logging
	InfoLevel
	// DebugLevel enables debug level logging
	DebugLevel
)
View Source
const (
	// DefaultScopeName defines the name of the default scope.
	DefaultScopeName = "default"
)

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug outputs a message at debug level.

func DebugEnabled

func DebugEnabled() bool

DebugEnabled returns whether output of messages using this scope is currently enabled for debug-level output.

func Debugf

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

Debugf uses fmt.Sprintf to construct and log a message at debug level.

func Error

func Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message at error level.

func ErrorEnabled

func ErrorEnabled() bool

ErrorEnabled returns whether output of messages using this scope is currently enabled for error-level output.

func Errorf

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

Errorf uses fmt.Sprintf to construct and log a message at error level.

func Fatal

func Fatal(args ...interface{})

Fatal outputs a message at fatal level.

func FatalEnabled

func FatalEnabled() bool

FatalEnabled returns whether output of messages using this scope is currently enabled for fatal-level output.

func Fatalf

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

Fatalf uses fmt.Sprintf to construct and log a message at fatal level.

func Info

func Info(args ...interface{})

Info outputs a message at info level.

func InfoEnabled

func InfoEnabled() bool

InfoEnabled returns whether output of messages using this scope is currently enabled for info-level output.

func Infof

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

Infof uses fmt.Sprintf to construct and log a message at info level.

func Scopes

func Scopes() map[string]*Scope

Scopes returns a snapshot of the currently defined set of scopes

func Warn

func Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message at warn level.

func WarnEnabled

func WarnEnabled() bool

WarnEnabled returns whether output of messages using this scope is currently enabled for warn-level output.

func Warnf

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

Warnf uses fmt.Sprintf to construct and log a message at warn level.

Types

type Entry

type Entry struct {
	//以下是配套的格式
	LogID         string  `json:"log_id"`
	Project       string  `json:"project"`
	Method        string  `json:"method"`
	RemoteRervice string  `json:"remote_service"`
	CostTime      float64 `json:"cost_time"`
	Status        string  `json:"status"`
	URLPath       string  `json:"url_path"`
	UserAgent     string  `json:"user_agent"`
	Code          string  `json:"code"`
	Extra         string  `json:"extra"`
	MerchantCode  string  `json:"merchant_code"`
}

Entry 是配套的格式

type Level

type Level uint

Level is an enumeration of all supported log levels.

type Options

type Options struct {
	LoggerName string
	// OutputPaths is a list of file system paths to write the log data to.
	// The special values stdout and stderr can be used to output to the
	// standard I/O streams. This defaults to stdout.
	OutputPaths []string

	// ErrorOutputPaths is a list of file system paths to write logger errors to.
	// The special values stdout and stderr can be used to output to the
	// standard I/O streams. This defaults to stderr.
	ErrorOutputPaths []string

	// RotateOutputPath is the path to a rotating log file. This file should
	// be automatically rotated over time, based on the rotation parameters such
	// as RotationMaxSize and RotationMaxAge. The default is to not rotate.
	//
	// This path is used as a foundational path. This is where log output is normally
	// saved. When a rotation needs to take place because the file got too big or too
	// old, then the file is renamed by appending a timestamp to the name. Such renamed
	// files are called backups. Once a backup has been created,
	// output resumes to this path.
	RotateOutputPath string

	// RotationMaxSize is the maximum size in megabytes of a log file before it gets
	// rotated. It defaults to 100 megabytes.
	RotationMaxSize int

	// RotationMaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename. Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is to remove log files
	// older than 30 days.
	RotationMaxAge int

	// RotationMaxBackups is the maximum number of old log files to retain.  The default
	// is to retain at most 1000 logs.
	RotationMaxBackups int

	// JSONEncoding controls whether the log is formatted as JSON.
	JSONEncoding bool

	OutputLevels     Level
	LogCallerLevels  Level
	StackTraceLevels Level

	////for test; If not nil, called instead of os.Exit.
	ExitFunc func()
}

Options Config

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns a new set of options, initialized to the defaults

type Scope

type Scope struct {
	Entry
	// contains filtered or unexported fields
}

func Configure

func Configure(options *Options) (s *Scope, err error)

Configure initializes logging system.

func GetScope

func GetScope(name string) *Scope

GetScope returns a previously registered scope, or nil if the named scope wasn't previously registered

func NewScope

func NewScope(name string, logID string, callerSkip int) *Scope

NewScope 从默认scope里复制一个出来,再作必要的修改

func RegisterScope

func RegisterScope(name string, logID string, callerSkip int) *Scope

RegisterScope registers a new logging scope. If the same name is used multiple times for a single process, the same Scope struct is returned.

Scope names cannot include colons, commas, or periods.

func (*Scope) CopyByCallerSkip

func (s *Scope) CopyByCallerSkip(callerSkip int) *Scope

func (*Scope) Debug

func (s *Scope) Debug(args ...interface{})

Debug uses fmt.Sprint to construct and log a message at debug level.

func (*Scope) DebugEnabled

func (s *Scope) DebugEnabled() bool

DebugEnabled returns whether output of messages using this scope is currently enabled for debug-level output.

func (*Scope) Debugf

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

Debugf uses fmt.Sprintf to construct and log a message at debug level.

func (*Scope) Error

func (s *Scope) Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message at error level.

func (*Scope) ErrorEnabled

func (s *Scope) ErrorEnabled() bool

ErrorEnabled returns whether output of messages using this scope is currently enabled for error-level output.

func (*Scope) Errorf

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

Errorf uses fmt.Sprintf to construct and log a message at error level.

func (*Scope) Fatal

func (s *Scope) Fatal(args ...interface{})

Fatal outputs a message at fatal level.

func (*Scope) FatalEnabled

func (s *Scope) FatalEnabled() bool

FatalEnabled returns whether output of messages using this scope is currently enabled for fatal-level output.

func (*Scope) Fatalf

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

Fatalf uses fmt.Sprintf to construct and log a message at fatal level.

func (*Scope) Info

func (s *Scope) Info(args ...interface{})

Info uses fmt.Sprint to construct and log a message at info level.

func (*Scope) InfoEnabled

func (s *Scope) InfoEnabled() bool

InfoEnabled returns whether output of messages using this scope is currently enabled for info-level output.

func (*Scope) Infof

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

Infof uses fmt.Sprintf to construct and log a message at info level.

func (*Scope) Warn

func (s *Scope) Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message at warn level.

func (*Scope) WarnEnabled

func (s *Scope) WarnEnabled() bool

WarnEnabled returns whether output of messages using this scope is currently enabled for warn-level output.

func (*Scope) Warnf

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

Warnf uses fmt.Sprintf to construct and log a message at warn level.

Jump to

Keyboard shortcuts

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