Documentation ¶
Overview ¶
Package log contains utilities for logging in a modular interface. This package can be used to wrap a third party library.
Index ¶
- Constants
- Variables
- func Spec() docs.FieldSpecs
- type Config
- type Logger
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Debugln(message string)
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Errorln(message string)
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Fatalln(message string)
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Infoln(message string)
- func (l *Logger) NewModule(name string) Modular
- func (l *Logger) Tracef(format string, v ...interface{})
- func (l *Logger) Traceln(message string)
- func (l *Logger) Warnf(format string, v ...interface{})
- func (l *Logger) Warnln(message string)
- func (l *Logger) With(args ...interface{}) Modular
- func (l *Logger) WithFields(inboundFields map[string]string) Modular
- type Modular
- func New(stream io.Writer, config Config) Modular
- func NewV2(stream io.Writer, config Config) (Modular, error)
- func Noop() Modular
- func With(l Modular, args ...interface{}) (Modular, error)
- func WithFields(l Modular, fields map[string]string) Modular
- func Wrap(l PrintFormatter) Modular
- func WrapAtLevel(l PrintFormatter, level int) Modular
- type PrintFormatter
Constants ¶
const ( LogOff int = 0 LogFatal int = 1 LogError int = 2 LogWarn int = 3 LogInfo int = 4 LogDebug int = 5 LogTrace int = 6 LogAll int = 7 )
Logger level constants
Variables ¶
var (
ErrClientNil = errors.New("the client pointer was nil")
)
Errors used throughout the package.
Functions ¶
func Spec ¶
func Spec() docs.FieldSpecs
Spec returns a field spec for the logger configuration fields.
Types ¶
type Config ¶
type Config struct { Prefix string `json:"prefix" yaml:"prefix"` LogLevel string `json:"level" yaml:"level"` Format string `json:"format" yaml:"format"` AddTimeStamp bool `json:"add_timestamp" yaml:"add_timestamp"` JSONFormat bool `json:"json_format" yaml:"json_format"` StaticFields map[string]string `json:"static_fields" yaml:"static_fields"` }
Config holds configuration options for a logger object.
func NewConfig ¶
func NewConfig() Config
NewConfig returns a config struct with the default values for each field.
func (Config) Sanitised ¶
Sanitised returns a sanitised version of the config, meaning sections that aren't relevant to behaviour are removed. Also optionally removes deprecated fields.
func (*Config) UnmarshalJSON ¶
UnmarshalJSON ensures that when parsing configs that are in a slice the default values are still applied.
func (*Config) UnmarshalYAML ¶
UnmarshalYAML ensures that when parsing configs that are in a slice the default values are still applied.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is an object with support for levelled logging and modular components.
func (*Logger) NewModule ¶
NewModule creates a new logger object from the previous, using the same configuration, but adds an extra prefix to represent a submodule.
type Modular ¶
type Modular interface { NewModule(prefix string) Modular WithFields(fields map[string]string) Modular Fatalf(format string, v ...interface{}) Errorf(format string, v ...interface{}) Warnf(format string, v ...interface{}) Infof(format string, v ...interface{}) Debugf(format string, v ...interface{}) Tracef(format string, v ...interface{}) Fatalln(message string) Errorln(message string) Warnln(message string) Infoln(message string) Debugln(message string) Traceln(message string) }
Modular is a log printer that allows you to branch new modules.
func NewV2 ¶
NewV2 returns a new logger from a config, or returns an error if the config is invalid.
func With ¶
With attempts to cast the Modular implementation into an interface that implements With, and if successful returns the result.
func WithFields ¶
WithFields attempts to cast the Modular implementation into an interface that implements WithFields, and if successful returns the result.
func Wrap ¶
func Wrap(l PrintFormatter) Modular
Wrap a PrintFormatter with a log.Modular implementation. Log level is set to INFO, use WrapAtLevel to set this explicitly.
func WrapAtLevel ¶
func WrapAtLevel(l PrintFormatter, level int) Modular
WrapAtLevel wraps a PrintFormatter with a log.Modular implementation with an explicit log level.
type PrintFormatter ¶
type PrintFormatter interface { Printf(format string, v ...interface{}) Println(v ...interface{}) }
PrintFormatter is an interface implemented by standard loggers.