logging

package module
v0.0.0-...-8616abd Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: GPL-3.0 Imports: 7 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrField is a shortcut function for adding an error field to the log output
	ErrField = func(e error) Field {
		return F("err", e)
	}
)

Functions

func Configure

func Configure(level, format, outfile string)

Configure will configure the logger with the given attributes

func Debug

func Debug(msg string, fields ...Field)

Debug calls the logger Debug method

func Error

func Error(msg string, fields ...Field)

Error calls the logger Error method

func Fatal

func Fatal(msg string, fields ...Field)

Fatal calls the logger Fatal method

func Info

func Info(msg string, fields ...Field)

Info calls the logger Info method

func SetClient

func SetClient(name string, cfg *Config) error

SetClient is a factory function to initiate the logging client with the given name. The instance is then set at the package level, and is retrievable in other packages using the Client() function.

Types

type Config

type Config struct {
	LogLevel  string // Debug | Info | Error
	OutFormat string // json | text
	Outfile   string // path to file. Missing = send to stdout/err
}

Config is the concrete type that is passed to a Configurer

func (*Config) Update

func (c *Config) Update(cfg *Config) *Config

Update will overwrite this Config's fields with the provided one if the new fields are not the zero value for that field.

type Configurer

type Configurer interface {
	Configure(*Config) error
}

Configurer defines the interface to configure logging clients

type Field

type Field struct {
	Name string
	Val  interface{}
}

Field represents a logging Field

func F

func F(name string, val interface{}) Field

F is a shortcut for creating logging Fields

type LogLeveler

type LogLeveler interface {
	Debug(string, ...Field)
	DebugL([]string, ...Field)
	Info(string, ...Field)
	InfoL([]string, ...Field)
	Error(string, ...Field)
	ErrorL([]string, ...Field)
	Fatal(string, ...Field)
	FatalL([]string, ...Field)
}

LogLeveler defines the interface for log level methods

type Logger

type Logger interface {
	Name() string
	Path() string
	Configurer
	LogLeveler
}

Logger defines the interface for logging clients

func Client

func Client() Logger

Client returns the logging client, or nil if it has not been initiated yet.

func NewClient

func NewClient(name string, cfg *Config) (Logger, error)

NewClient returns a new instance of the concrete logging Client with the given name

type LogrusLogger

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

LogrusLogger defines a logger using the logrus package as its backend

func NewLogrusLogger

func NewLogrusLogger(cfg *Config) (*LogrusLogger, error)

NewLogrusLogger wraps a logrus client

func (*LogrusLogger) Configure

func (l *LogrusLogger) Configure(cfg *Config) error

Configure permits configuration of the logger via a Config struct

func (*LogrusLogger) Debug

func (l *LogrusLogger) Debug(msg string, fields ...Field)

Debug defines the debug level for this logger

func (*LogrusLogger) DebugL

func (l *LogrusLogger) DebugL(msgs []string, fields ...Field)

DebugL defines the debug level for more than one log line

func (*LogrusLogger) Error

func (l *LogrusLogger) Error(msg string, fields ...Field)

Error defines the error level for this logger

func (*LogrusLogger) ErrorL

func (l *LogrusLogger) ErrorL(msgs []string, fields ...Field)

ErrorL defines the error level for more than one log line

func (*LogrusLogger) Fatal

func (l *LogrusLogger) Fatal(msg string, fields ...Field)

Fatal defines the fatal level for this logger

func (*LogrusLogger) FatalL

func (l *LogrusLogger) FatalL(msgs []string, fields ...Field)

FatalL defines the fatal level for more than one log line

func (*LogrusLogger) Info

func (l *LogrusLogger) Info(msg string, fields ...Field)

Info defines the info level for this logger

func (*LogrusLogger) InfoL

func (l *LogrusLogger) InfoL(msgs []string, fields ...Field)

InfoL defines the info level for more than one log line

func (*LogrusLogger) Name

func (l *LogrusLogger) Name() string

Name returns the name of the logg

func (*LogrusLogger) Path

func (l *LogrusLogger) Path() string

Path returns the full path to the logger output, or empty string if logging is not going to a file

type NullLogger

type NullLogger struct{}

NullLogger does nothing

func NewNullLogger

func NewNullLogger(cfg *Config) (*NullLogger, error)

NewNullLogger creates a new NullLogger

func (NullLogger) Configure

func (NullLogger) Configure(*Config) error

Configure permits configuration of the logger via a Config struct

func (NullLogger) Debug

func (NullLogger) Debug(string, ...Field)

Debug defines the debug level for this logger

func (NullLogger) DebugL

func (NullLogger) DebugL([]string, ...Field)

DebugL defines the debug level for this logger

func (NullLogger) Error

func (NullLogger) Error(string, ...Field)

Error defines the error level for this logger

func (NullLogger) ErrorL

func (NullLogger) ErrorL([]string, ...Field)

ErrorL defines the error level for this logger

func (NullLogger) Fatal

func (NullLogger) Fatal(string, ...Field)

Fatal defines the fatal level for this logger

func (NullLogger) FatalL

func (NullLogger) FatalL([]string, ...Field)

FatalL defines the fatal level for this logger

func (NullLogger) Info

func (NullLogger) Info(string, ...Field)

Info defines the info level for this logger

func (NullLogger) InfoL

func (NullLogger) InfoL([]string, ...Field)

InfoL defines the info level for this logger

func (NullLogger) Name

func (NullLogger) Name() string

Name returns the name of the logger

func (NullLogger) Path

func (NullLogger) Path() string

Path returns the path to the logger output file

Jump to

Keyboard shortcuts

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