out

package
v0.0.0-...-6e5121b Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2020 License: MPL-2.0 Imports: 9 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PriorityLevelMap = map[string]PriorityLevel{
	"DEBUG": PriorityDebug,
	"INFO":  PriorityInfo,
	"ERROR": PriorityError,
}

PriorityLevelMap defines string names for PriorityLevels

Functions

func Debugf

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

Debugf is a no-op when not compiled with a debug tag.

func Debugln

func Debugln(args ...interface{})

Debugln is a no-op when not compiled with a debug tag.

func Errorf

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

Errorf is a globally available logging function at the INFO level.

func Errorln

func Errorln(args ...interface{})

Errorln is a globally available logging function at the INFO level.

func Format

func Format(pl PriorityLevel, msg string) string

Format produces a message with timestamp and priority level

func Printf

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

Printf is a globally available logging function at the INFO level.

func Println

func Println(args ...interface{})

Println is a globally available logging function at the INFO level.

func Write

func Write(msg []byte)

Write is a globally available output function

func WriteString

func WriteString(msg string)

WriteString is a globally available output function

Types

type Config

type Config struct {
	Enabled   bool          `yaml:"enabled"`
	Filename  string        `yaml:"filename"`
	Async     bool          `yaml:"async"`
	Threshold PriorityLevel `yaml:"threshold"`
	Rotate    *RotateConfig `yaml:"rotate"`
}

Config defines settings for Log

func ConfigFromMap

func ConfigFromMap(m map[string]interface{}) *Config

ConfigFromMap returns a Config based on map values. Used with spf13/viper.

type Log

type Log struct {
	Filename  string
	Async     bool
	Threshold PriorityLevel
	// contains filtered or unexported fields
}

Log is a configurable logger and file writer designed for write heavy apps. Can be configured to periodically rotate and to write asynchronously. Implements the io.Writer interface

func New

func New(config *Config) (*Log, error)

New creates a new Log

func (*Log) Close

func (l *Log) Close()

Close will cleanly finish tasks and close the file

func (*Log) Flush

func (l *Log) Flush()

Flush triggers the log buffers to flush the output

func (*Log) Logf

func (l *Log) Logf(pl PriorityLevel, format string, args ...interface{})

Logf writes a formatted string with the given priority level and timestamped with the current time. The message is only written out if PriorityLevel is greater than or equal to the Threshold.

func (*Log) Logln

func (l *Log) Logln(pl PriorityLevel, args ...interface{})

Logln writes a message with the given priority level and timestamped with the current time. The message is only written out if PriorityLevel is greater than or equal to the Threshold.

func (*Log) Write

func (l *Log) Write(msg []byte) (int, error)

Write a message without additional formatting.

func (*Log) WriteString

func (l *Log) WriteString(msg string) (int, error)

WriteString is equivalent to Write([]byte(msg)).

type PriorityLevel

type PriorityLevel int

PriorityLevel indicates the severity level of a logged message

const (
	// PriorityDebug indicates the event is for debugging purposes
	PriorityDebug PriorityLevel = iota
	// PriorityInfo indicates the event is informational in nature
	PriorityInfo
	// PriorityError indicates an error has occurred
	PriorityError
)

func (PriorityLevel) String

func (p PriorityLevel) String() string

type RotateConfig

type RotateConfig struct {
	Enabled        bool `yaml:"enabled"`
	MaxSize        int  `yaml:"maxsize"`
	MaxCount       int  `yaml:"maxcount"`
	MaxAge         int  `yaml:"maxage"`
	RotateExisting bool `yaml:"rotate_existing"`
	Compress       bool `yaml:"compress"`
}

RotateConfig specifies how a rotating log should be rotated

Jump to

Keyboard shortcuts

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