log

package
v0.0.0-...-26b160e Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

@Time : 2018/8/16 12:46 @Author : kenny zhu @File : interface.go @Software: GoLand @Others: Default operations.

Package log is an interface for structured logging.

Index

Constants

View Source
const (
	DebugLevel Level = 0
	InfoLevel  Level = 1
	WarnLevel  Level = 2
	ErrorLevel Level = 3
	FatalLevel Level = 4

	// this is very small. must be modified.
	DefaultFileSize   int64 = 100 * 1024 * 1024 // for test , must be 1M at least in production.
	DefaultFileMaxNum int   = 1024
)

Variables

View Source
var (
	DefaultLevel      Level = InfoLevel
	DefaultOutputName       = "server.log"

	// file sequences.
	FileSize int64 = DefaultFileSize

	Levels = map[Level]string{
		DebugLevel: "debug",
		InfoLevel:  "info",
		WarnLevel:  "warn",
		ErrorLevel: "error",
		FatalLevel: "fatal",
	}
)

Functions

func Debug

func Debug(args ...interface{})

outer .interface...

func Debugf

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

Formatted logger

func Error

func Error(args ...interface{})

func Errorf

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

func Fatal

func Fatal(args ...interface{})

func Fatalf

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

func GetFunctionName

func GetFunctionName(i interface{}, seps ...rune) string

用 seps 进行分割, 根据协议栈信息查找...

func Info

func Info(args ...interface{})

func Infof

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

func InitLogger

func InitLogger(opts ...Option)

func NewContext

func NewContext(ctx context.Context, c Log) context.Context

func Warn

func Warn(args ...interface{})

func Warnf

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

Types

type Event

type Event struct {
	Timestamp string `json:"timestamp"`
	Level     Level  `json:"level"`
	Fields    Fields `json:"fields"`
	Message   string `json:"message"`
}

Event represents a single log event

func (*Event) MarshalJSON

func (e *Event) MarshalJSON() ([]byte, error)

type Fields

type Fields map[string]string

type Level

type Level int32

type Log

type Log interface {
	Init(opts ...Option) error
	Options() Options
	Logger
	String() string
}

A structure log interface which can output to multiple back-ends.

func FromContext

func FromContext(ctx context.Context) (Log, bool)

func NewLog

func NewLog(opts ...Option) Log

type Logger

type Logger interface {
	// Logger interface
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{}) // sjlin 新增漏掉接口
	Error(args ...interface{})
	Fatal(args ...interface{})
	// Formatted logger
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{}) // sjlin 新增漏掉接口
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	// Specify your own levels
	Log(l Level, args ...interface{})
	Logf(l Level, format string, args ...interface{})
	// Returns with extra fields
	WithFields(f Fields) Logger
}

type Option

type Option func(o *Options)

func WithDir

func WithDir(dir string) Option

func WithFields

func WithFields(f Fields) Option

func WithLevel

func WithLevel(l Level) Option

func WithName

func WithName(name string) Option

Output options

func WithOutput

func WithOutput(ot Output) Option

type Options

type Options struct {
	// the current log level
	Level Level

	// the output to write to
	Op Output

	// include a set of fields
	Fields Fields

	FileSize int

	// Alternative options
	Context context.Context

	//
	OpOption OutputOptions
}

type Output

type Output interface {
	// Send an event
	Send(*Event) error

	// Discard the output
	Close() error

	// Name of output
	String() string
}

An output represents a file, indexer, syslog, etc

func NewOutput

func NewOutput(opts ...OutputOption) Output

type OutputOption

type OutputOption func(o *OutputOptions)

func OutputDir

func OutputDir(dir string) OutputOption

func OutputName

func OutputName(name string) OutputOption

Output options

type OutputOptions

type OutputOptions struct {
	// file path, url, etc, Dir default is ""
	Name string
	Dir  string
}

Directories

Path Synopsis
output
Package go_micro_os_log is a generated protocol buffer package.
Package go_micro_os_log is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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