logger

package
v0.0.0-...-5db00e0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DebugLevel = "debug"
	InfoLevel  = "info"
	ErrorLevel = "error"
)

Log levels

Variables

This section is empty.

Functions

func ConfigureGRPC

func ConfigureGRPC(verbosity int, log *Logger)

ConfigureGRPC configures the GRPC logger verboisty level.

All logs in transport package only go to verbose level 2.
All logs in other packages in grpc are logged in spite of the verbosity level.

func Debug

func Debug(msg string, args ...interface{})

Debug logs debug messages to a global logger.

func PrintSimpleError

func PrintSimpleError(err error)

PrintSimpleError prints out an error message with a red "ERROR:" prefix.

Types

type Config

type Config struct {
	Level      string
	Formatter  string
	OutputFile string
	JSONFormat JSONFormatConfig
	TextFormat TextFormatConfig
}

Config provides configuration for a logger.

func DebugConfig

func DebugConfig() Config

DebugConfig returns a Config instance with default values useful for testing/debugging.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config instance with default values.

type Formatter

type Formatter logrus.Formatter

Formatter defines a log output formatter.

type JSONFormatConfig

type JSONFormatConfig struct {
	DisableTimestamp bool
	TimestampFormat  string
}

JSONFormatConfig provides configuration for the JSON logger format.

type Logger

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

Logger handles structured, configurable application logging.

func NewLogger

func NewLogger(ns string, conf Config) *Logger

NewLogger returns a new Logger instance.

func (*Logger) Configure

func (l *Logger) Configure(conf Config)

Configure configures the logging level and output path.

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...interface{})

Debug logs a debug message.

After the first argument, arguments are key-value pairs which are written as structured logs.

log.Debug("Some message here", "key1", value1, "key2", value2)

func (*Logger) Discard

func (l *Logger) Discard()

Discard configures the logger to discard all logs.

func (*Logger) Error

func (l *Logger) Error(msg string, args ...interface{})

Error logs an error message

After the first argument, arguments are key-value pairs which are written as structured logs.

log.Error("Some message here", "key1", value1, "key2", value2)

Error has a two-argument version that can be used as a shortcut.

err := startServer()
log.Error("Couldn't start server", err)

func (*Logger) Info

func (l *Logger) Info(msg string, args ...interface{})

Info logs an info message

After the first argument, arguments are key-value pairs which are written as structured logs.

log.Info("Some message here", "key1", value1, "key2", value2)

func (*Logger) SetFormatter

func (l *Logger) SetFormatter(f Formatter)

SetFormatter sets the formatter of the logger.

func (*Logger) SetLevel

func (l *Logger) SetLevel(lvl string)

SetLevel sets the level of the logger.

func (*Logger) SetOutput

func (l *Logger) SetOutput(o io.Writer)

SetOutput sets the output of the logger.

func (*Logger) Sub

func (l *Logger) Sub(ns string) *Logger

Sub is a shortcut for l.WithFields("ns", ns), it creates a new logger which inherits the parent's configuration but changes the namespace.

func (*Logger) WithFields

func (l *Logger) WithFields(args ...interface{}) *Logger

WithFields returns a new Logger instance with the given fields added to all log messages.

type TextFormatConfig

type TextFormatConfig struct {
	// Set to true to bypass checking for a TTY before outputting colors.
	ForceColors bool

	// Force disabling colors.
	DisableColors bool

	// Disable timestamp logging. useful when output is redirected to logging
	// system that already adds timestamps.
	DisableTimestamp bool

	// Enable logging the full timestamp when a TTY is attached instead of just
	// the time passed since beginning of execution.
	FullTimestamp bool

	// TimestampFormat to use for display when a full timestamp is printed
	TimestampFormat string

	// The fields are sorted by default for a consistent output. For applications
	// that log extremely frequently and don't use the JSON formatter this may not
	// be desired.
	DisableSorting bool

	Indent string
}

TextFormatConfig provides configuration for the text logger format.

Jump to

Keyboard shortcuts

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