log

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package log provides a logging package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(format string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(format string, args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(format string, args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(format string, args ...interface{})

func NewDefaultWriter

func NewDefaultWriter() io.WriteCloser

NewDefaultWriter will return a writer that writes to Stdout

func NewFileWriter

func NewFileWriter(filename string, maxSize int64) (io.WriteCloser, error)

NewFileWriter will return a writer that writes to the given file up to the maxSize after which it will it will rotate the file. If maxSize is set to 0, then it will not rotate the file.

func NewNilWriter

func NewNilWriter() io.WriteCloser

NewNilWriter will return a writer that does nothing

func Panic

func Panic(args ...interface{})

func Panicf

func Panicf(format string, args ...interface{})

func SetFormatter

func SetFormatter(formatter Formatter)

func SetLevel

func SetLevel(lvl Level)

func SetWriter

func SetWriter(writer io.WriteCloser)

func Setup

func Setup(cfg Config) error

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(format string, args ...interface{})

Types

type Config

type Config struct {
	Writer    string `config:"log.writer" default:"stdout"`
	Formatter string `config:"log.format" default:"text"`
	Level     string `config:"log.level" default:"warning"`
	MaxSize   int64  `config:"log.maxFileSize" default:"10000000"` // 10MB
}

type Entry

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

Entry represents a user log entry with additional metadata

func (*Entry) Tag

func (e *Entry) Tag(key string, value interface{}) *Entry

Add custom tags to the log entry

type Formatter

type Formatter interface {
	Format(Entry *Entry) []byte
}

Formatter is responsible to generate a byte array representing a log event in a specific format (json/txt/xml/etc)

func NewJSONFormatter

func NewJSONFormatter(defaultKeys map[string]interface{}) Formatter

NewJSONFormatter will encode the entry along with the default provided keys as a JSON string

func NewNilFormatter

func NewNilFormatter() Formatter

NewNilFormatter will return a Formatter that does nothing and returns an empty byte slice every time

func NewTextFormatter

func NewTextFormatter(defaultKeys map[string]interface{}) Formatter

NewTextFormatter will return encode the Entry along with the default provided keys as key=value pairs

type Level

type Level byte

Level of severity for a log entry

const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel Level = iota + 1
	// FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
)

func (Level) String

func (l Level) String() string

Jump to

Keyboard shortcuts

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