Documentation
¶
Overview ¶
Package log .
this log is inspired by `https://github.com/silenceper/log` and `https://github.com/sirupsen/logrus` 1. can be set to output to file 2. log file can be split into files day by day, just like `app.20060102.log`
Index ¶
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func GetCallerForTest() *runtime.Frame
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func SetCallerReporter(b bool)
- func SetLogLevel(level Level)
- func SetTimeFormat(b bool, layout string)
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- func WithContext(ctx context.Context) *entry
- func WithField(key string, value interface{}) *entry
- func WithFields(fields Fields) *entry
- type ContextParser
- type Fields
- type Formatter
- type Level
- type Logger
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) SetCallerReporter(b bool)
- func (l *Logger) SetLogLevel(level Level)
- func (l *Logger) SetTimeFormat(b bool, layout string)
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) WithContext(ctx context.Context) *entry
- func (l *Logger) WithField(key string, value interface{}) *entry
- func (l *Logger) WithFields(fields Fields) *entry
- type LoggerOption
- func WithContextParser(parser ContextParser) LoggerOption
- func WithCustomWriter(w io.Writer) LoggerOption
- func WithFieldsSort(sortField bool) LoggerOption
- func WithFileLog(fp string, autoRotate bool) LoggerOption
- func WithGlobalFields(fields Fields) LoggerOption
- func WithLevel(lv Level) LoggerOption
- func WithReportCaller(b bool) LoggerOption
- func WithStdout(v bool) LoggerOption
- func WithTimeFormat(b bool, layout string) LoggerOption
- type TextFormatter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetCallerReporter ¶ added in v1.0.3
func SetCallerReporter(b bool)
func SetTimeFormat ¶ added in v1.0.5
Types ¶
type ContextParser ¶ added in v1.0.4
type ContextParser interface {
// Parse contains the logic code which indicates how to parse the context.
Parse(ctx context.Context) interface{}
// FieldName is field which will be used in log fields.
FieldName() string
}
ContextParser want to to parse context into `context` field and log into fields. it would be called only when `ctx` it not nil
func DefaultContextParserFunc ¶ added in v1.0.4
func DefaultContextParserFunc(parseFunc func(ctx context.Context) interface{}) ContextParser
DefaultContextParserFunc use default field name as output context field name.
func NewContextParserFunc ¶ added in v1.0.4
func NewContextParserFunc(f func(ctx context.Context) interface{}, fieldName string) ContextParser
NewContextParserFunc parseFunc `func(ctx context.Context) interface{}` as the primary parameter, fieldName `string` as secondary parameter.
type Fields ¶ added in v1.0.0
type Fields map[string]interface{}
Fields to contains a batch field to log
type Logger ¶ added in v1.0.0
type Logger struct {
// contains filtered or unexported fields
}
func NewLogger ¶
func NewLogger(opts ...LoggerOption) (*Logger, error)
NewLogger using os.Stdout and LevelDebug to print log
func (*Logger) SetCallerReporter ¶ added in v1.0.3
func (*Logger) SetLogLevel ¶ added in v1.0.0
func (*Logger) SetTimeFormat ¶ added in v1.0.5
func (*Logger) WithContext ¶ added in v1.0.4
func (*Logger) WithFields ¶ added in v1.0.0
type LoggerOption ¶ added in v1.0.0
type LoggerOption func(lo *options) error
LoggerOption to apply single function into `lo`
func WithContextParser ¶ added in v1.0.4
func WithContextParser(parser ContextParser) LoggerOption
WithContextParser set a custom ContextParser for parsing context. maybe you want to auto log opentracing traceId, this could help you.
func WithCustomWriter ¶ added in v1.0.1
func WithCustomWriter(w io.Writer) LoggerOption
WithCustomWriter using custom writer to log
func WithFieldsSort ¶ added in v1.1.0
func WithFieldsSort(sortField bool) LoggerOption
WithFieldsSort print fields in order of fields' keys lexicographical order.
func WithFileLog ¶ added in v1.0.0
func WithFileLog(fp string, autoRotate bool) LoggerOption
WithFileLog store log into file, if autoRotate is set, it will start a goroutine to split log file by day. TODO(@yeqown): using time round instead of ticker
func WithGlobalFields ¶ added in v1.0.0
func WithGlobalFields(fields Fields) LoggerOption
WithGlobalFields set global fields those would be logged in every log.
func WithLevel ¶ added in v1.0.0
func WithLevel(lv Level) LoggerOption
WithLevel setting the level, this could change dynamic
func WithReportCaller ¶ added in v1.0.3
func WithReportCaller(b bool) LoggerOption
WithReportCaller b is a switch to open print caller or not.
func WithStdout ¶ added in v1.0.0
func WithStdout(v bool) LoggerOption
WithStdout output to os.Stdout also.
func WithTimeFormat ¶ added in v1.0.5
func WithTimeFormat(b bool, layout string) LoggerOption
WithTimeFormat to output time as the layout you want.
type TextFormatter ¶ added in v1.0.0
type TextFormatter struct {
// contains filtered or unexported fields
}