logger

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGormLogger added in v1.6.0

func NewGormLogger(l Logger) gormLogger

Types

type Builder

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

Builder is a Logger builder.

func NewBuilder

func NewBuilder(config *Config) *Builder

NewBuilder initializes a Logger builder with the given configuration.

func (*Builder) Build

func (b *Builder) Build() (Logger, error)

Build applies the given configuration and returns a Logger instance.

func (*Builder) BuildTestLogger

func (b *Builder) BuildTestLogger(out *bytes.Buffer) (Logger, error)

BuildTestLogger returns a Logger instance that will write into the bytes buffer passed as parameter. BuildTestLogger is only for testing.

func (*Builder) SetFields

func (b *Builder) SetFields(fields Fields) *Builder

SetFields adds Fields to the Builder.

func (*Builder) SetTracking

func (b *Builder) SetTracking(trackingConfig *tracking.Config) *Builder

SetTracking sets the error reporting configuration.

type Config

type Config struct {
	ConsoleEnabled    bool   `mapstructure:"console_enabled"`
	ConsoleJSONFormat bool   `mapstructure:"console_json_format"`
	ConsoleLevel      string `mapstructure:"console_level"`
	FileEnabled       bool   `mapstructure:"file_enabled"`
	FileJSONFormat    bool   `mapstructure:"file_json_format"`
	FileLevel         string `mapstructure:"file_level"`
	FileLocation      string `mapstructure:"file_location"`
	FileName          string `mapstructure:"file_name"`
}

Config stores the configuration for the logger. For some loggers there can only be one level across writers, for such the level of Console is picked by default.

func NewConfig

func NewConfig() (*Config, error)

NewConfig returns a new LoggerConfig instance

type Fields

type Fields map[string]interface{}

Fields is the struct that that stores key/value pairs for structured logs.

func (*Fields) Set

func (f *Fields) Set(key string, value interface{})

Set sets a key/value pair in the Fields map.

type Level

type Level string
const (
	// Panic level, highest level of severity. Logs and then calls
	// panic with the message passed to Debug, Info, ...
	Panic Level = "panic"
	// Fatal level. Logs and then calls `logger.Exit(1)`. It will
	// exit even if the logging level is set to Panic.
	Fatal Level = "fatal"
	// Error level. Logs. Used for errors that should definitely be
	// noted. Commonly used for hooks to send errors to an error
	// tracking service.
	Error Level = "error"
	// Warn level. Non-critical entries that deserve eyes.
	Warn Level = "warn"
	// Info level. General operational entries about what's going on
	// inside the application.
	Info Level = "info"
	// Debug level. Usually only enabled when debugging. Very
	// verbose logging.
	Debug Level = "debug"
	// Trace level. Designates finer-grained informational events
	// than the Debug.
	Trace Level = "trace"
)

type Logger

type Logger interface {
	// Panicf logs a message at level Panic.
	Panicf(format string, args ...interface{})
	// Fatalf logs a message at level Fatal.
	Fatalf(format string, args ...interface{})
	// Errorf logs a message at level Error.
	Errorf(format string, args ...interface{})
	// Warnf logs a message at level Warning.
	Warnf(format string, args ...interface{})
	// Infof logs a message at level Info.
	Infof(format string, args ...interface{})
	// Debugf logs a message at level Debug.
	Debugf(format string, args ...interface{})
	// Trace logs a message at level Trace.
	Tracef(format string, args ...interface{})
	// WithFields creates an entry from the logger and adds multiple
	// fields to it. This is simply a helper for `WithField`,
	// invoking it once for each field.
	//
	// Note that it doesn't log until you call Debug, Print, Info,
	// Warn, Fatal or Panic on the Entry it returns.
	WithFields(keyValues Fields) Logger
}

Logger is the interface that defines the API/contract exposed by the SDK Logger.

Jump to

Keyboard shortcuts

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