log

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 17 Imported by: 29

Documentation

Index

Constants

View Source
const (
	TraceIdName = "traceId"
)

Variables

View Source
var CallerName = callerName{}
View Source
var DefaultCaller = Caller(5)
View Source
var TimestampFormat = log.TimestampFormat(
	func() time.Time { return time.Now().UTC() },
	"2006-01-02T15:04:05.000Z07:00",
)

TimestampFormat This timestamp format differs from RFC3339Nano by using .000 instead of .999999999 which changes the timestamp from 9 variable to 3 fixed decimals (.130 instead of .130987456).

Functions

func Caller

func Caller(depth int) log.Valuer

func GetContextLogger

func GetContextLogger(ctx context.Context, options ...Option) log.Logger

GetContextLogger

@Description[en-US]: Get the log.Logger object in Context. If it does not exist, a new Logger with traceId will be returned
@Description[zh-CN]: 获取Context中的log.Logger对象,如果不存在,则返回一个新的带traceId的Logger
@param ctx 	context.Context
@param options 	...Option
@return log.Logger

func GetDefaultLogger

func GetDefaultLogger() log.Logger

GetDefaultLogger

@Description[en-US]: Get the default Logger
@Description[zh-CN]: 获取默认的Logger
@return log.Logger

func GetSourceCodeDir

func GetSourceCodeDir(codeRelativePath string, depth ...int) string

func GetTraceId

func GetTraceId(ctx context.Context) string

GetTraceId

@Description[en-US]: Get traceId in Context.
@Description[zh-CN]: 获取Context中的traceId
@param ctx 	context.Context
@return string

func New

func New(opts ...NewLoggerOption) log.Logger

New returns a new leveled oklog logger. Each logged line will be annotated with a timestamp. The output always goes to stderr.

func NewContextLogger

func NewContextLogger(parent context.Context, opts ...NewLoggerOption) (context.Context, log.Logger)

NewContextLogger

@Description[en-US]: Create a traceable context log object
@Description[zh-CN]: 创建可跟踪的上下文日志对象
@param parent 	context.Context
@param opts 	...NewLoggerOption
@return ${ret_name}	context.Context
@return ${ret_name}	log.Logger

func NewNopLogger added in v1.1.17

func NewNopLogger() log.Logger

func NewTeeLogger added in v1.4.0

func NewTeeLogger(lgs ...log.Logger) log.Logger

func NewTraceId

func NewTraceId() string

NewTraceId

@Description[en-US]: Generate a trace ID
@Description[zh-CN]: 生成一个跟踪ID
@return string

func NewTraceLogger

func NewTraceLogger(options ...NewLoggerOption) log.Logger

NewTraceLogger

@Description[en-US]: Create a new traceable log object
@Description[zh-CN]: 创建新的可跟踪的日志对象
@param options 	...NewLoggerOption
@return log.Logger

func NewWriterAdapter

func NewWriterAdapter(logger log.Logger, options ...WriterAdapterOption) io.Writer

func RegisterLogFormat

func RegisterLogFormat(logFmt AllowedFormat, f LoggerCreateFunc)

func SetDefaultLogger

func SetDefaultLogger(logger log.Logger)

SetDefaultLogger

@Description[en-US]: Set the default Logger
@Description[zh-CN]: 设置默认的Logger
@param logger 	log.Logger

func SetSourceCodeDir

func SetSourceCodeDir(d string)

func WrapKeyName added in v1.1.5

func WrapKeyName(name string) fmt.Stringer

Types

type AllowedFormat

type AllowedFormat string

AllowedFormat is a settable identifier for the output format that the logger can have.

const (
	FormatJSON   AllowedFormat = "json"
	FormatLogfmt AllowedFormat = "logfmt"
)

func GetRegisteredLogFormats

func GetRegisteredLogFormats() []AllowedFormat

func (*AllowedFormat) Set

func (f *AllowedFormat) Set(s string) error

Set updates the value of the allowed format.

func (AllowedFormat) String

func (f AllowedFormat) String() string

func (AllowedFormat) Valid

func (f AllowedFormat) Valid() error

type AllowedLevel

type AllowedLevel string

AllowedLevel is a settable identifier for the minimum level a log entry must be have.

const (
	LevelDebug AllowedLevel = "debug"
	LevelInfo  AllowedLevel = "info"
	LevelWarn  AllowedLevel = "warn"
	LevelError AllowedLevel = "error"
)

func (*AllowedLevel) Set

func (l *AllowedLevel) Set(s string) error

Set updates the value of the allowed level.

func (AllowedLevel) String

func (l AllowedLevel) String() string

func (*AllowedLevel) UnmarshalYAML

func (l *AllowedLevel) UnmarshalYAML(unmarshal func(interface{}) error) error

func (AllowedLevel) Valid

func (l AllowedLevel) Valid() error

type Config

type Config struct {
	Level            *AllowedLevel
	Format           *AllowedFormat
	FilePath         string
	FileMaxAge       time.Duration
	FileRotationSize string
	FileRotationTime time.Duration
}

Config is a struct containing configurable settings for the logger

var DefaultLoggerConfig *Config

func MustNewConfig

func MustNewConfig(level string, format string) *Config

type KeyName added in v1.1.5

type KeyName string

func (KeyName) String added in v1.1.5

func (n KeyName) String() string

type LoggerCreateFunc

type LoggerCreateFunc func(w io.Writer) log.Logger

type NewLoggerOption

type NewLoggerOption func(*newLoggerOptions)

func WithConfig

func WithConfig(c *Config) NewLoggerOption

func WithKeyValues

func WithKeyValues(keyvals ...interface{}) NewLoggerOption

func WithLogger

func WithLogger(l log.Logger) NewLoggerOption

WithLogger

@Description[en-US]: Specify parent Logger when creating Logger
@Description[zh-CN]: 创建Logger时指定父Logger
@param l 	log.Logger
@return NewLoggerOption

func WithTraceId

func WithTraceId(traceId string) NewLoggerOption

WithTraceId

@Description[en-US]: Specify TraceId when creating Logger
@Description[zh-CN]: 创建Logger时指定TraceId
@param traceId 	string
@return NewLoggerOption

func WithWriter

func WithWriter(w io.Writer) NewLoggerOption

WithWriter

@Description[en-US]: Specify parent Logger when creating Logger
@Description[zh-CN]: 创建Logger时指定父Logger
@param l 	log.Logger
@return NewLoggerOption

type Option

type Option func(l log.Logger) log.Logger

func WithCaller

func WithCaller(layer int) Option

WithCaller

@Description[en-US]: Get the file name path of the specified location of the call chain.
@Description[zh-CN]: 获取调用链的指定位置的文件名路径
@param layer 	int
@return Option

func WithMethod

func WithMethod(skip ...int) Option

WithMethod

@Description[en-US]: Get the method name of the specified location of the call chain (if not specified, the default is 2).
@Description[zh-CN]: 获取调用链的指定位置(如果不指定,默认为2)的方法名称
@param skip 	...int
@return Option

func WithPrint

func WithPrint(raw interface{}) Option

type WriterAdapter

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

func (WriterAdapter) Write

func (a WriterAdapter) Write(p []byte) (n int, err error)

type WriterAdapterOption

type WriterAdapterOption func(*WriterAdapter)

func MessageKey

func MessageKey(key string) WriterAdapterOption

func Prefix

func Prefix(prefix string, joinPrefixToMsg bool) WriterAdapterOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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