Documentation ¶
Index ¶
- Constants
- func PinLoggerContext(ctx context.Context) context.Context
- func SetGlobalErrorHandler(f ErrorHandler)
- func WithTestLogger(t *testing.T, filter *Filter, f func(lc *LogCapture))
- type CapturedLog
- type Category
- type ContextLoggerBuilder
- type ErrorHandler
- type Filter
- type Level
- type LogCapture
- type Logger
Constants ¶
const ( // CatServer is server lifecycle log CatServer Category = "server" // CatLogger is logging system events CatLogger = "logger" // CatTracing is tracing system events CatTracing = "tracing" // CatAuth is auth related events CatAuth = "auth" // CatHTTP is HTTP layer log CatHTTP = "http" // CatStorage is storage events CatStorage = "storage" // CatOutgoingWebhook is outgoing webhook events CatOutgoingWebhook = "webhook-out" )
Variables ¶
This section is empty.
Functions ¶
func PinLoggerContext ¶
PinLoggerContext creates context-specific logger along with the new context. By default, logger.Of(Context) returns same logger instance if no configuration changed. Some operation (e.g. global handlers) looks top-most context that logger belongs to.
func SetGlobalErrorHandler ¶
func SetGlobalErrorHandler(f ErrorHandler)
SetGlobalErrorHandler to set callback function for each error log
func WithTestLogger ¶
func WithTestLogger(t *testing.T, filter *Filter, f func(lc *LogCapture))
WithTestLogger swaps global logger for testing only.
Types ¶
type CapturedLog ¶
CapturedLog represents captured log object
func (CapturedLog) FindErrorField ¶
func (log CapturedLog) FindErrorField() error
FindErrorField returns error field of the log or nil
func (CapturedLog) FindStringField ¶
func (log CapturedLog) FindStringField(key string) string
FindStringField string field of the given name
type ContextLoggerBuilder ¶
type ContextLoggerBuilder interface { Build() context.Context WithStr(key string, value string) ContextLoggerBuilder WithInt(key string, value int) ContextLoggerBuilder WithInt64(key string, value int64) ContextLoggerBuilder WithBool(key string, value bool) ContextLoggerBuilder }
ContextLoggerBuilder is an interface to create child context that holds child logger
func WithAttributes ¶
func WithAttributes(ctx context.Context) ContextLoggerBuilder
WithAttributes returns builder to create child context that holds child logger
type ErrorHandler ¶
ErrorHandler function to receive error logs
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter controls log verbosity
func InitLogger ¶
func InitLogger(config *config.LoggingConfig) (*Filter, error)
InitLogger initializes Logger
func (*Filter) SetThreshold ¶
SetThreshold changes threshold immediately
type Level ¶
type Level int
Level represents log severity. Larger value represents more important log.
type LogCapture ¶
type LogCapture struct {
// contains filtered or unexported fields
}
LogCapture represents log capture system for testing purpose
func (*LogCapture) Count ¶
func (c *LogCapture) Count() int
Count returns total count of captured logs
func (*LogCapture) LastLog ¶
func (c *LogCapture) LastLog(offset int) *CapturedLog
LastLog returns captured log
type Logger ¶
type Logger interface { // output fatal log then exit this process immediately FatalExitProcess(msg string, err error) Error(msg string, err error) WarnError(cat Category, msg string, err error) InfoError(cat Category, msg string, err error) Warnf(cat Category, template string, args ...interface{}) Infof(cat Category, template string, args ...interface{}) Debugf(cat Category, template string, args ...interface{}) }
Logger represents implementation independent logger, also easy to inject mock.