log

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2018 License: MIT Imports: 8 Imported by: 43

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

View Source
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

View Source
var (
	ErrClientNil = errors.New("the client pointer was nil")
)

Errors used throughout the package.

Functions

This section is empty.

Types

type Config

type Config struct {
	Prefix       string `json:"prefix" yaml:"prefix"`
	LogLevel     string `json:"log_level" yaml:"log_level"`
	AddTimeStamp bool   `json:"add_timestamp" yaml:"add_timestamp"`
	JSONFormat   bool   `json:"json_format" yaml:"json_format"`
}

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.

type FanOutWriter added in v0.15.3

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

FanOutWriter is an io.Writer that can add and remove other writers, there is a primary writer that blocks, all other writers are lossy and will be cut off and closed if they return errors.

func NewFanOutWriter added in v0.15.3

func NewFanOutWriter(w io.Writer) *FanOutWriter

NewFanOutWriter creates a new fanned out writer.

func (*FanOutWriter) Add added in v0.15.3

func (w *FanOutWriter) Add(lw io.Writer)

Add a new lossy writer.

func (*FanOutWriter) Close added in v0.15.3

func (w *FanOutWriter) Close() error

Close all lossy writers. This call does NOT close the primary writer.

func (*FanOutWriter) Remove added in v0.15.3

func (w *FanOutWriter) Remove(lw io.Writer)

Remove an existing lossy writer. Writers that are removed and implement io.Closer will be closed as they are removed.

func (*FanOutWriter) Write added in v0.15.3

func (w *FanOutWriter) Write(p []byte) (n int, err error)

Write to all registered writers, if a writer blocks this call will also block.

type Logger

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

Logger is an object with support for levelled logging and modular components.

func (*Logger) AddWriter added in v0.15.3

func (l *Logger) AddWriter(w io.Writer)

AddWriter adds a new writer to the logger which receives the same log data as the primary writer. If this new writer returns an error it is removed. The logger becomes the owner of this writer and under any circumstance whereby the writer is removed it will also be closed by the logger.

func (*Logger) Close added in v0.15.3

func (l *Logger) Close() error

Close the logger, including the underlying io.Writer if it implements the io.Closer interface.

func (*Logger) Debugf

func (l *Logger) Debugf(message string, other ...interface{})

Debugf prints a debug message to the console.

func (*Logger) Debugln

func (l *Logger) Debugln(message string)

Debugln prints a debug message to the console.

func (*Logger) Errorf

func (l *Logger) Errorf(message string, other ...interface{})

Errorf prints an error message to the console.

func (*Logger) Errorln

func (l *Logger) Errorln(message string)

Errorln prints an error message to the console.

func (*Logger) Fatalf

func (l *Logger) Fatalf(message string, other ...interface{})

Fatalf prints a fatal message to the console. Does NOT cause panic.

func (*Logger) Fatalln

func (l *Logger) Fatalln(message string)

Fatalln prints a fatal message to the console. Does NOT cause panic.

func (*Logger) Infof

func (l *Logger) Infof(message string, other ...interface{})

Infof prints an information message to the console.

func (*Logger) Infoln

func (l *Logger) Infoln(message string)

Infoln prints an information message to the console.

func (*Logger) NewModule

func (l *Logger) NewModule(prefix string) Modular

NewModule creates a new logger object from the previous, using the same configuration, but adds an extra prefix to represent a submodule.

func (*Logger) Output

func (l *Logger) Output(calldepth int, s string) error

Output prints s to our output. Calldepth is ignored.

func (*Logger) RemoveWriter added in v0.15.3

func (l *Logger) RemoveWriter(w io.Writer)

RemoveWriter removes writer from the logger.

func (*Logger) Tracef

func (l *Logger) Tracef(message string, other ...interface{})

Tracef prints a trace message to the console.

func (*Logger) Traceln

func (l *Logger) Traceln(message string)

Traceln prints a trace message to the console.

func (*Logger) Warnf

func (l *Logger) Warnf(message string, other ...interface{})

Warnf prints a warning message to the console.

func (*Logger) Warnln

func (l *Logger) Warnln(message string)

Warnln prints a warning message to the console.

type Modular

type Modular interface {
	NewModule(prefix string) Modular

	// AddWriter adds a new writer to the logger which receives the same log
	// data as the primary writer. If this new writer returns an error it is
	// removed. The logger becomes the owner of this writer and under any
	// circumstance whereby the writer is removed it will also be closed by the
	// logger.
	AddWriter(w io.Writer)

	// RemoveWriter removes writer from the logger.
	RemoveWriter(w io.Writer)

	Fatalf(message string, other ...interface{})
	Errorf(message string, other ...interface{})
	Warnf(message string, other ...interface{})
	Infof(message string, other ...interface{})
	Debugf(message string, other ...interface{})
	Tracef(message string, other ...interface{})

	Fatalln(message string)
	Errorln(message string)
	Warnln(message string)
	Infoln(message string)
	Debugln(message string)
	Traceln(message string)

	Output(calldepth int, s string) error

	// Close the logger, including the underlying io.Writer if it implements the
	// io.Closer interface.
	Close() error
}

Modular is a log printer that allows you to branch new modules.

func New

func New(stream io.Writer, config Config) Modular

New creates and returns a new logger object.

func Noop

func Noop() Modular

Noop creates and returns a new logger object that writes nothing.

Jump to

Keyboard shortcuts

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