tinylog

package module
v0.0.0-...-9b2170e Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: ISC Imports: 7 Imported by: 0

README

tinylog

GoDoc

Functions

func DefaultDestination

func DefaultDestination() *destination

Destination based on os.Stderr as out and formatters.Default() as formatter.

func MustParseLogLevel

func MustParseLogLevel(level string) int

parses string to LogLevel int.

func ParseLogLevel

func ParseLogLevel(level string) (int, error)

Parses string to LogLevel int. Returns int if level is recognized or error if not.

Types

type Destination

type Destination func() *destination

Destination configuration. Defines log formatter and log level for particular output.

type FixedLevelLogger

type FixedLevelLogger interface { ... }

Logger bound to concrete log level.

type LogLevelSetter

type LogLevelSetter interface { ... }

type Logger

type Logger interface { ... }

Logger can print log of different verbosity level.

type LoggerFactory

type LoggerFactory interface { ... }

LoggerFactory manages Loggers instances verbosity levels and can get Logger instance bound to context.

Sub Packages


Readme created from Go doc with goreadme

Documentation

Index

Constants

View Source
const (
	// Most verbose level.
	// Is supposed to carry useful information to developers.
	// Is supposed to contain file and row number of place logging function was called.
	Trace int = iota
	// Is supposed to carry useful information not only to developers but to support as well.
	// Is supposed to contain file and row number of place logging function was called.
	Debug
	// Is supposed to carry useful information about program usage.
	Info
	// Is supposed to carry information about obscure behaviour of a program.
	Warn
	// Is supposed to carry information about error that caused abort of current operation.
	Error
	// Is supposed to carry information about error that caused program to exit.
	// Is supposed to contain file and row number of place logging function was called.
	Fatal
)

Variables

This section is empty.

Functions

func DefaultDestination

func DefaultDestination() *destination

Destination based on os.Stderr as out and formatters.Default() as formatter.

func MustParseLogLevel

func MustParseLogLevel(level string) int

parses string to LogLevel int.

func ParseLogLevel

func ParseLogLevel(level string) (int, error)

Parses string to LogLevel int. Returns int if level is recognized or error if not.

Types

type Destination

type Destination func() *destination

Destination configuration. Defines log formatter and log level for particular output.

func AllDestinations

func AllDestinations(factory LoggerFactory) []Destination

Returns all Destinations that were assigned to factory.

func DestinationFunc

func DestinationFunc(out io.Writer, formatter formatters.LogFormatter, level int) Destination

Destination constructor function.

type FixedLevelLogger

type FixedLevelLogger interface {
	// Printf formats according to a format specifier and writes to io.Writer with appended newline.
	Printf(format string, v ...interface{})
	// Fprintln formats using the default formats for its operands and writes to io.Writer.
	// Spaces are always added between operands and a newline is appended.
	Println(v ...interface{})
}

Logger bound to concrete log level.

type LogLevelSetter

type LogLevelSetter interface {
	// Sets verbosity level for set of Destinations.
	// 0 = Trace;
	// 1 = Debug;
	// 2 = Info;
	// 3 = Warn;
	// 4 = Error;
	// 5 = Fatal;
	// If no Destination were provided default LogLevelSetter Destinations are expected to be used.
	SetLogLevel(level int, destinations ...Destination)
}

type Logger

type Logger interface {
	LogLevelSetter

	// Returns instance of FixedLevelLogger that shares tags with Logger instance.
	GetFixedLevel(level int) FixedLevelLogger
	// Adds tag to a logger and all instances of FixedLevelLogger created from this Logger.
	AddTag(key string, value ...string)

	// Printf formats according to a format specifier and writes to io.Writer with level of verbosity.
	// 0 = Trace;
	// 1 = Debug;
	// 2 = Info;
	// 3 = Warn;
	// 4 = Error;
	// 5 = Fatal;
	Printf(level int, format string, v ...interface{})
	// Fprintln formats using the default formats for its operands and writes to io.Writer with level of verbosity.
	// Spaces are always added between operands and a newline is appended.
	// 0 = Trace;
	// 1 = Debug;
	// 2 = Info;
	// 3 = Warn;
	// 4 = Error;
	// 5 = Fatal;
	Println(level int, v ...interface{})
	// Fatalf is equivalent to l.Printf(tinylog.Fatal) followed by a call to os.Exit(1).
	Fatalf(format string, v ...interface{})
	// Fatalln is equivalent to l.Println(tinylog.Fatal) followed by a call to os.Exit(1).
	Fatalln(v ...interface{})
}

Logger can print log of different verbosity level.

func DefaultLogger

func DefaultLogger() Logger

Returns new instance of Logger with DefaultDestination.

func NewLogger

func NewLogger(destinations ...Destination) Logger

Returns new instance of Logger based on out and formatter.

type LoggerFactory

type LoggerFactory interface {
	LogLevelSetter
	// Returns instance of Logger bound to provided ctx with listed Destinations.
	// If no Destination were provided default LoggerFactory Destinations are expected to be used.
	GetLogger(ctx context.Context, destinations ...Destination) Logger
	// Returns all Destinations for this LoggerFactory.
	Destinations() []Destination
}

LoggerFactory manages Loggers instances verbosity levels and can get Logger instance bound to context.

func DefaultLoggerFactory

func DefaultLoggerFactory() LoggerFactory

Returns new instance of LoggerFactory with DefaultDestination.

func NewLoggerFactory

func NewLoggerFactory(destinations ...Destination) LoggerFactory

Returns new instance of LoggerFactory based on out and formatter.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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