Documentation ¶
Overview ¶
Example ¶
logger, err := NewDevelopmentConfig().Build() if err != nil { panic(err) } logger.Debug("str1") logger.Infof("str2: %d", 200) logger.Warnw("str3", "foo", 300) type HandlerContext struct { context.Context Logger } ctx := &HandlerContext{ Context: context.TODO(), Logger: logger.NewLoggerWith("handler", "UpdateUserName"), } ctx.Error("invalid user name")
Output:
Index ¶
- Constants
- type Config
- type DumbLogger
- func (DumbLogger) Debug(args ...any)
- func (DumbLogger) Debugf(format string, args ...any)
- func (DumbLogger) Debugw(msg string, keyVals ...any)
- func (DumbLogger) Error(args ...any)
- func (DumbLogger) Errorf(format string, args ...any)
- func (DumbLogger) Errorw(msg string, keyVals ...any)
- func (DumbLogger) FlushLogger() error
- func (DumbLogger) Info(args ...any)
- func (DumbLogger) Infof(format string, args ...any)
- func (DumbLogger) Infow(msg string, keyVals ...any)
- func (DumbLogger) NewLoggerWith(keyVals ...any) Logger
- func (DumbLogger) Warn(args ...any)
- func (DumbLogger) Warnf(format string, args ...any)
- func (DumbLogger) Warnw(msg string, keyVals ...any)
- type LogEntry
- type Logger
- type MessageFinder
- func (mf *MessageFinder) Find(str string) (string, int, bool)
- func (mf *MessageFinder) FindRegexp(pat string) (string, int, bool)
- func (mf *MessageFinder) FindRegexpSequence(a []string) (int, bool)
- func (mf *MessageFinder) FindSequence(a []string) (int, bool)
- func (mf *MessageFinder) FindString(str string) (string, int, bool)
- func (mf *MessageFinder) FindStringSequence(a []string) (int, bool)
- func (mf *MessageFinder) FindUnique(str string) (string, int, bool)
- func (mf *MessageFinder) FindUniqueRegexp(pat string) (string, int, bool)
- func (mf *MessageFinder) FindUniqueString(str string) (string, int, bool)
- type Scavenger
- func (sc *Scavenger) Debug(args ...any)
- func (sc *Scavenger) Debugf(format string, args ...any)
- func (sc *Scavenger) Debugw(msg string, keyVals ...any)
- func (sc *Scavenger) Dump() string
- func (sc *Scavenger) Entries() []LogEntry
- func (sc *Scavenger) Error(args ...any)
- func (sc *Scavenger) Errorf(format string, args ...any)
- func (sc *Scavenger) Errorw(msg string, keyVals ...any)
- func (sc *Scavenger) Exists(str string) (yes bool)
- func (sc *Scavenger) Filter(fn func(level, msg string) bool) *Scavenger
- func (sc *Scavenger) FindRegexpSequence(seq []string) (found int, yes bool)
- func (sc *Scavenger) FindSequence(seq []string) (found int, yes bool)
- func (sc *Scavenger) FindStringSequence(seq []string) (found int, yes bool)
- func (sc *Scavenger) Finder() *MessageFinder
- func (sc *Scavenger) FlushLogger() error
- func (sc *Scavenger) Info(args ...any)
- func (sc *Scavenger) Infof(format string, args ...any)
- func (sc *Scavenger) Infow(msg string, keyVals ...any)
- func (sc *Scavenger) Len() int
- func (sc *Scavenger) NewLoggerWith(keyVals ...any) Logger
- func (sc *Scavenger) RegexpExists(pat string) (yes bool)
- func (sc *Scavenger) Reset()
- func (sc *Scavenger) StringExists(str string) (yes bool)
- func (sc *Scavenger) UniqueExists(str string) (yes bool)
- func (sc *Scavenger) UniqueRegexpExists(pat string) (yes bool)
- func (sc *Scavenger) UniqueStringExists(str string) (yes bool)
- func (sc *Scavenger) Warn(args ...any)
- func (sc *Scavenger) Warnf(format string, args ...any)
- func (sc *Scavenger) Warnw(msg string, keyVals ...any)
- type ZapLogger
- func (zl *ZapLogger) Debug(args ...any)
- func (zl *ZapLogger) Debugf(format string, args ...any)
- func (zl *ZapLogger) Debugw(msg string, keyVals ...any)
- func (zl *ZapLogger) Error(args ...any)
- func (zl *ZapLogger) Errorf(format string, args ...any)
- func (zl *ZapLogger) Errorw(msg string, keyVals ...any)
- func (zl *ZapLogger) FlushLogger() error
- func (zl *ZapLogger) Info(args ...any)
- func (zl *ZapLogger) Infof(format string, args ...any)
- func (zl *ZapLogger) Infow(msg string, keyVals ...any)
- func (zl *ZapLogger) NewLoggerWith(keyVals ...any) Logger
- func (zl *ZapLogger) Warn(args ...any)
- func (zl *ZapLogger) Warnf(format string, args ...any)
- func (zl *ZapLogger) Warnw(msg string, keyVals ...any)
- func (zl *ZapLogger) Zap() *zap.SugaredLogger
Examples ¶
Constants ¶
const ( LevelDebug = "DEBUG" LevelInfo = "INFO" LevelWarn = "WARN" LevelError = "ERROR" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
func NewDevelopmentConfig ¶
func NewDevelopmentConfig() *Config
func NewProductionConfig ¶
func NewProductionConfig() *Config
type DumbLogger ¶
type DumbLogger struct{}
DumbLogger devours all log messages and outputs nothing.
func (DumbLogger) Debug ¶
func (DumbLogger) Debug(args ...any)
func (DumbLogger) Debugf ¶
func (DumbLogger) Debugf(format string, args ...any)
func (DumbLogger) Debugw ¶
func (DumbLogger) Debugw(msg string, keyVals ...any)
func (DumbLogger) Error ¶
func (DumbLogger) Error(args ...any)
func (DumbLogger) Errorf ¶
func (DumbLogger) Errorf(format string, args ...any)
func (DumbLogger) Errorw ¶
func (DumbLogger) Errorw(msg string, keyVals ...any)
func (DumbLogger) FlushLogger ¶
func (DumbLogger) FlushLogger() error
func (DumbLogger) Info ¶
func (DumbLogger) Info(args ...any)
func (DumbLogger) Infof ¶
func (DumbLogger) Infof(format string, args ...any)
func (DumbLogger) Infow ¶
func (DumbLogger) Infow(msg string, keyVals ...any)
func (DumbLogger) NewLoggerWith ¶
func (DumbLogger) NewLoggerWith(keyVals ...any) Logger
func (DumbLogger) Warn ¶
func (DumbLogger) Warn(args ...any)
func (DumbLogger) Warnf ¶
func (DumbLogger) Warnf(format string, args ...any)
func (DumbLogger) Warnw ¶
func (DumbLogger) Warnw(msg string, keyVals ...any)
type Logger ¶
type Logger interface { // NewLoggerWith adds a variadic number of fields to the logging context. It accepts a // mix of zap.Field objects and loosely-typed key-value pairs. When // processing pairs, the first element of the pair is used as the field key // and the second as the field value. The keys in key-value pairs should be strings. NewLoggerWith(keyVals ...any) Logger // Debug uses fmt.Sprint to construct and log a message. Debug(args ...any) // Info uses fmt.Sprint to construct and log a message. Info(args ...any) // Warn uses fmt.Sprint to construct and log a message. Warn(args ...any) // Error uses fmt.Sprint to construct and log a message. Error(args ...any) // Debugf uses fmt.Sprintf to log a templated message. Debugf(format string, args ...any) // Infof uses fmt.Sprintf to log a templated message. Infof(format string, args ...any) // Warnf uses fmt.Sprintf to log a templated message. Warnf(format string, args ...any) // Errorf uses fmt.Sprintf to log a templated message. Errorf(format string, args ...any) // Debugw logs a message with some additional context. The variadic key-value // pairs are treated as they are in NewLoggerWith. Debugw(msg string, keyVals ...any) // Infow logs a message with some additional context. The variadic key-value // pairs are treated as they are in NewLoggerWith. Infow(msg string, keyVals ...any) // Warnw logs a message with some additional context. The variadic key-value // pairs are treated as they are in NewLoggerWith. Warnw(msg string, keyVals ...any) // Errorw logs a message with some additional context. The variadic key-value // pairs are treated as they are in NewLoggerWith. Errorw(msg string, keyVals ...any) // FlushLogger flushes any buffered log entries. FlushLogger() error }
Logger is an interface which is highly compatible with zap.SugaredLogger.
type MessageFinder ¶
type MessageFinder Scavenger
func (*MessageFinder) FindRegexp ¶
func (mf *MessageFinder) FindRegexp(pat string) (string, int, bool)
func (*MessageFinder) FindRegexpSequence ¶
func (mf *MessageFinder) FindRegexpSequence(a []string) (int, bool)
func (*MessageFinder) FindSequence ¶
func (mf *MessageFinder) FindSequence(a []string) (int, bool)
func (*MessageFinder) FindString ¶
func (mf *MessageFinder) FindString(str string) (string, int, bool)
func (*MessageFinder) FindStringSequence ¶
func (mf *MessageFinder) FindStringSequence(a []string) (int, bool)
func (*MessageFinder) FindUnique ¶
func (mf *MessageFinder) FindUnique(str string) (string, int, bool)
func (*MessageFinder) FindUniqueRegexp ¶
func (mf *MessageFinder) FindUniqueRegexp(pat string) (string, int, bool)
func (*MessageFinder) FindUniqueString ¶
func (mf *MessageFinder) FindUniqueString(str string) (string, int, bool)
type Scavenger ¶
type Scavenger struct {
// contains filtered or unexported fields
}
Scavenger collects all log messages for later queries.
func (*Scavenger) Exists ¶
Exists returns whether any collected message contains str. If str starts with "rex: ", it is regarded as a regular expression.
func (*Scavenger) Filter ¶
Filter creates a new Scavenger that contains only the log messages satisfying the predicate fn.
func (*Scavenger) FindRegexpSequence ¶
FindRegexpSequence returns whether the collected messages contain the specified regular expression sequence.
func (*Scavenger) FindSequence ¶
FindSequence returns whether the collected messages contain the specified sequence. If a string in seq starts with "rex: ", it is regarded as a regular expression.
func (*Scavenger) FindStringSequence ¶
FindStringSequence returns whether the collected messages contain the specified sequence.
func (*Scavenger) Finder ¶
func (sc *Scavenger) Finder() *MessageFinder
Finder returns a MessageFinder.
func (*Scavenger) FlushLogger ¶
func (*Scavenger) NewLoggerWith ¶
func (*Scavenger) RegexpExists ¶
RegexpExists returns whether any collected message contains the regular expression pat.
func (*Scavenger) StringExists ¶
StringExists returns whether any collected message contains str.
func (*Scavenger) UniqueExists ¶
UniqueExists returns whether one and only one collected message contains str. If str starts with "rex: ", it is regarded as a regular expression.
func (*Scavenger) UniqueRegexpExists ¶
UniqueRegexpExists returns whether one and only one collected message contains the regular expression pat.
func (*Scavenger) UniqueStringExists ¶
UniqueStringExists returns whether one and only one collected message contains str.
type ZapLogger ¶
type ZapLogger struct {
// contains filtered or unexported fields
}
ZapLogger is a wrapper of zap.SugaredLogger.
func NewZapLogger ¶
func NewZapLogger(zsl *zap.SugaredLogger) *ZapLogger
NewZapLogger creates a new ZapLogger.
func (*ZapLogger) FlushLogger ¶
func (*ZapLogger) NewLoggerWith ¶
func (*ZapLogger) Zap ¶
func (zl *ZapLogger) Zap() *zap.SugaredLogger
Zap returns the internal zap.SugaredLogger to the caller.