Documentation ¶
Index ¶
- Constants
- Variables
- func Caller(depth int) log.Valuer
- func GetContextLogger(ctx context.Context, options ...Option) log.Logger
- func GetDefaultLogger() log.Logger
- func GetSourceCodeDir(codeRelativePath string, depth ...int) string
- func GetTraceId(ctx context.Context) string
- func New(opts ...NewLoggerOption) log.Logger
- func NewContextLogger(parent context.Context, opts ...NewLoggerOption) (context.Context, log.Logger)
- func NewNopLogger() log.Logger
- func NewTeeLogger(lgs ...log.Logger) log.Logger
- func NewTraceId() string
- func NewTraceLogger(options ...NewLoggerOption) log.Logger
- func NewWriterAdapter(logger log.Logger, options ...WriterAdapterOption) io.Writer
- func RegisterLogFormat(logFmt AllowedFormat, f LoggerCreateFunc)
- func SetDefaultLogger(logger log.Logger)
- func SetSourceCodeDir(d string)
- func WrapKeyName(name string) fmt.Stringer
- type AllowedFormat
- type AllowedLevel
- type Config
- type KeyName
- type LoggerCreateFunc
- type NewLoggerOption
- type Option
- type WriterAdapter
- type WriterAdapterOption
Constants ¶
const (
TraceIdName = "traceId"
)
Variables ¶
var CallerName = callerName{}
var DefaultCaller = Caller(5)
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 GetContextLogger ¶
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 ¶
GetDefaultLogger
@Description[en-US]: Get the default Logger @Description[zh-CN]: 获取默认的Logger @return log.Logger
func GetSourceCodeDir ¶
func GetTraceId ¶
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 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 ¶
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
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 ¶
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 ¶
func WithCaller ¶
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 ¶
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
type WriterAdapter ¶
type WriterAdapter struct {
// contains filtered or unexported fields
}
type WriterAdapterOption ¶
type WriterAdapterOption func(*WriterAdapter)
func MessageKey ¶
func MessageKey(key string) WriterAdapterOption
func Prefix ¶
func Prefix(prefix string, joinPrefixToMsg bool) WriterAdapterOption